diff --git a/branch-diff.js b/branch-diff.js index 6c206f5..c4c9f09 100755 --- a/branch-diff.js +++ b/branch-diff.js @@ -5,14 +5,15 @@ import { createRequire } from 'module' import path from 'path' import process from 'process' import { pipeline } from 'stream/promises' -import { parseArgs, promisify } from 'util' +import { spawn } from 'child_process' +import { once } from 'events' +import { parseArgs } from 'util' import commitStream from 'commit-stream' import split2 from 'split2' import pkgtoId from 'pkg-to-id' import { isReleaseCommit } from 'changelog-maker/groups' import { processCommits } from 'changelog-maker/process-commits' import { collectCommitLabels } from 'changelog-maker/collect-commit-labels' -import gitexec from 'gitexec' const pkgFile = path.join(process.cwd(), 'package.json') const require = createRequire(import.meta.url) @@ -33,6 +34,15 @@ function replace (s, m) { return s } +async function spawnCollect (cmd, args, opts, consume) { + const cp = spawn(cmd, args, opts) + const [result, [code, signal]] = await Promise.all([consume(cp.stdout), once(cp, 'close')]) + if (code !== 0) { + throw new Error(`Command "${[cmd, ...args].join(' ')}" exited with ${signal || code}`) + } + return result +} + export async function branchDiff (branch1, branch2, options) { if (!branch1 || !branch2) { throw new Error('Must supply two branch names to compare') @@ -47,9 +57,11 @@ export async function branchDiff (branch1, branch2, options) { } async function findMergeBase (repoPath, branch1, branch2) { - const gitcmd = `git merge-base ${branch1} ${branch2}` - const data = await promisify(gitexec.execCollect)(repoPath, gitcmd) - return data.substr(0, 10) + const chunks = await spawnCollect('git', ['merge-base', branch1, branch2], { + cwd: repoPath, + stdio: ['ignore', 'pipe', 'inherit'] + }, stdout => stdout.toArray()) + return Buffer.concat(chunks).toString('utf-8', 0, 10) } function normalizeIfTrailingSlash (commit) { @@ -108,15 +120,20 @@ async function collect (repoPath, branch, startCommit, endRef) { const _gitcmd = replace(gitcmd, { branch, startCommit, untilcmd }) const commitList = [] - await pipeline( - gitexec.exec(repoPath, _gitcmd), + await spawnCollect(_gitcmd, [], { + shell: true, + cwd: repoPath, + stdio: ['ignore', 'pipe', 'inherit'] + }, (stdout) => pipeline( + stdout, split2(), commitStream(ghId.user, ghId.repo), async function * (source) { for await (const commit of source) { commitList.push(commit) } - }) + } + )) return commitList } diff --git a/package.json b/package.json index 795478b..85be4eb 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "dependencies": { "changelog-maker": "^5.0.5", "commit-stream": "^2.0.1", - "gitexec": "^2.0.1", "pkg-to-id": "^0.0.3", "split2": "^4.2.0" },