simple-git
Advanced tools
Comparing version 1.32.1 to 1.33.0
{ | ||
"name": "simple-git", | ||
"description": "Simple GIT interface for node.js", | ||
"version": "1.32.1", | ||
"version": "1.33.0", | ||
"author": "Steve King <steve@mydev.co>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -5,2 +5,3 @@ | ||
function BranchSummary () { | ||
this.detached = false; | ||
this.current = ''; | ||
@@ -11,4 +12,5 @@ this.all = []; | ||
BranchSummary.prototype.push = function (current, name, commit, label) { | ||
BranchSummary.prototype.push = function (current, detached, name, commit, label) { | ||
if (current) { | ||
this.detached = detached; | ||
this.current = name; | ||
@@ -25,2 +27,5 @@ } | ||
BranchSummary.detachedRegex = /^(\*?\s+)\(detached from (\S+)\)\s+([a-z0-9]+)\s(.*)$/; | ||
BranchSummary.branchRegex = /^(\*?\s+)(\S+)\s+([a-z0-9]+)\s(.*)$/; | ||
BranchSummary.parse = function (commit) { | ||
@@ -31,6 +36,13 @@ var branchSummary = new BranchSummary(); | ||
.forEach(function (line) { | ||
var branch = /^(\*?\s+)(\S+)\s+([a-z0-9]+)\s(.*)$/.exec(line); | ||
var detached = true; | ||
var branch = BranchSummary.detachedRegex.exec(line); | ||
if (!branch) { | ||
detached = false; | ||
branch = BranchSummary.branchRegex.exec(line); | ||
} | ||
if (branch) { | ||
branchSummary.push( | ||
branch[1].charAt(0) === '*', | ||
detached, | ||
branch[2], | ||
@@ -37,0 +49,0 @@ branch[3], |
@@ -664,2 +664,27 @@ (function () { | ||
/** | ||
* Returns a list of objects in a tree based on commit hash. Passing in an object hash returns the object's content, | ||
* size, and type. | ||
* | ||
* Passing "-p" will instruct cat-file to determine the object type, and display its formatted contents. | ||
* | ||
* @param {string[]} [options] | ||
* @param {Function} [then] | ||
*/ | ||
Git.prototype.catFile = function (options, then) { | ||
var handler = Git.trailingFunctionArgument(arguments); | ||
var command = ['cat-file']; | ||
if (typeof options === 'string') { | ||
throw new TypeError('Git#catFile: options must be supplied as an array of strings'); | ||
} | ||
else if (Array.isArray(options)) { | ||
command.push.apply(command, options); | ||
} | ||
return this._run(command, function (err, data) { | ||
handler && handler(err, data); | ||
}); | ||
}; | ||
/** | ||
* Return repository changes. | ||
@@ -666,0 +691,0 @@ * |
@@ -104,4 +104,20 @@ | ||
'detached branches': function (test) { | ||
var BranchSummary = require('../src/BranchSummary'); | ||
var branchSummary = BranchSummary.parse('\ | ||
* (detached from 1.6.0) 2b2dba2 Add tests for commit\n\ | ||
cflynn07-add-git-ignore a0b67a3 Add support for filenames containing spaces\n\ | ||
master cb4be06 Release 1.30.0\n\ | ||
'); | ||
test.equals('1.6.0', branchSummary.current); | ||
test.equals(true, branchSummary.detached); | ||
test.same(['1.6.0', 'cflynn07-add-git-ignore', 'master'], branchSummary.all); | ||
test.done(); | ||
}, | ||
'gets branch data': function (test) { | ||
git.branch(function (err, branchSummary) { | ||
test.ok(branchSummary instanceof require('../src/BranchSummary'), 'Uses the BranchSummary response type'); | ||
test.equals(null, err, 'not an error'); | ||
@@ -349,2 +365,52 @@ test.equals('drschwabe-add-branches', branchSummary.current); | ||
exports.catFile = { | ||
setUp: function(done) { | ||
Instance(); | ||
done(); | ||
}, | ||
'displays tree for initial commit hash': function(test) { | ||
git.catFile(["-p", "366e4409"], function(err, result) { | ||
test.equals(null, err, 'not an error'); | ||
test.same(["cat-file", "-p", "366e4409"], theCommandRun()); | ||
test.same(([ | ||
'100644 blob bb8fa279535700c922d3f1ffce064cb5d40f793d .gitignore', | ||
'100644 blob 38e7c92830db7dc85d7911d53f7478d9311f4c81 .npmignore', | ||
'100644 blob a7eb4e85cdb50cc270ddf4511e72304c264b0baf package.json', | ||
'100644 blob e9028d5b1f9bd80c7f1b6bacba47cb79b637164a readme.md', | ||
'040000 tree b0a0e1d44895fa659bd62e7d94187adbdf5ba541 src' | ||
].join('\n')), result); | ||
test.done(); | ||
}); | ||
closeWith([ | ||
'100644 blob bb8fa279535700c922d3f1ffce064cb5d40f793d .gitignore', | ||
'100644 blob 38e7c92830db7dc85d7911d53f7478d9311f4c81 .npmignore', | ||
'100644 blob a7eb4e85cdb50cc270ddf4511e72304c264b0baf package.json', | ||
'100644 blob e9028d5b1f9bd80c7f1b6bacba47cb79b637164a readme.md', | ||
'040000 tree b0a0e1d44895fa659bd62e7d94187adbdf5ba541 src' | ||
].join('\n')) | ||
}, | ||
'displays valid usage when no arguments passed': function(test) { | ||
git.catFile(function(err, result) { | ||
// TODO: Add catch for empty response and prompt for valid hash and update test | ||
var errMsg = 'Please pass in a valid (tree/commit/object) hash'; | ||
test.equals(null, err, 'not an error'); | ||
test.same(["cat-file"], theCommandRun()); | ||
test.same(result, errMsg); | ||
test.done(); | ||
}); | ||
closeWith('Please pass in a valid (tree/commit/object) hash') | ||
}, | ||
}; | ||
exports.init = { | ||
@@ -351,0 +417,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
85552
2023