Skip to content

Commit 49b15b8

Browse files
committed
git: do not return prematurely from the git() function
When passing a `lineHandler` to the `git()` function, we want to return only when all of the lines have been processed. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 027eaa1 commit 49b15b8

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

lib/git.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,10 @@ export function git(args: string[], options?: IGitOptions | undefined):
4545
if (!process.stdout) {
4646
throw new Error(`No stdout for "git ${args.join(" ")}`);
4747
}
48-
let linePromise: Promise<void> | undefined;
48+
const promises: Array<Promise<void>> = [];
4949
const handleLine = (line: string): boolean => {
5050
try {
51-
if (!linePromise) {
52-
linePromise = lineHandler(line);
53-
} else {
54-
linePromise = linePromise.then(() => {
55-
return lineHandler(line);
56-
});
57-
}
58-
linePromise.catch((reason) => {
59-
reject(reason);
60-
process.kill();
61-
});
51+
promises.push(lineHandler(line));
6252
} catch (reason) {
6353
reject(reason);
6454
process.kill();
@@ -84,12 +74,7 @@ export function git(args: string[], options?: IGitOptions | undefined):
8474
if (buffer.length > 0) {
8575
handleLine(buffer);
8676
}
87-
if (linePromise) {
88-
linePromise.then(() => { resolve(""); })
89-
.catch((reason) => { reject(reason); });
90-
} else {
91-
resolve("");
92-
}
77+
Promise.all(promises).then(() => resolve("")).catch(reject);
9378
});
9479
};
9580
}

0 commit comments

Comments
 (0)