git-last-commit
Advanced tools
Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "git-last-commit", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Read details of the last commit including tags", | ||
@@ -5,0 +5,0 @@ "main": "./source/index.js", |
@@ -46,2 +46,13 @@ # git-last-commit | ||
}, {dst: 'some/other/path'}); | ||
``` | ||
``` | ||
Function uses comma as the format separator for the `git log` command output. You can customise this by providing another character using `splitChar` option: | ||
```javascript | ||
var git = require('git-last-commit'); | ||
git.getLastCommit(function(err, commit) { | ||
// read commit object properties | ||
console.log(commit); | ||
}, {splitChar: '|'}); | ||
``` |
var process = require('child_process'), | ||
options = {}; | ||
options = {}, | ||
splitCharacter = ','; | ||
@@ -17,3 +18,3 @@ function _command(command, callback) { | ||
if (stderr) { | ||
if (stderr) { | ||
callback(stderr); | ||
@@ -23,9 +24,11 @@ return; | ||
callback(null, stdout.split('\n').join(',')); | ||
callback(null, stdout.split('\n').join(splitCharacter)); | ||
}); | ||
} | ||
var command = | ||
'git log -1 --pretty=format:"%h,%H,%s,%f,%b,%at,%ct,%an,%ae,%cn,%ce,%N,"' + | ||
' && git rev-parse --abbrev-ref HEAD' + | ||
var prettyFormat = ["%h", "%H", "%s", "%f", "%b", "%at", "%ct", "%an", "%ae", "%cn", "%ce", "%N"]; | ||
var command = | ||
'git log -1 --pretty=format:"' + prettyFormat.join(splitCharacter) +'"' + | ||
' && git rev-parse --abbrev-ref HEAD' + | ||
' && git tag --contains HEAD'; | ||
@@ -36,2 +39,7 @@ | ||
options = _options; | ||
if (!!options && options.splitChar) { | ||
splitCharacter = options.splitChar; | ||
} | ||
_command(command, function(err, res) { | ||
@@ -42,5 +50,5 @@ if (err) { | ||
} | ||
var a = res.split(','); | ||
var a = res.split(splitCharacter); | ||
var tags = []; | ||
@@ -73,2 +81,2 @@ if (a[a.length-1] !== '') { | ||
} | ||
}; | ||
}; |
@@ -16,3 +16,3 @@ /*jshint expr: true*/ | ||
expect(commit.sanitizedSubject).to.match(/.+/); | ||
expect(commit.body).to.be.empty; | ||
expect(commit.body).to.match(/.*/); | ||
expect(commit.authoredOn).to.match(/\d{10}/); | ||
@@ -24,3 +24,3 @@ expect(commit.committedOn).to.match(/\d{10}/); | ||
expect(commit.committer.email).to.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/); | ||
expect(commit.branch).to.match(/.+/); | ||
expect(commit.branch).to.match(/.*/); | ||
expect(commit.tags).to.be.instanceOf(Array); | ||
@@ -31,2 +31,2 @@ | ||
}); | ||
}); | ||
}); |
@@ -143,2 +143,27 @@ /*jshint expr: true*/ | ||
it('should parse git commands when a custom split character is specified', function(done) { | ||
processExecMethod.yields(null, '26e689d¬26e689d8769908329a145201be5081233c711663¬initial commit¬initial-commit¬this is the body¬1437984178¬1437984179¬Author1¬author@gmail.com¬Committer1¬committer@gmail.com¬note 1\nmaster\nR1'); | ||
git.getLastCommit(function(err, commit) { | ||
expect(err).to.be.null; | ||
expect(commit).to.be.ok; | ||
expect(commit.shortHash).to.be.equal('26e689d'); | ||
expect(commit.hash).to.be.equal('26e689d8769908329a145201be5081233c711663'); | ||
expect(commit.subject).to.be.equal('initial commit'); | ||
expect(commit.sanitizedSubject).to.be.equal('initial-commit'); | ||
expect(commit.body).to.be.equal('this is the body'); | ||
expect(commit.authoredOn).to.be.equal('1437984178'); | ||
expect(commit.committedOn).to.be.equal('1437984179'); | ||
expect(commit.author.name).to.be.equal('Author1'); | ||
expect(commit.author.email).to.be.equal('author@gmail.com'); | ||
expect(commit.committer.name).to.be.equal('Committer1'); | ||
expect(commit.committer.email).to.be.equal('committer@gmail.com'); | ||
expect(commit.branch).to.be.equal('master'); | ||
expect(commit.notes).to.be.equal('note 1'); | ||
expect(commit.tags).to.have.members(['R1']); | ||
done(); | ||
}, { splitChar: '¬' }); | ||
}); | ||
it('should run the git command on given destination', function(done) { | ||
@@ -145,0 +170,0 @@ processExecMethod.yields(null, '26e689d,26e689d8769908329a145201be5081233c711663,initial commit,initial-commit,this is the body,1437984178,1437984179,Author1,author@gmail.com,Committer1,committer@gmail.com,note 1\nmaster\nR2\nR1'); |
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
15960
283
58