simple-git
Advanced tools
Comparing version 1.13.0 to 1.14.0
{ | ||
"name": "simple-git", | ||
"description": "Simple GIT interface for node.js", | ||
"version": "1.13.0", | ||
"version": "1.14.0", | ||
"author": "Steve King <steve@mydev.co>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -79,2 +79,5 @@ # Simple Git | ||
`.getRemotes([verbose], handlerFn)` gets a list of the named remotes, when the verbose option is supplied as true, | ||
includes the URLs and purpose of each ref. | ||
`.reset(resetMode, handlerFn)` resets the repository (resetMode can be 'hard' or 'soft', handlerFn: (err)) | ||
@@ -81,0 +84,0 @@ |
@@ -325,13 +325,11 @@ (function () { | ||
Git.prototype.listRemote = function (args, then) { | ||
if (!then && typeof args === "function") { | ||
then = args; | ||
args = []; | ||
} | ||
var next = Git.trailingFunctionArgument(arguments); | ||
var data = next === args || args === undefined ? [] : args; | ||
if (typeof args === 'string') { | ||
if (typeof data === 'string') { | ||
this._getLog('warn', 'Git#listRemote: args should be supplied as an array of individual arguments'); | ||
} | ||
return this._run(['ls-remote'].concat(args), function (err, data) { | ||
then && then(err, data); | ||
return this._run(['ls-remote'].concat(data), function (err, data) { | ||
next && next(err, data); | ||
}); | ||
@@ -368,2 +366,58 @@ }; | ||
/** | ||
* Gets the currently available remotes, setting the optional verbose argument to true includes additional | ||
* detail on the remotes themselves. | ||
* | ||
* @param {boolean} [verbose=false] | ||
* @param {Function} [then] | ||
*/ | ||
Git.prototype.getRemotes = function (verbose, then) { | ||
var next = Git.trailingFunctionArgument(arguments); | ||
var args = verbose === true ? ['-v'] : []; | ||
return this.remote(args, function (err, data) { | ||
next(err, !err && function () { | ||
return data.trim().split('\n').reduce(function (remotes, remote) { | ||
var detail = remote.trim().split(/\s+/); | ||
var name = detail.shift(); | ||
if (!remotes[name]) { | ||
remotes[name] = remotes[remotes.length] = { | ||
name: name, | ||
refs: {} | ||
}; | ||
} | ||
if (detail.length) { | ||
remotes[name].refs[detail.pop().replace(/[^a-z]/g, '')] = detail.pop(); | ||
} | ||
return remotes; | ||
}, []).slice(0); | ||
}()); | ||
}); | ||
}; | ||
/** | ||
* Call any `git remote` function with arguments passed as an array of strings. | ||
* | ||
* @param {string[]} options | ||
* @param {Function} [then] | ||
*/ | ||
Git.prototype.remote = function (options, then) { | ||
if (!Array.isArray(options)) { | ||
return this.then(function () { | ||
then && then(new TypeError("Git.remote requires an array of arguments")); | ||
}); | ||
} | ||
if (options[0] !== 'remote') { | ||
options.unshift('remote'); | ||
} | ||
return this._run(options, function (err, data) { | ||
then && then(err || null, err ? null : data); | ||
}); | ||
}; | ||
/** | ||
* Pushes the current committed changes to a remote, optionally specify the names of the remote and branch to use | ||
@@ -370,0 +424,0 @@ * when pushing. |
@@ -228,2 +228,44 @@ | ||
exports.remotes = { | ||
setUp: function (done) { | ||
Instance(); | ||
done(); | ||
}, | ||
'get list': function (test) { | ||
git.getRemotes(function (err, result) { | ||
test.equals(null, err, 'not an error'); | ||
test.same(["remote"], theCommandRun()); | ||
test.same([ | ||
{name: 'origin', refs: {}}, | ||
{name: 'upstream', refs: {}} | ||
], result, 'parses response'); | ||
test.done(); | ||
}); | ||
closeWith('\ | ||
origin\n\ | ||
upstream'); | ||
}, | ||
'get verbose list': function (test) { | ||
git.getRemotes(true, function (err, result) { | ||
test.equals(null, err, 'not an error'); | ||
test.same(["remote", "-v"], theCommandRun()); | ||
test.same([ | ||
{name: 'origin', refs: {fetch: 's://u@d.com/u/repo.git', push: 's://u@d.com/u/repo.git'}}, | ||
{name: 'upstream', refs: {fetch: 's://u@d.com/another/repo.git', push: 's://u@d.com/another/repo.git'}} | ||
], result, 'parses response'); | ||
test.done(); | ||
}); | ||
closeWith('\ | ||
origin s://u@d.com/u/repo.git (fetch)\n\ | ||
origin s://u@d.com/u/repo.git (push)\n\ | ||
upstream s://u@d.com/another/repo.git (fetch)\n\ | ||
upstream s://u@d.com/another/repo.git (push)\n\ | ||
'); | ||
} | ||
}; | ||
exports.reset = { | ||
@@ -230,0 +272,0 @@ setUp: function (done) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51297
1167
169