-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.js
More file actions
52 lines (46 loc) · 1.22 KB
/
git.js
File metadata and controls
52 lines (46 loc) · 1.22 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var exec = require('child_process').exec;
var temp = require('temp');
var fs = require('fs');
var log = require('./logger');
exports.head = function (path, callback) {
exec('git --git-dir=' + path + ".git log -1 --pretty=format:'%H%n%an <%ae>%n%ad%n%s%n'", function(err, stdout, stderr) {
var str = stdout.split('\n');
var commit = {
commit: str[0],
author: str[1],
date: str[2],
message: str[3]
};
callback(err, commit);
});
};
exports.get = function(path, file, revision, callback) {
exec('git --git-dir=' + path + ".git show "+revision+":"+file, function(err, stdout, stderr) {
callback(err, stdout);
});
}
exports.commit = function (path, author, message, callback) {
temp.open('bombastic', function(err, info) {
if (err) {
log.error("Can't create temporaty file " + info.path);
callback();
}
log.debug('Write commit message into temporary file ' + info.path);
fs.write(info.fd, message);
fs.close(info.fd, function(err) {
var command = [__dirname + '/scripts/commit.sh ',
path,
' "',
author.name,
' <',
author.email,
'> " "',
info.path,
'"'].join('');
exec(command, function(error, stdout, stderr) {
log.debug(stdout);
callback();
});
});
});
};