Skip to content

Commit 562cea7

Browse files
Erik ElmekeLUCI
Erik Elmeke
authored and
LUCI
committed
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 <[email protected]> Tested-by: Erik Elmeke <[email protected]> Commit-Queue: Erik Elmeke <[email protected]>
1 parent eede374 commit 562cea7

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

project.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,34 @@ def CurrentBranch(self):
727727
return None
728728

729729
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".
730733
return (
731734
os.path.exists(self.work_git.GetDotgitPath("rebase-apply"))
732735
or os.path.exists(self.work_git.GetDotgitPath("rebase-merge"))
733736
or os.path.exists(os.path.join(self.worktree, ".dotest"))
734737
)
735738

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+
736758
def IsDirty(self, consider_untracked=True):
737759
"""Is the working directory modified in some way?"""
738760
self.work_git.update_index(
@@ -1583,7 +1605,15 @@ def _dosubmodules():
15831605
if branch is None or syncbuf.detach_head:
15841606
# Currently on a detached HEAD. The user is assumed to
15851607
# 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:
15871617
fail(_PriorSyncFailedError(project=self.name))
15881618
return
15891619

0 commit comments

Comments
 (0)