summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorJosip Sokcevic <sokcevic@google.com>2024-02-29 09:48:37 -0800
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-03-07 17:21:51 +0000
commitedadb25c0270398e9afa3eb0093d6b94aa51c3f4 (patch)
tree93632765156d4aa4b5c64cbab38af8d4d3ac3736 /project.py
parent96edb9b573d6c58b1990090c467ce0c2809bc0b1 (diff)
downloadgit-repo-edadb25c0270398e9afa3eb0093d6b94aa51c3f4.tar.gz
sync: introduce --force-checkoutv2.43
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>
Diffstat (limited to 'project.py')
-rw-r--r--project.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/project.py b/project.py
index 40ca116d..2ba2b766 100644
--- a/project.py
+++ b/project.py
@@ -1515,6 +1515,7 @@ class Project:
1515 self, 1515 self,
1516 syncbuf, 1516 syncbuf,
1517 force_sync=False, 1517 force_sync=False,
1518 force_checkout=False,
1518 submodules=False, 1519 submodules=False,
1519 errors=None, 1520 errors=None,
1520 verbose=False, 1521 verbose=False,
@@ -1602,7 +1603,7 @@ class Project:
1602 syncbuf.info(self, "discarding %d commits", len(lost)) 1603 syncbuf.info(self, "discarding %d commits", len(lost))
1603 1604
1604 try: 1605 try:
1605 self._Checkout(revid, quiet=True) 1606 self._Checkout(revid, force_checkout=force_checkout, quiet=True)
1606 if submodules: 1607 if submodules:
1607 self._SyncSubmodules(quiet=True) 1608 self._SyncSubmodules(quiet=True)
1608 except GitError as e: 1609 except GitError as e:
@@ -2857,10 +2858,12 @@ class Project:
2857 except OSError: 2858 except OSError:
2858 return False 2859 return False
2859 2860
2860 def _Checkout(self, rev, quiet=False): 2861 def _Checkout(self, rev, force_checkout=False, quiet=False):
2861 cmd = ["checkout"] 2862 cmd = ["checkout"]
2862 if quiet: 2863 if quiet:
2863 cmd.append("-q") 2864 cmd.append("-q")
2865 if force_checkout:
2866 cmd.append("-f")
2864 cmd.append(rev) 2867 cmd.append(rev)
2865 cmd.append("--") 2868 cmd.append("--")
2866 if GitCommand(self, cmd).Wait() != 0: 2869 if GitCommand(self, cmd).Wait() != 0: