diff options
author | Gavin Mak <gavinmak@google.com> | 2023-08-08 04:43:36 +0000 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-08-10 18:13:14 +0000 |
commit | f0aeb220def22edfac9838288ad251f86da782c1 (patch) | |
tree | 7ef6ac75fc6bf83abf5a060a69bd6bed9b716685 /tests/test_subcmds_sync.py | |
parent | f1ddaaa553521c5c659271dd52c8d33866a51936 (diff) | |
download | git-repo-f0aeb220def22edfac9838288ad251f86da782c1.tar.gz |
sync: Warn if partial sync state is detected
Partial syncs are not supported and can lead to strange behavior like
deleting files. Explicitly warn users on partial sync.
Bug: b/286126621, b/271507654
Change-Id: I471f78ac5942eb855bc34c80af47aa561dfa61e8
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/382154
Reviewed-by: Jason Chang <jasonnc@google.com>
Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Diffstat (limited to 'tests/test_subcmds_sync.py')
-rw-r--r-- | tests/test_subcmds_sync.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index 00c34852..7cc93e39 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py | |||
@@ -175,12 +175,73 @@ class LocalSyncState(unittest.TestCase): | |||
175 | os.listdir(self.repodir), [".repo_localsyncstate.json"] | 175 | os.listdir(self.repodir), [".repo_localsyncstate.json"] |
176 | ) | 176 | ) |
177 | 177 | ||
178 | def test_partial_sync(self): | ||
179 | """Partial sync state is detected.""" | ||
180 | with open(self.state._path, "w") as f: | ||
181 | f.write( | ||
182 | """ | ||
183 | { | ||
184 | "projA": { | ||
185 | "last_fetch": 5, | ||
186 | "last_checkout": 5 | ||
187 | }, | ||
188 | "projB": { | ||
189 | "last_fetch": 5, | ||
190 | "last_checkout": 5 | ||
191 | } | ||
192 | } | ||
193 | """ | ||
194 | ) | ||
195 | |||
196 | # Initialize state to read from the new file. | ||
197 | self.state = self._new_state() | ||
198 | projB = mock.MagicMock(relpath="projB") | ||
199 | self.assertEqual(self.state.IsPartiallySynced(), False) | ||
200 | |||
201 | self.state.SetFetchTime(projB) | ||
202 | self.state.SetCheckoutTime(projB) | ||
203 | self.assertEqual(self.state.IsPartiallySynced(), True) | ||
204 | |||
178 | def test_nonexistent_project(self): | 205 | def test_nonexistent_project(self): |
179 | """Unsaved projects don't have data.""" | 206 | """Unsaved projects don't have data.""" |
180 | p = mock.MagicMock(relpath="projC") | 207 | p = mock.MagicMock(relpath="projC") |
181 | self.assertEqual(self.state.GetFetchTime(p), None) | 208 | self.assertEqual(self.state.GetFetchTime(p), None) |
182 | self.assertEqual(self.state.GetCheckoutTime(p), None) | 209 | self.assertEqual(self.state.GetCheckoutTime(p), None) |
183 | 210 | ||
211 | def test_prune_removed_projects(self): | ||
212 | """Removed projects are pruned.""" | ||
213 | with open(self.state._path, "w") as f: | ||
214 | f.write( | ||
215 | """ | ||
216 | { | ||
217 | "projA": { | ||
218 | "last_fetch": 5 | ||
219 | }, | ||
220 | "projB": { | ||
221 | "last_fetch": 7 | ||
222 | } | ||
223 | } | ||
224 | """ | ||
225 | ) | ||
226 | |||
227 | def mock_exists(path): | ||
228 | if "projA" in path: | ||
229 | return False | ||
230 | return True | ||
231 | |||
232 | projA = mock.MagicMock(relpath="projA") | ||
233 | projB = mock.MagicMock(relpath="projB") | ||
234 | self.state = self._new_state() | ||
235 | self.assertEqual(self.state.GetFetchTime(projA), 5) | ||
236 | self.assertEqual(self.state.GetFetchTime(projB), 7) | ||
237 | with mock.patch("os.path.exists", side_effect=mock_exists): | ||
238 | self.state.PruneRemovedProjects() | ||
239 | self.assertIsNone(self.state.GetFetchTime(projA)) | ||
240 | |||
241 | self.state = self._new_state() | ||
242 | self.assertIsNone(self.state.GetFetchTime(projA)) | ||
243 | self.assertEqual(self.state.GetFetchTime(projB), 7) | ||
244 | |||
184 | 245 | ||
185 | class GetPreciousObjectsState(unittest.TestCase): | 246 | class GetPreciousObjectsState(unittest.TestCase): |
186 | """Tests for _GetPreciousObjectsState.""" | 247 | """Tests for _GetPreciousObjectsState.""" |