Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 38ad9c8

Browse files
committedJan 6, 2025··
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 b1a15a9 commit 38ad9c8

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed
 

‎lib/prepare_release.js

+38-12
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ export default class ReleasePreparation extends Session {
9393
} = this;
9494

9595
// Create new proposal branch.
96-
cli.startSpinner(`Creating new proposal branch for ${newVersion}`);
97-
const proposalBranch = await this.createProposalBranch(releaseBranch);
98-
cli.stopSpinner(`Created new proposal branch for ${newVersion}`);
96+
cli.startSpinner(`Switching to proposal branch for ${newVersion}`);
97+
const { proposalBranch, resultMsg } =
98+
await this.createProposalBranch(releaseBranch);
99+
cli.stopSpinner(resultMsg);
99100

100101
const success = await this.cherryPickSecurityPRs(filterLabels);
101102
if (!success) {
@@ -201,9 +202,10 @@ export default class ReleasePreparation extends Session {
201202
}
202203

203204
// Create new proposal branch.
204-
cli.startSpinner(`Creating new proposal branch for ${newVersion}`);
205-
await this.createProposalBranch();
206-
cli.stopSpinner(`Created new proposal branch for ${newVersion}`);
205+
cli.startSpinner(`Switching to proposal branch for ${newVersion}`);
206+
const { resultMsg } =
207+
await this.createProposalBranch();
208+
cli.stopSpinner(resultMsg);
207209

208210
if (this.isLTSTransition) {
209211
// For releases transitioning into LTS, fetch the new code name.
@@ -533,13 +535,37 @@ export default class ReleasePreparation extends Session {
533535
const { newVersion } = this;
534536
const proposalBranch = `v${newVersion}-proposal`;
535537

536-
await runAsync('git', [
537-
'checkout',
538-
'-b',
538+
try {
539+
await forceRunAsync('git', [
540+
'checkout',
541+
'-b',
542+
proposalBranch,
543+
base
544+
], { captureStdout: true, captureStderr: true, ignoreFailure: false });
545+
} catch (err) {
546+
const branchExistsRE = /fatal: a branch named '.*' already exists/i;
547+
if (branchExistsRE.test(err.stderr)) {
548+
await runAsync('git', [
549+
'checkout',
550+
proposalBranch
551+
]);
552+
await runAsync('git', [
553+
'reset',
554+
'--hard',
555+
base
556+
]);
557+
return {
558+
proposalBranch,
559+
resultMsg: `Updated proposal branch for ${newVersion}`
560+
};
561+
} else {
562+
throw err;
563+
}
564+
}
565+
return {
539566
proposalBranch,
540-
base
541-
]);
542-
return proposalBranch;
567+
resultMsg: `Created new proposal branch for ${newVersion}`
568+
};
543569
}
544570

545571
async updateNodeVersion() {

0 commit comments

Comments
 (0)
Please sign in to comment.