resolve global path

master
jonschlinkert 9 years ago
parent 3fb683c02d
commit 936b3f17bc

@ -42,7 +42,6 @@ function parse(options, cb) {
options = options || {};
var filepath = parse.resolve(options);
if (gitCache[filepath]) {
cb(null, gitCache[filepath]);
return;
@ -77,7 +76,6 @@ function parse(options, cb) {
parse.sync = function parseSync(options) {
options = options || {};
var filepath = parse.resolve(options);
if (gitCache[filepath]) {
return gitCache[filepath];
}
@ -93,10 +91,16 @@ parse.sync = function parseSync(options) {
*/
parse.resolve = function resolve(options) {
var isGlobal = false;
if (options === 'global') {
isGlobal = true;
options = {};
}
if (typeof options === 'string') {
options = { path: options };
}
var opts = extend({path: configPath()}, options);
var opts = extend({path: configPath(isGlobal ? 'global' : null)}, options);
if (opts.cwd) {
opts.path = path.resolve(opts.cwd, opts.path);
}

@ -1,7 +1,7 @@
{
"name": "parse-git-config",
"description": "Parse `.git/config` into a JavaScript object. sync or async.",
"version": "0.4.1",
"version": "0.4.2",
"homepage": "https://github.com/jonschlinkert/parse-git-config",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/parse-git-config",
@ -26,7 +26,8 @@
},
"devDependencies": {
"gulp-format-md": "^0.1.7",
"mocha": "^2.4.5"
"mocha": "^2.4.5",
"os-homedir": "^1.0.1"
},
"keywords": [
"config",
@ -60,4 +61,4 @@
"reflinks": true
}
}
}
}

@ -10,6 +10,7 @@
require('mocha');
var assert = require('assert');
var path = require('path');
var home = require('os-homedir');
var parse = require('./');
describe('sync:', function() {
@ -52,7 +53,7 @@ describe('resolve:', function() {
});
it('should allow override path', function() {
var fp = path.resolve(process.env.HOME, '.gitconfig');
var fp = path.resolve(home(), '.gitconfig');
assert.equal(parse.resolve({path: fp}), fp);
});
@ -60,6 +61,10 @@ describe('resolve:', 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() {
assert.equal(parse.resolve('global'), path.resolve(home(), '.gitconfig'));
});
it('should allow override of cwd', function() {
var actual = parse.resolve({path: '.config', cwd: '/opt/config'});
assert.equal(actual, path.resolve('/opt/config/.config'));

Loading…
Cancel
Save