From d7b00dff7faee127b166accbb8794f042eac95a4 Mon Sep 17 00:00:00 2001 From: gzaripov Date: Sat, 23 May 2020 13:03:27 +0300 Subject: [PATCH 1/2] fix: wait for close event on spawned process in local git --- source/platforms/git/localGetCommits.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/source/platforms/git/localGetCommits.ts b/source/platforms/git/localGetCommits.ts index 9d132a0a0..716b7abc8 100644 --- a/source/platforms/git/localGetCommits.ts +++ b/source/platforms/git/localGetCommits.ts @@ -21,13 +21,14 @@ const committer = `"committer": {"name": "${committerName}", "email": "${committ export const formatJSON = `{ "sha": "${sha}", "parents": "${parents}", ${author}, ${committer}, "message": "${message}"},` export const localGetCommits = (base: string, head: string) => - new Promise(done => { + new Promise((resolve, reject) => { const args = ["log", `${base}...${head}`, `--pretty=format:${formatJSON}`] const child = spawn("git", args, { env: process.env }) d("> git", args.join(" ")) - child.stdout.on("data", async data => { - data = data.toString() + const commits: GitCommit[] = [] + child.stdout.on("data", async (chunk: Buffer) => { + const data = chunk.toString() // remove trailing comma, and wrap into an array const asJSONString = `[${data.substring(0, data.length - 1)}]` const commits = JSON5.parse(asJSONString) @@ -36,11 +37,21 @@ export const localGetCommits = (base: string, head: string) => parents: c.parents.split(" "), })) - done(realCommits) + commits.push(...realCommits) }) - child.stderr.on("data", data => { - console.error(`Could not get commits from git between ${base} and ${head}`) - throw new Error(data.toString()) + child.stderr.on("end", () => resolve(commits)) + + const errorParts: string[] = [] + + child.stderr.on("data", (chunk: Buffer) => errorParts.push(chunk.toString())) + + child.on("close", code => { + if (code !== 0) { + console.error(`Could not get commits from git between ${base} and ${head}`) + reject(new Error(errorParts.join(""))) + } else { + resolve(commits) + } }) }) From d87f978522799553dcab6365f63c54fe7079114e Mon Sep 17 00:00:00 2001 From: gzaripov Date: Mon, 25 May 2020 11:19:57 +0300 Subject: [PATCH 2/2] chore: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52039936c..cbb628b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ x -- Fix danger failure on getting diff for files with spaces in file path [@HonzaMac] +- Wait for close event on spawned process in local git platform - [@gzaripov]