forked from tblobaum/git-rev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·28 lines (26 loc) · 790 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var exec = require('child_process').exec
function _command (cmd, cb) {
exec(cmd, { cwd: __dirname }, function (err, stdout, stderr) {
cb(stdout.split('\n').join(''))
})
}
module.exports = {
short : function (cb) {
_command('git rev-parse --short HEAD', cb)
}
, long : function (cb) {
_command('git rev-parse HEAD', cb)
}
, branch : function (cb) {
_command('git rev-parse --abbrev-ref HEAD', cb)
}
, tag : function (cb) {
_command('git describe --always --tag --abbrev=0', cb)
}
, log : function (cb) {
_command('git log --no-color --pretty=format:\'[ "%H", "%s", "%cr", "%an" ],\' --abbrev-commit', function (str) {
str = str.substr(0, str.length-1)
cb(JSON.parse('[' + str + ']'))
})
}
}