Socket
Socket
Sign inDemoInstall

parse-git-config

Package Overview
Dependencies
7
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    parse-git-config

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


Version published
Weekly downloads
1.4M
decreased by-2.84%
Maintainers
1
Install size
65.0 kB
Created
Weekly downloads
 

Package description

What is parse-git-config?

The parse-git-config npm package is a utility for parsing git configuration files. It allows developers to read and interpret the configuration settings of git repositories programmatically. This can be useful for automating tasks, creating development tools, or integrating with other software that needs to understand git configurations.

What are parse-git-config's main functionalities?

Parse local git configuration

This feature allows you to parse the git configuration file of a local repository. The function takes options specifying the working directory and the path to the git config file, then returns the configuration as an object.

const parseGitConfig = require('parse-git-config');
parseGitConfig({ cwd: '/path/to/repo', path: '.git/config' }, (err, config) => {
  if (err) throw err;
  console.log(config);
});

Synchronously parse git config

This feature provides a synchronous method to parse the git config file. It is useful when you need to get the configuration data immediately without dealing with asynchronous callbacks.

const parseGitConfig = require('parse-git-config');
const config = parseGitConfig.sync({ cwd: '/path/to/repo', path: '.git/config' });
console.log(config);

Expand include paths

This feature supports expanding include directives in git config files, allowing you to see the full configuration with included paths resolved. This is particularly useful for complex configurations that use multiple included files.

const parseGitConfig = require('parse-git-config');
parseGitConfig.expandKeys({ include: true }).then(config => {
  console.log(config);
});

Other packages similar to parse-git-config

Readme

Source

parse-git-config NPM version NPM monthly downloads NPM total downloads Linux Build Status

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

Install

Install with npm:

$ npm install --save parse-git-config

Usage

var parse = require('parse-git-config');

// sync
var config = parse.sync();

// or async
parse(function (err, config) {
  // do stuff with err/config
});

Custom path and/or cwd

parse.sync({cwd: 'foo', path: '.git/config'});

// async
parse({cwd: 'foo', path: '.git/config'}, function (err, config) {
  // do stuff 
});

Example result

Config object will be something like:

{ core:
   { repositoryformatversion: '0',
     filemode: true,
     bare: false,
     logallrefupdates: true,
     ignorecase: true,
     precomposeunicode: true },
  'remote "origin"':
   { url: 'https://github.com/jonschlinkert/parse-git-config.git',
     fetch: '+refs/heads/*:refs/remotes/origin/*' },
  'branch "master"': { remote: 'origin', merge: 'refs/heads/master', ... } }

API

parse

Asynchronously parse a .git/config file. If only the callback is passed, the .git/config file relative to process.cwd() is used.

Example

parse(function(err, config) {
  if (err) throw err;
  // do stuff with config
});

Params

  • options {Object|String|Function}: Options with cwd or path, the cwd to use, or the callback function.
  • cb {Function}: callback function if the first argument is options or cwd.
  • returns {Object}

.sync

Synchronously parse a .git/config file. If no arguments are passed, the .git/config file relative to process.cwd() is used.

Example

var config = parse.sync();

Params

  • options {Object|String}: Options with cwd or path, or the cwd to use.
  • returns {Object}

.keys

Returns an object with only the properties that had ini-style keys converted to objects (example below).

Example

var config = parse.sync();
var obj = parse.keys(config);

Params

  • config {Object}: The parsed git config object.
  • returns {Object}

.keys examples

Converts ini-style keys into objects:

Example 1

var parse = require('parse-git-config');
var config = { 
  'foo "bar"': { doStuff: true },
  'foo "baz"': { doStuff: true } 
};

console.log(parse.keys(config));

Results in:

{ 
  foo: { 
    bar: { doStuff: true }, 
    baz: { doStuff: true } 
  } 
}

Example 2

var parse = require('parse-git-config');
var config = {
  'remote "origin"': { 
    url: 'https://github.com/jonschlinkert/normalize-pkg.git',
    fetch: '+refs/heads/*:refs/remotes/origin/*' 
  },
  'branch "master"': { 
    remote: 'origin', 
    merge: 'refs/heads/master' 
  },
  'branch "dev"': { 
    remote: 'origin', 
    merge: 'refs/heads/dev', 
    rebase: true 
  }
};

console.log(parse.keys(config));

Results in:

{
  remote: {
    origin: {
      url: 'https://github.com/jonschlinkert/normalize-pkg.git',
      fetch: '+refs/heads/*:refs/remotes/origin/*'
    }
  },
  branch: {
    master: {
      remote: 'origin',
      merge: 'refs/heads/master'
    },
    dev: {
      remote: 'origin',
      merge: 'refs/heads/dev',
      rebase: true
    }
  }
}

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

CommitsContributor
33jonschlinkert
1sam3d
1jsdnxx

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb-generate-readme, v0.2.0, on October 26, 2016.

Keywords

FAQs

Last updated on 26 Oct 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc