Skip to content

Commit 0bed42a

Browse files
authored
fix(git): read commits from stream
1 parent b1f8559 commit 0bed42a

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/git.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import {execFile} from 'mz/child_process';
2+
import {ChildProcess, execFile, spawn} from 'mz/child_process';
33
import * as chalk from 'chalk';
44
import * as path from 'path';
55
import * as fs from 'mz/fs';
@@ -108,9 +108,40 @@ export async function getNewCommits(since?: Commit): Promise<CommitSequence> {
108108
if (since) {
109109
args.push(headBehindLastMigration ? 'HEAD..' + since.sha1 : since.sha1 + '..HEAD');
110110
}
111-
const [stdout] = await execFile('git', args);
112-
const output = stdout.toString().trim();
113-
const commits = parseGitLog(output);
111+
const commits = await (new Promise<CommitSequence>((resolve, reject) => {
112+
const gitProcess = spawn('git', args);
113+
let buffer = '';
114+
const parsedCommits = new CommitSequence();
115+
gitProcess.stdout.on('data', data => {
116+
buffer += data.toString().trim();
117+
const commitMarkerIndex = buffer.lastIndexOf('>>>>COMMIT\n');
118+
if (commitMarkerIndex !== -1) {
119+
const completeCommits = buffer.substring(0, commitMarkerIndex);
120+
buffer = buffer.substring(commitMarkerIndex);
121+
const parsedLog = parseGitLog(completeCommits);
122+
for (const commit of parsedLog) {
123+
parsedCommits.push(commit);
124+
}
125+
}
126+
});
127+
let errorBuffer = '';
128+
gitProcess.stderr.on('data', data => {
129+
/* istanbul ignore next */
130+
errorBuffer += data.toString();
131+
});
132+
gitProcess.on('error', reject);
133+
gitProcess.on('exit', code => {
134+
/* istanbul ignore next */
135+
if (code !== 0) {
136+
reject(new Error(`git errored: ${code}\n${errorBuffer}`));
137+
}
138+
const parsedLog = parseGitLog(buffer);
139+
for (const commit of parsedLog) {
140+
parsedCommits.push(commit);
141+
}
142+
resolve(parsedCommits);
143+
});
144+
}));
114145
commits.isReversed = headBehindLastMigration;
115146
return commits;
116147
}

0 commit comments

Comments
 (0)