Skip to content

Commit f838c7e

Browse files
committed
release(gitforwindows.org): better failure reports of git invocations
When trying to update the site to reflect that Git for Windows v2.49.0 was released, the workflow failed with: [...] Pushing updates to git-for-windows/git-for-windows.github.io Cloning into 'git-for-windows.github.io'... Reset branch 'main' Auto-detected version 2.49.0 (Mon, 17 Mar 2025 09:40:38 UTC) Error: git commit -a -s -m New Git for Windows version failed with status 1 at callProg (/home/runner/work/git-for-windows-automation/git-for-windows-automation/repository-updates.js:8:33) at callGit (/home/runner/work/git-for-windows-automation/git-for-windows-automation/repository-updates.js:13:10) at pushRepositoryUpdate (/home/runner/work/git-for-windows-automation/git-for-windows-automation/repository-updates.js:124:5) at eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35424:16), <anonymous>:4:7) at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35425:12) at main (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35522:26) at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:35497:1 at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:35553:3 at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35556:12) at Module._compile (node:internal/modules/cjs/loader:1469:14) Error: Unhandled error: Error: git commit -a -s -m New Git for Windows version failed with status 1 [...] This is not helpful. The (hidden) `stdout` wanted to say this: On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean Let's unhide that kind of errors. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 54a6a53 commit f838c7e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

repository-updates.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
const maybeQuote = (arg) =>
2+
!arg.match(/[ "']/) ? arg : `'${arg.replace(/'/g, "'\\''")}'`
3+
const prettyPrintCommand = (prog, parameters) =>
4+
`${maybeQuote(prog)} ${parameters.map(maybeQuote).join(' ')}`
15
const callProg = (prog, parameters, cwd) => {
26
const { spawnSync } = require('child_process')
37
const child = spawnSync(prog, parameters, {
48
stdio: ['ignore', 'pipe', 'inherit'],
59
cwd
610
})
7-
if (child.error) throw child.error
8-
if (child.status !== 0) throw new Error(`${prog} ${parameters.join(' ')} failed with status ${child.status}`)
11+
const error = (message) => [
12+
`${prettyPrintCommand(prog, parameters)}: ${message}`,
13+
`stdout: ${child.stdout}`,
14+
].join('\n')
15+
if (child.error) throw new Error(error(`failed with ${child.error}`), { cause: child.error })
16+
if (child.status !== 0) throw new Error(error(`failed with status ${child.status}`))
917
return child.stdout.toString('utf-8').replace(/\r?\n$/, '')
1018
}
1119

0 commit comments

Comments
 (0)