@@ -79,6 +79,10 @@ func main() {
79
79
Name : "no-xdg-open" ,
80
80
Usage : "Set this flag to not use xdg-open to open the PR URL" ,
81
81
},
82
+ cli.BoolFlag {
83
+ Name : "continue" ,
84
+ Usage : "Set this flag to continue from a git cherry-pick that has broken" ,
85
+ },
82
86
}
83
87
cli .AppHelpTemplate = `NAME:
84
88
{{.Name}} - {{.Usage}}
@@ -104,7 +108,19 @@ func runBackport(c *cli.Context) error {
104
108
ctx , cancel := installSignals ()
105
109
defer cancel ()
106
110
111
+ continuing := c .Bool ("continue" )
112
+
113
+ var pr string
114
+
107
115
version := c .String ("version" )
116
+ if version == "" && continuing {
117
+ // determine version from current branch name
118
+ var err error
119
+ pr , version , err = readCurrentBranch (ctx )
120
+ if err != nil {
121
+ return err
122
+ }
123
+ }
108
124
if version == "" {
109
125
version = readVersion ()
110
126
}
@@ -135,13 +151,14 @@ func runBackport(c *cli.Context) error {
135
151
localReleaseBranch := path .Join (upstream , upstreamReleaseBranch )
136
152
137
153
args := c .Args ()
138
- if len (args ) == 0 {
154
+ if len (args ) == 0 && pr == "" {
139
155
return fmt .Errorf ("no PR number provided\n Provide a PR number to backport" )
140
- } else if len (args ) != 1 {
156
+ } else if len (args ) != 1 && pr == "" {
141
157
return fmt .Errorf ("multiple PRs provided %v\n Only a single PR can be backported at a time" , args )
142
158
}
143
-
144
- pr := args [0 ]
159
+ if pr == "" {
160
+ pr = args [0 ]
161
+ }
145
162
146
163
backportBranch := c .String ("backport-branch" )
147
164
if backportBranch == "" {
@@ -168,8 +185,10 @@ func runBackport(c *cli.Context) error {
168
185
}
169
186
}
170
187
171
- if err := checkoutBackportBranch (ctx , backportBranch , localReleaseBranch ); err != nil {
172
- return err
188
+ if ! continuing {
189
+ if err := checkoutBackportBranch (ctx , backportBranch , localReleaseBranch ); err != nil {
190
+ return err
191
+ }
173
192
}
174
193
175
194
if err := cherrypick (ctx , sha ); err != nil {
@@ -353,6 +372,22 @@ func determineRemote(ctx context.Context, forkUser string) (string, string, erro
353
372
return "" , "" , fmt .Errorf ("unable to find appropriate remote in:\n %s" , string (out ))
354
373
}
355
374
375
+ func readCurrentBranch (ctx context.Context ) (pr , version string , err error ) {
376
+ out , err := exec .CommandContext (ctx , "git" , "branch" , "--show-current" ).Output ()
377
+ if err != nil {
378
+ fmt .Fprintf (os .Stderr , "Unable to read current git branch:\n %s\n " , string (out ))
379
+ return "" , "" , fmt .Errorf ("unable to read current git branch: %w" , err )
380
+ }
381
+ parts := strings .Split (strings .TrimSpace (string (out )), "-" )
382
+
383
+ if len (parts ) != 3 || parts [0 ] != "backport" {
384
+ fmt .Fprintf (os .Stderr , "Unable to continue from git branch:\n %s\n " , string (out ))
385
+ return "" , "" , fmt .Errorf ("unable to continue from git branch:\n %s" , string (out ))
386
+ }
387
+
388
+ return parts [1 ], parts [2 ], nil
389
+ }
390
+
356
391
func readVersion () string {
357
392
bs , err := os .ReadFile ("docs/config.yaml" )
358
393
if err != nil {
0 commit comments