sync: introduce --force-checkout

In some cases (e.g. in a CI system), it's desirable to be able to
instruct repo to force checkout. This flag passes --force flag to `git
checkout` operations.

Bug: b/327624021
Change-Id: I579edda546fb8147c4e1a267e2605fcf6e597421
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/411518
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: George Engelbrecht <engeg@google.com>
Tested-by: Josip Sokcevic <sokcevic@google.com>
This commit is contained in:
Josip Sokcevic
2024-02-29 09:48:37 -08:00
committed by LUCI
parent 96edb9b573
commit edadb25c02
2 changed files with 31 additions and 5 deletions

View File

@ -1515,6 +1515,7 @@ class Project:
self,
syncbuf,
force_sync=False,
force_checkout=False,
submodules=False,
errors=None,
verbose=False,
@ -1602,7 +1603,7 @@ class Project:
syncbuf.info(self, "discarding %d commits", len(lost))
try:
self._Checkout(revid, quiet=True)
self._Checkout(revid, force_checkout=force_checkout, quiet=True)
if submodules:
self._SyncSubmodules(quiet=True)
except GitError as e:
@ -2857,10 +2858,12 @@ class Project:
except OSError:
return False
def _Checkout(self, rev, quiet=False):
def _Checkout(self, rev, force_checkout=False, quiet=False):
cmd = ["checkout"]
if quiet:
cmd.append("-q")
if force_checkout:
cmd.append("-f")
cmd.append(rev)
cmd.append("--")
if GitCommand(self, cmd).Wait() != 0: