@@ -13,7 +13,7 @@ export class BaseReleaseTask {
13
13
constructor ( public git : GitClient ) { }
14
14
15
15
/** Checks if the user is on an allowed publish branch for the specified version. */
16
- protected switchToPublishBranch ( newVersion : Version ) : string {
16
+ protected async assertValidPublishBranch ( newVersion : Version ) : Promise < string > {
17
17
const allowedBranches = getAllowedPublishBranches ( newVersion ) ;
18
18
const currentBranchName = this . git . getCurrentBranch ( ) ;
19
19
@@ -24,30 +24,24 @@ export class BaseReleaseTask {
24
24
return currentBranchName ;
25
25
}
26
26
27
- // In case there are multiple allowed publish branches for this version, we just
28
- // exit and let the user decide which branch they want to release from.
29
- if ( allowedBranches . length !== 1 ) {
30
- console . warn ( chalk . yellow ( ' ✘ You are not on an allowed publish branch.' ) ) ;
31
- console . warn ( chalk . yellow ( ` Please switch to one of the following branches: ` +
32
- `${ allowedBranches . join ( ', ' ) } ` ) ) ;
33
- process . exit ( 0 ) ;
34
- }
35
-
36
- // For this version there is only *one* allowed publish branch, so we could
37
- // automatically switch to that branch in case the user isn't on it yet.
38
- const defaultPublishBranch = allowedBranches [ 0 ] ;
27
+ console . error ( chalk . red ( ' ✘ You are not on an allowed publish branch.' ) ) ;
28
+ console . info ( chalk . yellow (
29
+ ` Allowed branches are: ${ chalk . bold ( allowedBranches . join ( ', ' ) ) } ` ) ) ;
30
+ console . info ( ) ;
39
31
40
- if ( ! this . git . checkoutBranch ( defaultPublishBranch ) ) {
41
- console . error ( chalk . red (
42
- ` ✘ Could not switch to the "${ chalk . italic ( defaultPublishBranch ) } " branch.` ) ) ;
43
- console . error ( chalk . red (
44
- ` Please ensure that the branch exists or manually switch to the branch.` ) ) ;
45
- process . exit ( 1 ) ;
32
+ // Prompt the user if they wants to forcibly use the current branch. We support this
33
+ // because in some cases, releases do not use the common publish branches. e.g. a major
34
+ // release is delayed, and new features for the next minor version are collected.
35
+ if ( await this . promptConfirm (
36
+ `Do you want to forcibly use the current branch? (${ chalk . italic ( currentBranchName ) } )` ) ) {
37
+ console . log ( ) ;
38
+ console . log ( chalk . green ( ` ✓ Using the "${ chalk . italic ( currentBranchName ) } " branch.` ) ) ;
39
+ return currentBranchName ;
46
40
}
47
41
48
- console . log ( chalk . green (
49
- ` ✓ Switched to the " ${ chalk . italic ( defaultPublishBranch ) } " branch.` ) ) ;
50
- return defaultPublishBranch ;
42
+ console . warn ( ) ;
43
+ console . warn ( chalk . yellow ( ' Please switch to one of the allowed publish branches.' ) ) ;
44
+ process . exit ( 0 ) ;
51
45
}
52
46
53
47
/** Verifies that the local branch is up to date with the given publish branch. */
@@ -73,11 +67,12 @@ export class BaseReleaseTask {
73
67
}
74
68
75
69
/** Prompts the user with a confirmation question and a specified message. */
76
- protected async promptConfirm ( message : string ) : Promise < boolean > {
70
+ protected async promptConfirm ( message : string , defaultValue = false ) : Promise < boolean > {
77
71
return ( await prompt < { result : boolean } > ( {
78
72
type : 'confirm' ,
79
73
name : 'result' ,
80
74
message : message ,
75
+ default : defaultValue ,
81
76
} ) ) . result ;
82
77
}
83
78
}
0 commit comments