summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Elmeke <erik@haleytek.corp-partner.google.com>2024-04-29 11:26:53 +0200
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-05-23 14:14:18 +0000
commit562cea77580d5f217be73f21757c7d5b32d2d11f (patch)
treea453a5077bbd7372f45ecff96642232d18c09998
parenteede374e3ec446d5f03c12a886efcb2d8f946917 (diff)
downloadgit-repo-562cea77580d5f217be73f21757c7d5b32d2d11f.tar.gz
sync: Abort rebase in progress if force-checkout is set
This will make "repo sync -d --force-checkout" more reliable in CI automation, as there are fewer things in the way that may need manual intervention. Bug: b/40015382 Change-Id: I8a79971724a3d9a8e2d682b7a0c04deda9e34177 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/423317 Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Erik Elmeke <erik@haleytek.corp-partner.google.com> Commit-Queue: Erik Elmeke <erik@haleytek.corp-partner.google.com>
-rw-r--r--project.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/project.py b/project.py
index 07685dae..80a6c395 100644
--- a/project.py
+++ b/project.py
@@ -727,12 +727,34 @@ class Project:
727 return None 727 return None
728 728
729 def IsRebaseInProgress(self): 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 return ( 733 return (
731 os.path.exists(self.work_git.GetDotgitPath("rebase-apply")) 734 os.path.exists(self.work_git.GetDotgitPath("rebase-apply"))
732 or os.path.exists(self.work_git.GetDotgitPath("rebase-merge")) 735 or os.path.exists(self.work_git.GetDotgitPath("rebase-merge"))
733 or os.path.exists(os.path.join(self.worktree, ".dotest")) 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 def IsDirty(self, consider_untracked=True): 758 def IsDirty(self, consider_untracked=True):
737 """Is the working directory modified in some way?""" 759 """Is the working directory modified in some way?"""
738 self.work_git.update_index( 760 self.work_git.update_index(
@@ -1583,7 +1605,15 @@ class Project:
1583 if branch is None or syncbuf.detach_head: 1605 if branch is None or syncbuf.detach_head:
1584 # Currently on a detached HEAD. The user is assumed to 1606 # Currently on a detached HEAD. The user is assumed to
1585 # not have any local modifications worth worrying about. 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 fail(_PriorSyncFailedError(project=self.name)) 1617 fail(_PriorSyncFailedError(project=self.name))
1588 return 1618 return
1589 1619