From edadb25c0270398e9afa3eb0093d6b94aa51c3f4 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Thu, 29 Feb 2024 09:48:37 -0800 Subject: 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 Reviewed-by: Gavin Mak Reviewed-by: George Engelbrecht Tested-by: Josip Sokcevic --- project.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'project.py') diff --git a/project.py b/project.py index 40ca116d..2ba2b766 100644 --- a/project.py +++ b/project.py @@ -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: -- cgit v1.2.3-54-g00ecf