Skip to content

Commit e40d5b7

Browse files
committed
fix(git-node): prepare_release resilient checkout
In `git node release --prepare` when checking out a new proposal branch make sure it's also possible to update an already existing branch of that same name instead of failing and terminating the automation.
1 parent 3afe24f commit e40d5b7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lib/prepare_release.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,24 @@ export default class ReleasePreparation extends Session {
523523
const { newVersion } = this;
524524
const proposalBranch = `v${newVersion}-proposal`;
525525

526-
await runAsync('git', [
527-
'checkout',
528-
'-b',
529-
proposalBranch,
530-
base
531-
]);
526+
try {
527+
await forceRunAsync('git', [
528+
'checkout',
529+
'-b',
530+
proposalBranch,
531+
base
532+
], { captureStdout: true, captureStderr: true, ignoreFailures: false });
533+
} catch (err) {
534+
const branchExistsRE = /fatal: a branch named '.*' already exists/i;
535+
if (branchExistsRE.test(err.stderr)) {
536+
await runAsync('git', [
537+
'checkout',
538+
proposalBranch
539+
]);
540+
} else {
541+
throw err;
542+
}
543+
}
532544
return proposalBranch;
533545
}
534546

0 commit comments

Comments
 (0)