@@ -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 = / f a t a l : a b r a n c h n a m e d ' .* ' a l r e a d y e x i s t s / 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