From 86d95da4e988834144b7ae133ff6cfab89363dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 1 Sep 2024 10:05:22 +0200 Subject: [PATCH] fix(v8): handle error in git apply Capture stdout so it can be used in the catch block when there is a conflict. Fixes: https://github.com/nodejs/node-core-utils/issues/850 --- lib/update-v8/minorUpdate.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/update-v8/minorUpdate.js b/lib/update-v8/minorUpdate.js index d14f007a..aa1ffee9 100644 --- a/lib/update-v8/minorUpdate.js +++ b/lib/update-v8/minorUpdate.js @@ -1,4 +1,3 @@ -import { spawn } from 'node:child_process'; import path from 'node:path'; import { promises as fs } from 'node:fs'; @@ -61,30 +60,22 @@ function doMinorUpdate() { } async function applyPatch(ctx, latestStr) { - const diff = spawn( + const diff = await forceRunAsync( 'git', ['format-patch', '--stdout', `${ctx.currentVersion}...${latestStr}`], - { cwd: ctx.v8Dir, stdio: ['ignore', 'pipe', 'ignore'] } + { captureStdout: true, ignoreFailure: false, spawnArgs: { cwd: ctx.v8Dir } } ); try { await forceRunAsync('git', ['apply', '--directory', 'deps/v8'], { + input: diff, ignoreFailure: false, - spawnArgs: { - cwd: ctx.nodeDir, - stdio: [diff.stdout, 'ignore', 'ignore'] - } + spawnArgs: { cwd: ctx.nodeDir } }); } catch (e) { const file = path.join(ctx.nodeDir, `${latestStr}.diff`); await fs.writeFile(file, diff); throw new Error(`Could not apply patch.\n${e}\nDiff was stored in ${file}`); } - if (diff.exitCode !== 0) { - const err = new Error(`git format-patch failed: ${diff.exitCode}`); - err.code = diff.exitCode; - err.messageOnly = true; - throw err; - } } function filterAndSortTags(tags) {