|
1 | 1 |
|
2 | | -import {execFile} from 'mz/child_process'; |
| 2 | +import {ChildProcess, execFile, spawn} from 'mz/child_process'; |
3 | 3 | import * as chalk from 'chalk'; |
4 | 4 | import * as path from 'path'; |
5 | 5 | import * as fs from 'mz/fs'; |
@@ -108,9 +108,40 @@ export async function getNewCommits(since?: Commit): Promise<CommitSequence> { |
108 | 108 | if (since) { |
109 | 109 | args.push(headBehindLastMigration ? 'HEAD..' + since.sha1 : since.sha1 + '..HEAD'); |
110 | 110 | } |
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 | + })); |
114 | 145 | commits.isReversed = headBehindLastMigration; |
115 | 146 | return commits; |
116 | 147 | } |
|
0 commit comments