File tree Expand file tree Collapse file tree 3 files changed +36
-5
lines changed
Expand file tree Collapse file tree 3 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ mod rev_list;
1414mod switch;
1515
1616pub use branch:: { branch, StartingPoint } ;
17- pub use cherry_pick:: cherry_pick;
17+ pub use cherry_pick:: { cherry_pick, cherry_pick_abort } ;
1818pub use commit:: commit;
1919pub use fetch:: fetch;
2020pub use log:: log;
Original file line number Diff line number Diff line change @@ -18,3 +18,16 @@ impl GitCmd for CherryPick {
1818 cmd. arg ( "cherry-pick" ) . arg ( self . commit ) ;
1919 }
2020}
21+
22+ #[ derive( Default ) ]
23+ pub struct CherryPickAbort ;
24+
25+ pub fn cherry_pick_abort ( ) -> CherryPickAbort {
26+ CherryPickAbort
27+ }
28+
29+ impl GitCmd for CherryPickAbort {
30+ fn setup ( self , cmd : & mut Command ) {
31+ cmd. arg ( "cherry-pick" ) . arg ( "--abort" ) ;
32+ }
33+ }
Original file line number Diff line number Diff line change @@ -224,12 +224,30 @@ pub async fn prepare_commits(
224224
225225 info ! ( "created branch `{new_branch}`" ) ;
226226
227- rev_list. lines ( ) . try_for_each ( |commit| {
227+ // cherry-pick until we hit a commit we can't apply
228+ // if we hit such a commit, only error if we haven't applied any commits
229+ let mut had_successful_cherry_pick = false ;
230+ for commit in rev_list. lines ( ) {
228231 info ! ( "cherry-picking {commit}..." ) ;
229- git:: cherry_pick ( git:: Commit ( commit) ) . spawn ( ) ?;
230232
231- maybe_prefix_cherry_picked_commit ( )
232- } ) ?;
233+ match git:: cherry_pick ( git:: Commit ( commit) ) . spawn ( ) {
234+ Err ( e_cherry) => {
235+ if !had_successful_cherry_pick {
236+ info ! ( "failed on first commit" ) ;
237+ return Err ( Error :: Git ( e_cherry) )
238+ } else if let Err ( e_abort) = git:: cherry_pick_abort ( ) . spawn ( ) {
239+ info ! ( "failed to abort cherry-pick" ) ;
240+ return Err ( Error :: Git ( e_abort) )
241+ } else {
242+ info ! ( "failed, stopping early" ) ;
243+ break
244+ }
245+ }
246+ _ => had_successful_cherry_pick = true
247+ }
248+
249+ maybe_prefix_cherry_picked_commit ( ) ?;
250+ }
233251
234252 info ! ( "pushing branch..." ) ;
235253 git:: push ( )
You can’t perform that action at this time.
0 commit comments