How to use parse-git-config - 10 common examples

To help you get started, we’ve selected a few parse-git-config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hubidu / bifrost-io / src / utils / git-user.js View on Github external
module.exports = function(options) {
  try {
    const gc = gitconfig(Object.assign({type: 'global'}, options && options.gitconfig));
    options = Object.assign({cwd: '/', path: gc}, options);
    const config = parse.sync(options) || {};
    return config.user ? config.user : null;
  } catch (err) {
    // Dont log on CI/CD
    if (!process.env.NODE_ENV) {
      console.log('WARNING Could not determine git user info', err)
    }
  }
};
github microsoft / azure-repos-vscode / src / contexts / gitcontext.ts View on Github external
if (gitDir) {
                this._gitFolder = rootPath;
                gri._changeGitDir(gitDir);
            } else {
                this._gitFolder = Utils.FindGitFolder(rootPath);
            }

            if (this._gitFolder !== undefined) {
                // With parse-git-config, cwd is the directory containing the path, .git/config, you want to sync
                this._gitParentFolder = path.dirname(this._gitFolder);
                let syncObj: any = { cwd: this._gitParentFolder };
                //If gitDir, send pgc the exact path to the config file to use
                if (gitDir) {
                    syncObj = { path: path.join(this._gitFolder, "config") };
                }
                this._gitConfig = pgc.sync(syncObj);

                /* tslint:disable:quotemark */
                const remote: any = this._gitConfig['remote "origin"'];
                /* tslint:enable:quotemark */
                if (remote === undefined) {
                    return;
                }
                this._gitOriginalRemoteUrl = remote.url;

                if (gitDir) {
                    this._gitRepoInfo = gri(this._gitParentFolder);
                } else {
                    this._gitRepoInfo = gri(this._gitFolder);
                }

                this._gitCurrentBranch = this._gitRepoInfo.branch;
github xpack / xpm-js / lib / xpm / init.js View on Github external
const liquidMap = {}

    liquidMap.projectName = config.projectName
    // Return original if not a match.
    liquidMap.gitProjectName = config.projectName.replace(
      /^[@][a-zA-Z0-9-_]+[/]([a-zA-Z0-9-_]+)$/, '$1')

    const author = {}
    author.name = ''
    author.email = ''
    author.url = ''

    let gitConfig
    try {
      gitConfig = await parseGitConfig.promise()
    } catch (err) {
      try {
        gitConfig = await parseGitConfig.promise(
          {
            cwd: userHome,
            path: '.gitconfig'
          }
        )
      } catch (err) {
      }
    }
    if (gitConfig) {
      if (gitConfig.user && gitConfig.user.name) {
        author.name = gitConfig.user.name
      }
      if (gitConfig.user && gitConfig.user.email) {
github ember-learn / ember-cli-addon-docs / lib / utils / update-demo-url.js View on Github external
function gitConfigUrl(configPath) {
  const options = configPath ? { path: configPath } : {};
  const config = parseGitConfig.sync(options);
  const originProp = Object.keys(config).find(key => /^remote/.test(key));

  return originProp ? config[originProp].url : '';
}
github jonschlinkert / remote-origin-url / index.js View on Github external
originUrl.sync = options => {
  if (typeof options === 'string') {
    options = { path: options };
  }

  let parsed = parse.sync(options);
  if (parsed) {
    let origin = parsed[getKey(parsed)];
    return origin ? origin.url : void 0;
  }
};
github freesewing / freesewing / packages / create-freesewing-pattern / lib / get-default-library-params.js View on Github external
const defaults = {
    name: '',
    description: '',
    author: config.get('author'),
    repo: (info) => `${info.author}/${info.name}`,
    license: config.get('license', 'MIT'),
    manager: config.get('manager', 'npm'),
    template: config.get('template', 'light')
  }

  try {
    if (!config.get('author')) {
      const gitConfigPath = getGitConfigPath('global')

      if (gitConfigPath) {
        const gitConfig = parseGitConfig.sync({ path: gitConfigPath })

        if (gitConfig.github && gitConfig.github.user) {
          defaults.author = gitConfig.github.user
        } else if (gitConfig.user && gitConfig.user.email) {
          defaults.author = await githubUsername(gitConfig.user.email)
        }
      }

      if (defaults.author) {
        config.set('author', defaults.author)
      }
    }

    if (!config.get('manager')) {
      if (which.sync('yarn', { nothrow: true })) {
        defaults.manager = 'yarn'
github jonschlinkert / git-user-email / index.js View on Github external
module.exports = function gitUserEmail(opts) {
  opts = extend({cwd: '/', path: gitconfig()}, opts);
  var config = parse.sync(opts);
  if (typeof config === 'object' && config.hasOwnProperty('user')) {
    return config.user.email;
  }
  return null;
};
github KuangPF / vue-cli-analysis / packages / @vue / cli-ui / apollo-server / connectors / projects.js View on Github external
function getHomepage (project, context) {
  const gitConfigPath = path.join(project.path, '.git', 'config')
  if (fs.existsSync(gitConfigPath)) {
    const gitConfig = parseGitConfig.sync({ path: gitConfigPath })
    const gitRemoteUrl = gitConfig['remote "origin"']
    if (gitRemoteUrl) {
      return getHttpsGitURL(gitRemoteUrl.url)
    }
  }

  const pkg = folders.readPackage(project.path, context)
  return pkg.homepage
}
github saasify-sh / saasify / packages / saasify-cli / lib / template / get-default-params.js View on Github external
module.exports = async () => {
  const defaults = {
    name: '',
    description: 'Powered by Saasify',
    author: config.get('author'),
    repo: (info) => `${info.author}/${info.name}`,
    license: config.get('license', 'MIT'),
    template: config.get('template', 'typescript')
  }

  try {
    if (!config.get('author')) {
      const gitConfigPath = getGitConfigPath('global')

      if (gitConfigPath) {
        const gitConfig = parseGitConfig.sync({ path: gitConfigPath })

        if (gitConfig.github && gitConfig.github.user) {
          defaults.author = gitConfig.github.user
        } else if (gitConfig.user && gitConfig.user.email) {
          defaults.author = await githubUsername(gitConfig.user.email)
        }
      }

      if (defaults.author) {
        config.set('author', defaults.author)
      }
    }
  } catch (err) {}

  return defaults
}

parse-git-config

Parse `.git/config` into a JavaScript object. sync or async.

MIT
Latest version published 6 years ago

Package Health Score

71 / 100
Full package analysis