summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2023-08-22 01:24:46 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-08-22 17:18:13 +0000
commit16109a66b705211efd25f434201d113628aff04c (patch)
treefede640aae0b6a485cf71c2b9fd315a53673b613
parent321b7934b5e8e316b7fa4dc306e055d3d6d351ff (diff)
downloadgit-repo-16109a66b705211efd25f434201d113628aff04c.tar.gz
upload: Suggest full sync if hooks fail with partially synced tree
Pre-upload hooks may fail because of partial syncs. Bug: b/271507654 Change-Id: I124cd386c5af2c34e1dcaa3e86916624e235b1e3 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/383474 Reviewed-by: Mike Frysinger <vapier@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com> Tested-by: Gavin Mak <gavinmak@google.com>
-rw-r--r--subcmds/sync.py4
-rw-r--r--subcmds/upload.py7
-rw-r--r--tests/test_subcmds_sync.py4
3 files changed, 11 insertions, 4 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index bbe03722..159771eb 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -1696,7 +1696,7 @@ later is required to fix a server side protocol bug.
1696 ) 1696 )
1697 1697
1698 self._fetch_times = _FetchTimes(manifest) 1698 self._fetch_times = _FetchTimes(manifest)
1699 self._local_sync_state = _LocalSyncState(manifest) 1699 self._local_sync_state = LocalSyncState(manifest)
1700 if not opt.local_only: 1700 if not opt.local_only:
1701 with multiprocessing.Manager() as manager: 1701 with multiprocessing.Manager() as manager:
1702 with ssh.ProxyManager(manager) as ssh_proxy: 1702 with ssh.ProxyManager(manager) as ssh_proxy:
@@ -1932,7 +1932,7 @@ class _FetchTimes(object):
1932 platform_utils.remove(self._path, missing_ok=True) 1932 platform_utils.remove(self._path, missing_ok=True)
1933 1933
1934 1934
1935class _LocalSyncState(object): 1935class LocalSyncState(object):
1936 _LAST_FETCH = "last_fetch" 1936 _LAST_FETCH = "last_fetch"
1937 _LAST_CHECKOUT = "last_checkout" 1937 _LAST_CHECKOUT = "last_checkout"
1938 1938
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 040eaeb5..b89525ce 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -26,6 +26,7 @@ from git_command import GitCommand
26from git_refs import R_HEADS 26from git_refs import R_HEADS
27from hooks import RepoHook 27from hooks import RepoHook
28from project import ReviewableBranch 28from project import ReviewableBranch
29from subcmds.sync import LocalSyncState
29 30
30 31
31_DEFAULT_UNUSUAL_COMMIT_THRESHOLD = 5 32_DEFAULT_UNUSUAL_COMMIT_THRESHOLD = 5
@@ -804,6 +805,12 @@ Gerrit Code Review: https://www.gerritcodereview.com/
804 if not hook.Run( 805 if not hook.Run(
805 project_list=pending_proj_names, worktree_list=pending_worktrees 806 project_list=pending_proj_names, worktree_list=pending_worktrees
806 ): 807 ):
808 if LocalSyncState(manifest).IsPartiallySynced():
809 print(
810 "Partially synced tree detected. Syncing all projects "
811 "may resolve issues you're seeing.",
812 file=sys.stderr,
813 )
807 ret = 1 814 ret = 1
808 if ret: 815 if ret:
809 return ret 816 return ret
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py
index b43fe18e..71b0f8e0 100644
--- a/tests/test_subcmds_sync.py
+++ b/tests/test_subcmds_sync.py
@@ -110,7 +110,7 @@ def test_cli_jobs(argv, jobs_manifest, jobs, jobs_net, jobs_check):
110 110
111 111
112class LocalSyncState(unittest.TestCase): 112class LocalSyncState(unittest.TestCase):
113 """Tests for _LocalSyncState.""" 113 """Tests for LocalSyncState."""
114 114
115 _TIME = 10 115 _TIME = 10
116 116
@@ -129,7 +129,7 @@ class LocalSyncState(unittest.TestCase):
129 129
130 def _new_state(self, time=_TIME): 130 def _new_state(self, time=_TIME):
131 with mock.patch("time.time", return_value=time): 131 with mock.patch("time.time", return_value=time):
132 return sync._LocalSyncState(self.manifest) 132 return sync.LocalSyncState(self.manifest)
133 133
134 def test_set(self): 134 def test_set(self):
135 """Times are set.""" 135 """Times are set."""