This repository has been archived by the owner on Feb 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
71 lines (57 loc) · 1.61 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
var dargs = require('dargs');
var execFile = require('child_process').execFile;
var split = require('split2');
var stream = require('stream');
var template = require('lodash.template');
var through = require('through2');
function gitRawCommits(options) {
var readable = new stream.Readable();
readable._read = function() {};
options = options || {};
options.format = options.format || '%B';
options.from = options.from || '';
options.to = options.to || 'HEAD';
var gitFormat = template('--format=<%= format %>%n' +
'------------------------ >8 ------------------------'
)(options);
var gitFromTo = template('<%- from ? [from, to].join("..") : to %>')(options);
var args = dargs(options, {
excludes: ['from', 'to', 'format']
});
args = [
'log',
gitFormat,
gitFromTo
].concat(args);
if (options.debug) {
options.debug('Your git-log command is:\ngit ' + args.join(' '));
}
var isError = false;
var child = execFile('git', args, {
maxBuffer: Infinity
});
child.stdout
.pipe(split('------------------------ >8 ------------------------\n'))
.pipe(through(function(chunk, enc, cb) {
readable.push(chunk);
isError = false;
cb();
}, function(cb) {
setImmediate(function() {
if (!isError) {
readable.push(null);
readable.emit('close');
}
cb();
});
}));
child.stderr
.pipe(through.obj(function(chunk) {
isError = true;
readable.emit('error', new Error(chunk));
readable.emit('close');
}));
return readable;
}
module.exports = gitRawCommits;