Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
parse-git-config
Advanced tools
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.
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);
});
git-config is another npm package that reads and parses git configuration files. Unlike parse-git-config, git-config focuses more on providing a simpler and more direct approach to accessing git config values without the additional features for handling includes or synchronous parsing.
The ini package is used to parse INI files, which is the format used by git config files. While not specifically designed for git, it can be used to parse any INI file, including git configs. It lacks the git-specific enhancements of parse-git-config, such as understanding git-specific properties or includes.
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:
$ npm install --save parse-git-config
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:
{ 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
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
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
const config = parse.sync({ path: '/path/to/.gitconfig' });
const obj = parse.expandKeys(config);
Converts ini-style keys into objects:
Example 1
const parse = require('parse-git-config');
const config = {
'foo "bar"': { doStuff: true },
'foo "baz"': { doStuff: true }
};
console.log(parse.expandKeys(config));
Results in:
{
foo: {
bar: { doStuff: true },
baz: { doStuff: true }
}
}
Example 2
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:
{
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
}
}
}
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
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:
$ npm install && npm test
(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:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
name
, email
and url
properties following… more | homepageCommits | Contributor |
---|---|
66 | jonschlinkert |
4 | doowb |
1 | daviwil |
1 | LexSwed |
1 | sam3d |
1 | suarasaur |
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on November 20, 2018.
FAQs
Parse `.git/config` into a JavaScript object. sync or async.
The npm package parse-git-config receives a total of 909,301 weekly downloads. As such, parse-git-config popularity was classified as popular.
We found that parse-git-config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.