-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-info.js
36 lines (26 loc) · 1 KB
/
git-info.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
var exec = require('child_process').exec;
var commit_rev_cmd = "git rev-list HEAD --max-count=1";
var uncommitted_cmd = "git status --porcelain"
function addUncommitted (doc, callback) {
exec(uncommitted_cmd, function(err, stdout, stderr) {
var uncommitted = stdout.trim();
doc.kanso.git.uncommitted = uncommitted.split('\n');
if (doc.kanso.git.uncommitted && doc.kanso.git.uncommitted.length == 1 && doc.kanso.git.uncommitted[0] == "") {
doc.kanso.git.uncommitted = [];
}
callback(null, doc);
});
}
module.exports = {
run : function(root, path, settings, doc, callback) {
exec(commit_rev_cmd, function(error, stdout, stderr) {
if (!doc.kanso) doc.kanso = {};
doc.kanso.git = {}
doc.kanso.git.commit = stdout.trim();
if (settings.git_info && settings.git_info.skip_uncommitted) {
return callback(null, doc);
}
addUncommitted(doc, callback);
})
}
}