|
|
@ -9,7 +9,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
var extend = require('extend-shallow');
|
|
|
|
|
|
|
|
var configPath = require('git-config-path');
|
|
|
|
var ini = require('ini');
|
|
|
|
var ini = require('ini');
|
|
|
|
|
|
|
|
var gitCache = {};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Asynchronously parse a `.git/config` file. If only the callback is passed,
|
|
|
|
* Asynchronously parse a `.git/config` file. If only the callback is passed,
|
|
|
@ -40,12 +43,19 @@ function parse(options, cb) {
|
|
|
|
options = options || {};
|
|
|
|
options = options || {};
|
|
|
|
var filepath = parse.resolve(options);
|
|
|
|
var filepath = parse.resolve(options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gitCache[filepath]) {
|
|
|
|
|
|
|
|
cb(null, gitCache[filepath]);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fs.stat(filepath, function(err, stat) {
|
|
|
|
fs.stat(filepath, function(err, stat) {
|
|
|
|
if (err) return cb(err);
|
|
|
|
if (err) return cb(err);
|
|
|
|
|
|
|
|
|
|
|
|
fs.readFile(filepath, 'utf8', function(err, str) {
|
|
|
|
fs.readFile(filepath, 'utf8', function(err, str) {
|
|
|
|
if (err) return cb(err);
|
|
|
|
if (err) return cb(err);
|
|
|
|
cb(null, ini.parse(str));
|
|
|
|
var parsed = ini.parse(str);
|
|
|
|
|
|
|
|
gitCache[filepath] = parsed;
|
|
|
|
|
|
|
|
cb(null, parsed);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -67,9 +77,13 @@ function parse(options, cb) {
|
|
|
|
parse.sync = function parseSync(options) {
|
|
|
|
parse.sync = function parseSync(options) {
|
|
|
|
options = options || {};
|
|
|
|
options = options || {};
|
|
|
|
var filepath = parse.resolve(options);
|
|
|
|
var filepath = parse.resolve(options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gitCache[filepath]) {
|
|
|
|
|
|
|
|
return gitCache[filepath];
|
|
|
|
|
|
|
|
}
|
|
|
|
if (exists(filepath)) {
|
|
|
|
if (exists(filepath)) {
|
|
|
|
var str = fs.readFileSync(filepath, 'utf8');
|
|
|
|
var str = fs.readFileSync(filepath, 'utf8');
|
|
|
|
return ini.parse(str);
|
|
|
|
return (gitCache[filepath] = ini.parse(str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
return {};
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -79,17 +93,14 @@ parse.sync = function parseSync(options) {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
parse.resolve = function resolve(options) {
|
|
|
|
parse.resolve = function resolve(options) {
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
var cwd;
|
|
|
|
|
|
|
|
if (typeof options === 'string') {
|
|
|
|
if (typeof options === 'string') {
|
|
|
|
cwd = path.resolve(options);
|
|
|
|
options = { path: options };
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
} else if (options.cwd) {
|
|
|
|
var opts = extend({path: configPath()}, options);
|
|
|
|
cwd = options.cwd;
|
|
|
|
if (opts.cwd) {
|
|
|
|
} else {
|
|
|
|
opts.path = path.resolve(opts.cwd, opts.path);
|
|
|
|
cwd = process.cwd();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return path.resolve(cwd, options.path || '.git/config');
|
|
|
|
return path.resolve(opts.path);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|