@@ -727,12 +727,34 @@ def CurrentBranch(self):
727
727
return None
728
728
729
729
def IsRebaseInProgress (self ):
730
+ """Returns true if a rebase or "am" is in progress"""
731
+ # "rebase-apply" is used for "git rebase".
732
+ # "rebase-merge" is used for "git am".
730
733
return (
731
734
os .path .exists (self .work_git .GetDotgitPath ("rebase-apply" ))
732
735
or os .path .exists (self .work_git .GetDotgitPath ("rebase-merge" ))
733
736
or os .path .exists (os .path .join (self .worktree , ".dotest" ))
734
737
)
735
738
739
+ def IsCherryPickInProgress (self ):
740
+ """Returns True if a cherry-pick is in progress."""
741
+ return os .path .exists (self .work_git .GetDotgitPath ("CHERRY_PICK_HEAD" ))
742
+
743
+ def _AbortRebase (self ):
744
+ """Abort ongoing rebase, cherry-pick or patch apply (am).
745
+
746
+ If no rebase, cherry-pick or patch apply was in progress, this method
747
+ ignores the status and continues.
748
+ """
749
+
750
+ def _git (* args ):
751
+ # Ignore return code, in case there was no rebase in progress.
752
+ GitCommand (self , * args , log_as_error = False ).Wait ()
753
+
754
+ _git ("cherry-pick" , "--abort" )
755
+ _git ("rebase" , "--abort" )
756
+ _git ("am" , "--abort" )
757
+
736
758
def IsDirty (self , consider_untracked = True ):
737
759
"""Is the working directory modified in some way?"""
738
760
self .work_git .update_index (
@@ -1583,7 +1605,15 @@ def _dosubmodules():
1583
1605
if branch is None or syncbuf .detach_head :
1584
1606
# Currently on a detached HEAD. The user is assumed to
1585
1607
# not have any local modifications worth worrying about.
1586
- if self .IsRebaseInProgress ():
1608
+ rebase_in_progress = (
1609
+ self .IsRebaseInProgress () or self .IsCherryPickInProgress ()
1610
+ )
1611
+ if rebase_in_progress and force_checkout :
1612
+ self ._AbortRebase ()
1613
+ rebase_in_progress = (
1614
+ self .IsRebaseInProgress () or self .IsCherryPickInProgress ()
1615
+ )
1616
+ if rebase_in_progress :
1587
1617
fail (_PriorSyncFailedError (project = self .name ))
1588
1618
return
1589
1619
0 commit comments