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/2] 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/2] 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 = []