Distinguish expected absence from git errors in remote removal

Why: swallowing all errors silently masks genuine git failures.
Check presence explicitly instead, so setup/teardown can still
skip when origin is absent while letting real errors surface.
This commit is contained in:
Jinjing
2026-07-30 21:45:16 -07:00
parent b757bf4473
commit 60a810d899
@@ -26,11 +26,18 @@ async function writeEvidence(
}
function removeOriginRemoteIfPresent(cwd: string): void {
try {
execFileSync('git', ['remote', 'remove', 'origin'], { cwd, stdio: 'pipe' })
} catch {
// Why: setup and teardown must not fail just because origin is absent.
// Why: check presence instead of swallowing errors, so real Git failures still surface.
const remotes = execFileSync('git', ['remote'], {
cwd,
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe']
})
.split('\n')
.map((line) => line.trim())
if (!remotes.includes('origin')) {
return
}
execFileSync('git', ['remote', 'remove', 'origin'], { cwd, stdio: 'pipe' })
}
test.describe('Source Control Create PR intent worktree switching', () => {