Parse `.git/config` into a JavaScript object. sync or async.
npm install parse-git-config> Parse .git/config into a JavaScript object. sync or async.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
``sh`
$ npm install --save parse-git-config
`js
const parse = require('parse-git-config');
// sync
console.log(parse.sync());
// using async/await
(async () => console.log(await parse()))();
`
The starting directory to search from.
Type: string
Default: process.cwd() (current working directory)
Either the absolute path to .git config, or the path relative to the current working directory.
Type: string
Default: .git/config
Parsed config object will look something like:
`js`
{ 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', ... } }
Asynchronously parse a .git/config file. If only the callback is passed, the .git/config file relative to process.cwd() is used.
Params
* options {Object|String|Function}: Options with cwd or path, the cwd to use, or the callback function.callback
* {Function}: callback function if the first argument is options or cwd.returns
* {Object}
Example
`js
parse((err, config) => {
if (err) throw err;
// do stuff with config
});
// or, using async/await
(async () => {
console.log(await parse());
console.log(await parse({ cwd: 'foo' }));
console.log(await parse({ cwd: 'foo', path: 'some/.git/config' }));
})();
`
Synchronously parse a .git/config file. If no arguments are passed, the .git/config file relative to process.cwd() is used.
Params
* options {Object|String}: Options with cwd or path, or the cwd to use.returns
* {Object}
Example
`js`
console.log(parse.sync());
console.log(parse.sync({ cwd: 'foo' }));
console.log(parse.sync({ cwd: 'foo', path: 'some/.git/config' }));
Returns an object with only the properties that had ini-style keys converted to objects.
Params
* config {Object}: The parsed git config object.returns
* {Object}
Example
`js`
const config = parse.sync({ path: '/path/to/.gitconfig' });
const obj = parse.expandKeys(config);
Converts ini-style keys into objects:
Example 1
`js
const parse = require('parse-git-config');
const config = {
'foo "bar"': { doStuff: true },
'foo "baz"': { doStuff: true }
};
console.log(parse.expandKeys(config));
`
Results in:
`js`
{
foo: {
bar: { doStuff: true },
baz: { doStuff: true }
}
}
Example 2
`js
const parse = require('parse-git-config');
const 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.expandKeys(config));
`
Results in:
`js`
{
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
}
}
}
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
`sh`
$ npm install && npm test
Building docs
_(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)_
To generate the readme, run the following command:
`sh`
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
* git-user-name: Get a user's name from git config at the project or global scope, depending on… more | homepage
* git-username: Get the username (or 'owner' name) from a git/GitHub remote origin URL. | homepage from a git/GitHub remote origin URL.")
* parse-author: Parse an author, contributor, maintainer or other 'person' string into an object with name, email… more | homepage
* parse-authors: Parse a string into an array of objects with name, email and url properties following… more | name, email and url properties following npm conventions. Useful for the authors` property in package.json or for parsing an AUTHORS file into an array of authors objects."" class="text-primary hover:underline" target="_blank" rel="noopener noreferrer">homepage
* parse-github-url: Parse a github URL into an object. | homepage
* parse-gitignore: Parse a .gitignore or .npmignore file into an array of patterns. | homepage
| Commits | Contributor |
| --- | --- |
| 66 | jonschlinkert |
| 4 | doowb |
| 1 | daviwil |
| 1 | LexSwed |
| 1 | sam3d |
| 1 | suarasaur |
Jon Schlinkert
* GitHub Profile
* Twitter Profile
* LinkedIn Profile
Copyright © 2018, Jon Schlinkert.
Released under the MIT License.
*
_This file was generated by verb-generate-readme, v0.8.0, on November 20, 2018._