adds promise support

master
jonschlinkert 7 years ago
parent 4a32467144
commit 7322fc740c

@ -5,7 +5,5 @@ os:
language: node_js language: node_js
node_js: node_js:
- node - node
- '6' - '9'
- '5' - '8'
- '0.12'
- '0.10'

@ -1,10 +1,10 @@
## Usage ## Usage
```js ```js
var parse = require('{%= name %}'); const parse = require('{%= name %}');
// sync // sync
var config = parse.sync(); const config = parse.sync();
// or async // or async
parse(function (err, config) { parse(function (err, config) {
@ -51,8 +51,8 @@ Converts ini-style keys into objects:
**Example 1** **Example 1**
```js ```js
var parse = require('parse-git-config'); const parse = require('parse-git-config');
var config = { const config = {
'foo "bar"': { doStuff: true }, 'foo "bar"': { doStuff: true },
'foo "baz"': { doStuff: true } 'foo "baz"': { doStuff: true }
}; };
@ -74,8 +74,8 @@ Results in:
**Example 2** **Example 2**
```js ```js
var parse = require('parse-git-config'); const parse = require('parse-git-config');
var config = { const config = {
'remote "origin"': { 'remote "origin"': {
url: 'https://github.com/jonschlinkert/normalize-pkg.git', url: 'https://github.com/jonschlinkert/normalize-pkg.git',
fetch: '+refs/heads/*:refs/remotes/origin/*' fetch: '+refs/heads/*:refs/remotes/origin/*'

@ -1,7 +1,9 @@
# parse-git-config [![NPM version](https://img.shields.io/npm/v/parse-git-config.svg?style=flat)](https://www.npmjs.com/package/parse-git-config) [![NPM monthly downloads](https://img.shields.io/npm/dm/parse-git-config.svg?style=flat)](https://npmjs.org/package/parse-git-config) [![NPM total downloads](https://img.shields.io/npm/dt/parse-git-config.svg?style=flat)](https://npmjs.org/package/parse-git-config) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/parse-git-config.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/parse-git-config) # parse-git-config [![NPM version](https://img.shields.io/npm/v/parse-git-config.svg?style=flat)](https://www.npmjs.com/package/parse-git-config) [![NPM monthly downloads](https://img.shields.io/npm/dm/parse-git-config.svg?style=flat)](https://npmjs.org/package/parse-git-config) [![NPM total downloads](https://img.shields.io/npm/dt/parse-git-config.svg?style=flat)](https://npmjs.org/package/parse-git-config) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/parse-git-config.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/parse-git-config)
> Parse `.git/config` into a JavaScript object. sync or async. > Parse `.git/config` into a JavaScript object. sync or async.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install ## Install
Install with [npm](https://www.npmjs.com/): Install with [npm](https://www.npmjs.com/):
@ -13,10 +15,10 @@ $ npm install --save parse-git-config
## Usage ## Usage
```js ```js
var parse = require('parse-git-config'); const parse = require('parse-git-config');
// sync // sync
var config = parse.sync(); const config = parse.sync();
// or async // or async
parse(function (err, config) { parse(function (err, config) {
@ -55,10 +57,16 @@ Config object will be something like:
## API ## API
### [parse](index.js#L33) ### [parse](index.js#L35)
Asynchronously parse a `.git/config` file. If only the callback is passed, the `.git/config` file relative to `process.cwd()` is used. 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.
* `cb` **{Function}**: callback function if the first argument is options or cwd.
* `returns` **{Object}**
**Example** **Example**
```js ```js
@ -68,43 +76,53 @@ parse(function(err, config) {
}); });
``` ```
**Params** ### [.sync](index.js#L64)
* `options` **{Object|String|Function}**: Options with `cwd` or `path`, the cwd to use, or the callback function. Parse the given
* `cb` **{Function}**: callback function if the first argument is options or cwd.
* `returns` **{Object}**
### [.sync](index.js#L71) **Params**
Synchronously parse a `.git/config` file. If no arguments are passed, the `.git/config` file relative to `process.cwd()` is used. * `options` **{Object|String}**: Options with `cwd` or `path`, or the cwd to use.
* `returns` **{Object}**
**Example** **Example**
```js ```js
var config = parse.sync(); parse.promise({ path: '/path/to/.gitconfig' })
.then(config => console.log(config));
``` ```
### [.sync](index.js#L98)
Synchronously parse a `.git/config` file. If no arguments are passed, the `.git/config` file relative to `process.cwd()` is used.
**Params** **Params**
* `options` **{Object|String}**: Options with `cwd` or `path`, or the cwd to use. * `options` **{Object|String}**: Options with `cwd` or `path`, or the cwd to use.
* `returns` **{Object}** * `returns` **{Object}**
### [.keys](index.js#L109)
Returns an object with only the properties that had ini-style keys converted to objects (example below).
**Example** **Example**
```js ```js
var config = parse.sync(); const config = parse.sync();
var obj = parse.keys(config);
``` ```
### [.keys](index.js#L150)
Returns an object with only the properties that had ini-style keys converted to objects (example below).
**Params** **Params**
* `config` **{Object}**: The parsed git config object. * `config` **{Object}**: The parsed git config object.
* `returns` **{Object}** * `returns` **{Object}**
**Example**
```js
const config = parse.sync();
const obj = parse.keys(config);
```
### .keys examples ### .keys examples
Converts ini-style keys into objects: Converts ini-style keys into objects:
@ -112,8 +130,8 @@ Converts ini-style keys into objects:
**Example 1** **Example 1**
```js ```js
var parse = require('parse-git-config'); const parse = require('parse-git-config');
var config = { const config = {
'foo "bar"': { doStuff: true }, 'foo "bar"': { doStuff: true },
'foo "baz"': { doStuff: true } 'foo "baz"': { doStuff: true }
}; };
@ -135,8 +153,8 @@ Results in:
**Example 2** **Example 2**
```js ```js
var parse = require('parse-git-config'); const parse = require('parse-git-config');
var config = { const config = {
'remote "origin"': { 'remote "origin"': {
url: 'https://github.com/jonschlinkert/normalize-pkg.git', url: 'https://github.com/jonschlinkert/normalize-pkg.git',
fetch: '+refs/heads/*:refs/remotes/origin/*' fetch: '+refs/heads/*:refs/remotes/origin/*'
@ -181,57 +199,68 @@ Results in:
## About ## About
### Related projects <details>
<summary><strong>Contributing</strong></summary>
* [git-user-name](https://www.npmjs.com/package/git-user-name): Get a user's name from git config at the project or global scope, depending on… [more](https://github.com/jonschlinkert/git-user-name) | [homepage](https://github.com/jonschlinkert/git-user-name "Get a user's name from git config at the project or global scope, depending on what git uses in the current context.") Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
* [git-username](https://www.npmjs.com/package/git-username): Get the username from a git remote origin URL. | [homepage](https://github.com/jonschlinkert/git-username "Get the username from a git remote origin URL.")
* [parse-author](https://www.npmjs.com/package/parse-author): Parse a string into an object with `name`, `email` and `url` properties following npm conventions… [more](https://github.com/jonschlinkert/parse-author) | [homepage](https://github.com/jonschlinkert/parse-author "Parse a string into an object with `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.")
* [parse-authors](https://www.npmjs.com/package/parse-authors): Parse a string into an array of objects with `name`, `email` and `url` properties following… [more](https://github.com/jonschlinkert/parse-authors) | [homepage](https://github.com/jonschlinkert/parse-authors "Parse a string into an array of objects with `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.")
* [parse-github-url](https://www.npmjs.com/package/parse-github-url): Parse a github URL into an object. | [homepage](https://github.com/jonschlinkert/parse-github-url "Parse a github URL into an object.")
* [parse-gitignore](https://www.npmjs.com/package/parse-gitignore): Parse a gitignore file into an array of patterns. Comments and empty lines are stripped. | [homepage](https://github.com/jonschlinkert/parse-gitignore "Parse a gitignore file into an array of patterns. Comments and empty lines are stripped.")
### Contributing </details>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). <details>
<summary><strong>Running Tests</strong></summary>
### Contributors 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:
| **Commits** | **Contributor**<br/> | ```sh
| --- | --- | $ npm install && npm test
| 48 | [jonschlinkert](https://github.com/jonschlinkert) | ```
| 1 | [sam3d](https://github.com/sam3d) |
| 1 | [jsdnxx](https://github.com/jsdnxx) |
### Building docs </details>
<details>
<summary><strong>Building docs</strong></summary>
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_ _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme and API documentation with [verb](https://github.com/verbose/verb): To generate the readme, run the following command:
```sh ```sh
$ npm install -g verb verb-generate-readme && verb $ npm install -g verbose/verb#dev verb-generate-readme && verb
``` ```
### Running tests </details>
Install dev dependencies: ### Related projects
```sh You might also be interested in these projects:
$ npm install -d && npm test
``` * [git-user-name](https://www.npmjs.com/package/git-user-name): Get a user's name from git config at the project or global scope, depending on… [more](https://github.com/jonschlinkert/git-user-name) | [homepage](https://github.com/jonschlinkert/git-user-name "Get a user's name from git config at the project or global scope, depending on what git uses in the current context.")
* [git-username](https://www.npmjs.com/package/git-username): Get the username from a git remote origin URL. | [homepage](https://github.com/jonschlinkert/git-username "Get the username from a git remote origin URL.")
* [parse-author](https://www.npmjs.com/package/parse-author): Parse an author, contributor, maintainer or other 'person' string into an object with name, email… [more](https://github.com/jonschlinkert/parse-author) | [homepage](https://github.com/jonschlinkert/parse-author "Parse an author, contributor, maintainer or other 'person' string into an object with name, email and url properties following npm conventions.")
* [parse-authors](https://www.npmjs.com/package/parse-authors): Parse a string into an array of objects with `name`, `email` and `url` properties following… [more](https://github.com/jonschlinkert/parse-authors) | [homepage](https://github.com/jonschlinkert/parse-authors "Parse a string into an array of objects with `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.")
* [parse-github-url](https://www.npmjs.com/package/parse-github-url): Parse a github URL into an object. | [homepage](https://github.com/jonschlinkert/parse-github-url "Parse a github URL into an object.")
* [parse-gitignore](https://www.npmjs.com/package/parse-gitignore): Parse a gitignore file into an array of patterns. Comments and empty lines are stripped. | [homepage](https://github.com/jonschlinkert/parse-gitignore "Parse a gitignore file into an array of patterns. Comments and empty lines are stripped.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 51 | [jonschlinkert](https://github.com/jonschlinkert) |
| 1 | [sam3d](https://github.com/sam3d) |
| 1 | [js-n](https://github.com/js-n) |
### Author ### Author
**Jon Schlinkert** **Jon Schlinkert**
* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)
* [github/jonschlinkert](https://github.com/jonschlinkert) * [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License ### License
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/parse-git-config/blob/master/LICENSE). Released under the [MIT License](LICENSE).
*** ***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on December 14, 2016._ _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on January 23, 2018._

@ -1,7 +1,8 @@
'use strict'; 'use strict';
var parse = require('./'); const parse = require('./');
var config = { const gitconfig = {
email: 'email',
'remote "origin"': { 'remote "origin"': {
url: 'https://github.com/jonschlinkert/normalize-pkg.git', url: 'https://github.com/jonschlinkert/normalize-pkg.git',
fetch: '+refs/heads/*:refs/remotes/origin/*' fetch: '+refs/heads/*:refs/remotes/origin/*'
@ -14,4 +15,5 @@ var config = {
} }
}; };
console.log(parse.keys(config)); const config = parse.expandKeys(gitconfig);
console.log(config);

@ -7,13 +7,14 @@
'use strict'; 'use strict';
var fs = require('fs'); const fs = require('fs');
var path = require('path'); const path = require('path');
var expand = require('expand-tilde'); const util = require('util');
var exists = require('fs-exists-sync'); const ini = require('ini');
var extend = require('extend-shallow'); const configPath = require('git-config-path');
var configPath = require('git-config-path'); const expand = require('expand-tilde');
var ini = require('ini'); const read = util.promisify(fs.readFile);
const stat = util.promisify(fs.stat);
/** /**
* Asynchronously parse a `.git/config` file. If only the callback is passed, * Asynchronously parse a `.git/config` file. If only the callback is passed,
@ -38,42 +39,54 @@ function parse(options, cb) {
} }
if (typeof cb !== 'function') { if (typeof cb !== 'function') {
throw new TypeError('expected callback to be a function'); return parse.promise(options);
} }
var filepath = parse.resolveConfigPath(options); return parse.promise(options)
if (filepath === null) { .then(config => cb(null, config))
cb(); .catch(cb);
return; }
}
fs.stat(filepath, function(err, stat) { /**
if (err) { * Parse the given
cb(err); *
return; * ```js
} * parse.promise({ path: '/path/to/.gitconfig' })
* .then(config => console.log(config));
* ```
*
* @name .sync
* @param {Object|String} `options` Options with `cwd` or `path`, or the cwd to use.
* @return {Object}
* @api public
*/
fs.readFile(filepath, 'utf8', function(err, str) { parse.promise = function(options) {
if (err) { const opts = Object.assign({}, options);
cb(err); const filepath = parse.resolveConfigPath(opts);
return;
}
if (options && options.include === true) { if (!filepath) {
return Promise.resolve(null);
}
return stat(filepath)
.then(() => {
return read(filepath, 'utf8');
})
.then(str => {
if (opts.include === true) {
str = injectInclude(str, path.resolve(path.dirname(filepath))); str = injectInclude(str, path.resolve(path.dirname(filepath)));
} }
return parseIni(str, opts);
cb(null, ini.parse(str));
}); });
}); };
}
/** /**
* Synchronously parse a `.git/config` file. If no arguments are passed, * Synchronously parse a `.git/config` file. If no arguments are passed,
* the `.git/config` file relative to `process.cwd()` is used. * the `.git/config` file relative to `process.cwd()` is used.
* *
* ```js * ```js
* var config = parse.sync(); * const config = parse.sync();
* ``` * ```
* *
* @name .sync * @name .sync
@ -82,18 +95,19 @@ function parse(options, cb) {
* @api public * @api public
*/ */
parse.sync = function parseSync(options) { parse.sync = function(options) {
var filepath = parse.resolveConfigPath(options); const opts = Object.assign({}, options);
if (filepath && exists(filepath)) { const filepath = parse.resolveConfigPath(opts);
var input = fs.readFileSync(filepath, 'utf8'); if (filepath && fs.existsSync(filepath)) {
const input = fs.readFileSync(filepath, 'utf8');
if (options && options.include === true) { if (opts.include === true) {
var cwd = path.resolve(path.dirname(filepath)); const cwd = path.resolve(path.dirname(filepath));
var str = injectInclude(input, cwd); const str = injectInclude(input, cwd);
return ini.parse(str); return parseIni(str, opts);
} }
return ini.parse(input); return parseIni(input, opts);
} }
return {}; return {};
}; };
@ -106,8 +120,8 @@ parse.resolveConfigPath = function(options) {
if (typeof options === 'string') { if (typeof options === 'string') {
options = { type: options }; options = { type: options };
} }
var opts = extend({cwd: process.cwd()}, options); const opts = Object.assign({cwd: process.cwd()}, options);
var fp = opts.path ? expand(opts.path) : configPath(opts.type); const fp = opts.path ? expand(opts.path) : configPath(opts.type);
return fp ? path.resolve(opts.cwd, fp) : null; return fp ? path.resolve(opts.cwd, fp) : null;
}; };
@ -121,59 +135,57 @@ parse.resolve = function(options) {
/** /**
* Returns an object with only the properties that had ini-style keys * Returns an object with only the properties that had ini-style keys
* converted to objects (example below). * converted to objects.
* *
* ```js * ```js
* var config = parse.sync(); * const config = parse.sync({ path: '/path/to/.gitconfig' });
* var obj = parse.keys(config); * const obj = parse.expandKeys(config);
* ``` * ```
* @name .keys
* @param {Object} `config` The parsed git config object. * @param {Object} `config` The parsed git config object.
* @return {Object} * @return {Object}
* @api public * @api public
*/ */
parse.keys = function parseKeys(config) { parse.expandKeys = function(config) {
var res = {}; for (const key of Object.keys(config)) {
for (var key in config) { const m = /(\S+) "(.*)"/.exec(key);
var m = /(\S+) "(.*)"/.exec(key);
if (!m) continue; if (!m) continue;
var prop = m[1]; const prop = m[1];
res[prop] = res[prop] || {}; config[prop] = config[prop] || {};
res[prop][m[2]] = config[key]; config[prop][m[2]] = config[key];
delete config[key];
} }
return res; return config;
}; };
function parseIni(str, options) {
const opts = Object.assign({}, options);
const config = ini.parse(str);
if (opts.expandKeys === true) {
return parse.expandKeys(config);
}
return config;
}
function injectInclude(input, cwd) { function injectInclude(input, cwd) {
var pathRegex = /^\s*path\s*=\s*/; const lines = input.split('\n').filter(function(line) {
var lines = input.split('\n'); return line.trim() !== '';
var len = lines.length; });
var filepath = '';
var res = [];
for (var i = 0; i < len; i++) { const len = lines.length;
var line = lines[i]; const res = [];
var n = i;
for (let i = 0; i < len; i++) {
const line = lines[i];
if (line.indexOf('[include]') === 0) { if (line.indexOf('[include]') === 0) {
while (n < len && !pathRegex.test(filepath)) { const filepath = lines[i + 1].replace(/^\s*path\s*=\s*/, '');
filepath = lines[++n]; const fp = path.resolve(cwd, expand(filepath));
}
if (!filepath) {
return input;
}
filepath = filepath.replace(pathRegex, '');
var fp = path.resolve(cwd, expand(filepath));
res.push(fs.readFileSync(fp)); res.push(fs.readFileSync(fp));
} else { } else {
res.push(line); res.push(line);
} }
} }
return res.join('\n'); return res.join('\n');
} }

@ -19,7 +19,7 @@
], ],
"main": "index.js", "main": "index.js",
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=8"
}, },
"scripts": { "scripts": {
"test": "mocha" "test": "mocha"
@ -61,9 +61,6 @@
"parse-gitignore" "parse-gitignore"
] ]
}, },
"reflinks": [
"verb"
],
"lint": { "lint": {
"reflinks": true "reflinks": true
} }

@ -1,108 +1,134 @@
/*!
* parse-git-config <https://github.com/jonschlinkert/parse-git-config>
*
* Copyright (c) 2015-2018 Jon Schlinkert.
* Licensed under the MIT license.
*/
'use strict'; 'use strict';
require('mocha'); require('mocha');
var isTravis = process.env.TRAVIS || process.env.CLI; const isTravis = process.env.TRAVIS || process.env.CLI;
var fs = require('fs'); const fs = require('fs');
var os = require('os'); const os = require('os');
var assert = require('assert'); const assert = require('assert');
var path = require('path'); const path = require('path');
var homedir = require('homedir-polyfill'); const homedir = require('homedir-polyfill');
var parse = require('..'); const parse = require('..');
const cwd = (...args) => path.resolve(__dirname, ...args);
const fixture = name => cwd('fixtures', name);
function read(filepath) { function read(filepath) {
return fs.readFileSync(path.join(__dirname, filepath), 'utf8'); return fs.readFileSync(path.join(__dirname, filepath), 'utf8');
} }
describe('sync:', function() { describe('parse-git-config', function() {
it('should return an object', function() { describe('async', function() {
assert(parse.sync().hasOwnProperty('core')); it('should return a promise when callback is not passed', function(cb) {
}); parse({ path: fixture('_gitconfig') })
}); .then(config => {
assert(config.hasOwnProperty('core'));
cb();
})
.catch(cb);
});
describe('async:', function() { it('should parse .git/config', function(cb) {
it('should throw a callback is not passed:', function() { parse({ path: fixture('_gitconfig') }, function(err, config) {
assert.throws(function() { assert(!err);
parse(); assert(config.hasOwnProperty('core'));
}, /expected/); cb();
}); });
});
it('should parse .git/config', function(cb) { it('should expand keys in config', function(cb) {
parse(function(err, config) { parse({ path: fixture('_gitconfig'), expandKeys: true })
assert(!err); .then(config => {
assert(config.hasOwnProperty('core')); assert(config.hasOwnProperty('color'));
cb(); assert(config.color.hasOwnProperty('diff'));
cb();
})
.catch(cb);
}); });
});
it('should include other config sources', function() { it('should include other config sources', function(cb) {
var fp = path.join(__dirname, 'fixtures/_gitconfig'); parse({ path: fixture('_gitconfig'), include: true }, function(err, config) {
assert(!err);
assert.deepEqual(config, require('./expected/_gitconfig.js'));
cb();
});
});
parse({ path: fp, include: true }, function(err, config) { it('should throw an error when .git/config does not exist', function(cb) {
assert(!err); parse({ path: 'foo' }, function(err, config) {
assert.deepEqual(config, require('./expected/_gitconfig.js')); assert(err instanceof Error);
cb(); assert(/ENOENT.*parse-git-config/.test(err.message));
cb();
});
}); });
}); });
it('should throw an error when .git/config does not exist:', function(cb) { describe('promise', function() {
parse({ path: 'foo' }, function(err, config) { it('should return a promise', function(cb) {
assert(err instanceof Error); parse.promise({ path: fixture('_gitconfig') })
assert(/ENOENT.*parse-git-config/.test(err.message)); .then(config => {
cb(); assert(config.hasOwnProperty('core'));
cb();
});
}); });
});
});
describe('resolve:', function() { it('should include other config sources', function() {
it('should resolve the git config in the cwd by default', function() { return parse.promise({ path: fixture('_gitconfig'), include: true })
assert.equal(parse.resolve(), path.resolve(process.cwd(), '.git/config')); .then(config => {
assert.deepEqual(config, require('./expected/_gitconfig.js'));
});
});
}); });
it('should allow override path', function() { describe('sync', function() {
var fp = path.resolve(homedir(), '.gitconfig'); it('should return an object', function() {
assert.equal(parse.resolve({ path: fp }), fp); assert(parse.sync({path: fixture('_gitconfig') }).hasOwnProperty('core'));
});
}); });
it('should include other config sources', function() { describe('.expandKeys', function() {
var fp = path.join(__dirname, 'fixtures/_gitconfig'); it('should expand ini-style keys', function() {
var actual = parse.sync({ path: fp, include: true }); const config = {
assert.deepEqual(actual, require('./expected/_gitconfig.js')); 'foo "bar"': { doStuff: true },
'foo "baz"': { doStuff: true }
};
assert.deepEqual(parse.expandKeys(config), {
foo: {
bar: { doStuff: true },
baz: { doStuff: true }
}
});
});
}); });
it('should resolve relative path to cwd', function() { describe('resolve', function() {
assert.equal(parse.resolve({ path: '.config' }), path.resolve(process.cwd(), '.config')); it('should resolve the git config in the cwd by default', function() {
}); assert.equal(parse.resolve(), path.resolve(process.cwd(), '.git/config'));
});
it('should resolve relative path to the global git config when `global` is passed', function() { it('should allow override path', function() {
if (isTravis && os.platform() === 'darwin') return this.skip(); const fp = path.resolve(homedir(), '.gitconfig');
assert.equal(parse.resolve('global'), path.resolve(homedir(), '.gitconfig')); assert.equal(parse.resolve({ path: fp }), fp);
}); });
it('should allow override of cwd', function() { it('should include other config sources', function() {
var actual = parse.resolve({ path: '.config', cwd: '/opt/config' }); const fp = path.join(__dirname, 'fixtures/_gitconfig');
assert.equal(actual, path.resolve('/opt/config/.config')); const actual = parse.sync({ path: fp, include: true });
}); assert.deepEqual(actual, require('./expected/_gitconfig.js'));
}); });
it('should resolve relative path to cwd', function() {
assert.equal(parse.resolve({ path: '.config' }), path.resolve(process.cwd(), '.config'));
});
it('should resolve relative path to the global git config when `global` is passed', function() {
if (isTravis && os.platform() === 'darwin') return this.skip();
assert.equal(parse.resolve('global'), path.resolve(homedir(), '.gitconfig'));
});
describe('.keys:', function() { it('should allow override of cwd', function() {
it('should parse ini-style keys', function() { const actual = parse.resolve({ path: '.config', cwd: '/opt/config' });
var config = { assert.equal(actual, path.resolve('/opt/config/.config'));
'foo "bar"': { doStuff: true },
'foo "baz"': { doStuff: true }
};
assert.deepEqual(parse.keys(config), {
foo: {
bar: { doStuff: true },
baz: { doStuff: true }
}
}); });
}); });
}); });

Loading…
Cancel
Save