summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--project.py7
-rw-r--r--subcmds/sync.py29
2 files changed, 31 insertions, 5 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:
diff --git a/subcmds/sync.py b/subcmds/sync.py
index c6682a5b..7acb6e5b 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -278,6 +278,11 @@ directories if they have previously been linked to a different
278object directory. WARNING: This may cause data to be lost since 278object directory. WARNING: This may cause data to be lost since
279refs may be removed when overwriting. 279refs may be removed when overwriting.
280 280
281The --force-checkout option can be used to force git to switch revs even if the
282index or the working tree differs from HEAD, and if there are untracked files.
283WARNING: This may cause data to be lost since uncommitted changes may be
284removed.
285
281The --force-remove-dirty option can be used to remove previously used 286The --force-remove-dirty option can be used to remove previously used
282projects with uncommitted changes. WARNING: This may cause data to be 287projects with uncommitted changes. WARNING: This may cause data to be
283lost since uncommitted changes may be removed with projects that no longer 288lost since uncommitted changes may be removed with projects that no longer
@@ -376,6 +381,14 @@ later is required to fix a server side protocol bug.
376 "may cause loss of data", 381 "may cause loss of data",
377 ) 382 )
378 p.add_option( 383 p.add_option(
384 "--force-checkout",
385 dest="force_checkout",
386 action="store_true",
387 help="force checkout even if it results in throwing away "
388 "uncommitted modifications. "
389 "WARNING: this may cause loss of data",
390 )
391 p.add_option(
379 "--force-remove-dirty", 392 "--force-remove-dirty",
380 dest="force_remove_dirty", 393 dest="force_remove_dirty",
381 action="store_true", 394 action="store_true",
@@ -991,12 +1004,17 @@ later is required to fix a server side protocol bug.
991 1004
992 return _FetchMainResult(all_projects) 1005 return _FetchMainResult(all_projects)
993 1006
994 def _CheckoutOne(self, detach_head, force_sync, verbose, project): 1007 def _CheckoutOne(
1008 self, detach_head, force_sync, force_checkout, verbose, project
1009 ):
995 """Checkout work tree for one project 1010 """Checkout work tree for one project
996 1011
997 Args: 1012 Args:
998 detach_head: Whether to leave a detached HEAD. 1013 detach_head: Whether to leave a detached HEAD.
999 force_sync: Force checking out of the repo. 1014 force_sync: Force checking out of .git directory (e.g. overwrite
1015 existing git directory that was previously linked to a different
1016 object directory).
1017 force_checkout: Force checking out of the repo content.
1000 verbose: Whether to show verbose messages. 1018 verbose: Whether to show verbose messages.
1001 project: Project object for the project to checkout. 1019 project: Project object for the project to checkout.
1002 1020
@@ -1011,7 +1029,11 @@ later is required to fix a server side protocol bug.
1011 errors = [] 1029 errors = []
1012 try: 1030 try:
1013 project.Sync_LocalHalf( 1031 project.Sync_LocalHalf(
1014 syncbuf, force_sync=force_sync, errors=errors, verbose=verbose 1032 syncbuf,
1033 force_sync=force_sync,
1034 force_checkout=force_checkout,
1035 errors=errors,
1036 verbose=verbose,
1015 ) 1037 )
1016 success = syncbuf.Finish() 1038 success = syncbuf.Finish()
1017 except GitError as e: 1039 except GitError as e:
@@ -1082,6 +1104,7 @@ later is required to fix a server side protocol bug.
1082 self._CheckoutOne, 1104 self._CheckoutOne,
1083 opt.detach_head, 1105 opt.detach_head,
1084 opt.force_sync, 1106 opt.force_sync,
1107 opt.force_checkout,
1085 opt.verbose, 1108 opt.verbose,
1086 ), 1109 ),
1087 projects, 1110 projects,