Skip to content

Commit

Permalink
fix(v8): handle error in git apply (#851)
Browse files Browse the repository at this point in the history
Capture stdout so it can be used in the catch block when there is a conflict.

Fixes: #850
  • Loading branch information
targos authored Sep 3, 2024
1 parent c401a77 commit 11d0a04
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions lib/update-v8/minorUpdate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { spawn } from 'node:child_process';
import path from 'node:path';
import { promises as fs } from 'node:fs';

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 11d0a04

Please sign in to comment.