From 76a683ceb09fe4eac37ba3089f5ca877184ebe4d Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 20 Nov 2026 12:40:50 +0100 Subject: [PATCH 1/6] chore: remove `gitexec` in favor of built-in `spawn` --- branch-diff.js | 57 ++++++++++++++++++++++++++++++++++++++------------ package.json | 1 - 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/branch-diff.js b/branch-diff.js index 6c206f5..1db51a9 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) @@ -47,9 +48,22 @@ 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 cp = spawn('git', ['merge-base', branch1, branch2], { + cwd: repoPath, + stdio: ['ignore', 'pipe', 'inherit'] + }) + const closeEv = once(cp, 'close'); + closeEv.catch(() => {}) + + const chunks = await Promise.race([ + once(cp, 'error').then(e => Promise.reject(e[0])), + cp.stdout.toArray() + ]) + const [code, signal] = await closeEv + if (code !== 0) { + throw new Error(`Command "git merge-base ${branch1} ${branch2}" exited with code ${code} and signal ${signal}`) + } + return Buffer.concat(chunks).toString('utf-8', 0, 10) } function normalizeIfTrailingSlash (commit) { @@ -107,16 +121,33 @@ async function collect (repoPath, branch, startCommit, endRef) { const untilcmd = endRef ? replace(commitdatecmd, { refcmd: endrefcmd }) : '' const _gitcmd = replace(gitcmd, { branch, startCommit, untilcmd }) + const cp = spawn(_gitcmd, [], { + shell: true, + cwd: repoPath, + stdio: ['ignore', 'pipe', 'inherit'] + }) + const closeEv = once(cp, 'close'); + closeEv.catch(() => {}) + const commitList = [] - await pipeline( - gitexec.exec(repoPath, _gitcmd), - split2(), - commitStream(ghId.user, ghId.repo), - async function * (source) { - for await (const commit of source) { - commitList.push(commit) + await Promise.race([ + once(cp, 'error').then(e => Promise.reject(e[0])), + pipeline( + cp.stdout, + split2(), + commitStream(ghId.user, ghId.repo), + async function * (source) { + for await (const commit of source) { + commitList.push(commit) + } } - }) + ) + ]) + const [code, signal] = await closeEv + if (code !== 0) { + throw new Error(`Command "${_gitcmd}" exited with code ${code} and signal ${signal}`) + } + 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" }, From b64ad90072f6936f1bd8f59f68970c568f1769b1 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 20 Nov 2026 12:54:07 +0100 Subject: [PATCH 2/6] fixup! chore: remove `gitexec` in favor of built-in `spawn` --- branch-diff.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/branch-diff.js b/branch-diff.js index 1db51a9..c466879 100755 --- a/branch-diff.js +++ b/branch-diff.js @@ -52,7 +52,7 @@ async function findMergeBase (repoPath, branch1, branch2) { cwd: repoPath, stdio: ['ignore', 'pipe', 'inherit'] }) - const closeEv = once(cp, 'close'); + const closeEv = once(cp, 'close') closeEv.catch(() => {}) const chunks = await Promise.race([ @@ -126,7 +126,7 @@ async function collect (repoPath, branch, startCommit, endRef) { cwd: repoPath, stdio: ['ignore', 'pipe', 'inherit'] }) - const closeEv = once(cp, 'close'); + const closeEv = once(cp, 'close') closeEv.catch(() => {}) const commitList = [] From 3521f38cd7fef596feffc5d4f7d9b8f8565941da Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 21 Nov 2026 09:51:58 +0100 Subject: [PATCH 3/6] fixup! chore: remove `gitexec` in favor of built-in `spawn` --- branch-diff.js | 68 ++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/branch-diff.js b/branch-diff.js index c466879..68ff76a 100755 --- a/branch-diff.js +++ b/branch-diff.js @@ -34,6 +34,25 @@ function replace (s, m) { return s } +async function spawnPromisified (...args) { + const callback = args.pop() + const cp = spawn(...args) + + const closeEv = once(cp, 'close') + closeEv.catch(() => {}) + + const result = await Promise.race([ + once(cp, 'error').then(e => Promise.reject(e[0])), + callback(cp.stdout) + ]) + const [code, signal] = await closeEv + if (code !== 0) { + throw new Error(`Command "${args[0]} ${args[1].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') @@ -48,21 +67,10 @@ export async function branchDiff (branch1, branch2, options) { } async function findMergeBase (repoPath, branch1, branch2) { - const cp = spawn('git', ['merge-base', branch1, branch2], { + const chunks = await spawnPromisified('git', ['merge-base', branch1, branch2], { cwd: repoPath, stdio: ['ignore', 'pipe', 'inherit'] - }) - const closeEv = once(cp, 'close') - closeEv.catch(() => {}) - - const chunks = await Promise.race([ - once(cp, 'error').then(e => Promise.reject(e[0])), - cp.stdout.toArray() - ]) - const [code, signal] = await closeEv - if (code !== 0) { - throw new Error(`Command "git merge-base ${branch1} ${branch2}" exited with code ${code} and signal ${signal}`) - } + }, stdout => stdout.toArray()) return Buffer.concat(chunks).toString('utf-8', 0, 10) } @@ -121,33 +129,21 @@ async function collect (repoPath, branch, startCommit, endRef) { const untilcmd = endRef ? replace(commitdatecmd, { refcmd: endrefcmd }) : '' const _gitcmd = replace(gitcmd, { branch, startCommit, untilcmd }) - const cp = spawn(_gitcmd, [], { + const commitList = [] + await spawnPromisified(_gitcmd, [], { shell: true, cwd: repoPath, stdio: ['ignore', 'pipe', 'inherit'] - }) - const closeEv = once(cp, 'close') - closeEv.catch(() => {}) - - const commitList = [] - await Promise.race([ - once(cp, 'error').then(e => Promise.reject(e[0])), - pipeline( - cp.stdout, - split2(), - commitStream(ghId.user, ghId.repo), - async function * (source) { - for await (const commit of source) { - commitList.push(commit) - } + }, (stdout) => pipeline( + stdout, + split2(), + commitStream(ghId.user, ghId.repo), + async function * (source) { + for await (const commit of source) { + commitList.push(commit) } - ) - ]) - const [code, signal] = await closeEv - if (code !== 0) { - throw new Error(`Command "${_gitcmd}" exited with code ${code} and signal ${signal}`) - } - + } + )) return commitList } From 4f94ac30150dda3d67ff081b569b82030dc5fe71 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Sat, 28 Nov 2026 22:48:16 +1300 Subject: [PATCH 4/6] Apply suggestion from @rvagg --- branch-diff.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/branch-diff.js b/branch-diff.js index 68ff76a..7e2acff 100755 --- a/branch-diff.js +++ b/branch-diff.js @@ -34,22 +34,12 @@ function replace (s, m) { return s } -async function spawnPromisified (...args) { - const callback = args.pop() - const cp = spawn(...args) - - const closeEv = once(cp, 'close') - closeEv.catch(() => {}) - - const result = await Promise.race([ - once(cp, 'error').then(e => Promise.reject(e[0])), - callback(cp.stdout) - ]) - const [code, signal] = await closeEv +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 "${args[0]} ${args[1].join(' ')}" exited with ${signal || code}`) + throw new Error(`Command "${[cmd, ...args].join(' ')}" exited with ${signal || code}`) } - return result } From fca87bc2a2ca0c506bfe82879fab2c24e3c6f3b7 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Sat, 28 Nov 2026 22:48:22 +1300 Subject: [PATCH 5/6] Apply suggestion from @rvagg --- branch-diff.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/branch-diff.js b/branch-diff.js index 7e2acff..bd9a954 100755 --- a/branch-diff.js +++ b/branch-diff.js @@ -57,7 +57,7 @@ export async function branchDiff (branch1, branch2, options) { } async function findMergeBase (repoPath, branch1, branch2) { - const chunks = await spawnPromisified('git', ['merge-base', branch1, branch2], { + const chunks = await spawnCollect('git', ['merge-base', branch1, branch2], { cwd: repoPath, stdio: ['ignore', 'pipe', 'inherit'] }, stdout => stdout.toArray()) From 7dcd96ed44cee415be0a2ef869cc48f646809585 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Sat, 28 Nov 2026 22:48:30 +1300 Subject: [PATCH 6/6] Apply suggestion from @rvagg --- branch-diff.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/branch-diff.js b/branch-diff.js index bd9a954..c4c9f09 100755 --- a/branch-diff.js +++ b/branch-diff.js @@ -120,7 +120,7 @@ async function collect (repoPath, branch, startCommit, endRef) { const _gitcmd = replace(gitcmd, { branch, startCommit, untilcmd }) const commitList = [] - await spawnPromisified(_gitcmd, [], { + await spawnCollect(_gitcmd, [], { shell: true, cwd: repoPath, stdio: ['ignore', 'pipe', 'inherit']