-
Notifications
You must be signed in to change notification settings - Fork 96
/
index.js
executable file
·38 lines (35 loc) · 968 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
29
30
31
32
33
34
35
36
37
38
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 + ']'))
})
}
, exactTag: function(cb){
_command('git describe --exact-match --tags HEAD',function(str){
if (str){
cb(str)
}else{
cb(undefined)
}
})
}
}