mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-26 20:17:52 +00:00
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>
This commit is contained in:
@ -175,12 +175,73 @@ class LocalSyncState(unittest.TestCase):
|
||||
os.listdir(self.repodir), [".repo_localsyncstate.json"]
|
||||
)
|
||||
|
||||
def test_partial_sync(self):
|
||||
"""Partial sync state is detected."""
|
||||
with open(self.state._path, "w") as f:
|
||||
f.write(
|
||||
"""
|
||||
{
|
||||
"projA": {
|
||||
"last_fetch": 5,
|
||||
"last_checkout": 5
|
||||
},
|
||||
"projB": {
|
||||
"last_fetch": 5,
|
||||
"last_checkout": 5
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
# Initialize state to read from the new file.
|
||||
self.state = self._new_state()
|
||||
projB = mock.MagicMock(relpath="projB")
|
||||
self.assertEqual(self.state.IsPartiallySynced(), False)
|
||||
|
||||
self.state.SetFetchTime(projB)
|
||||
self.state.SetCheckoutTime(projB)
|
||||
self.assertEqual(self.state.IsPartiallySynced(), True)
|
||||
|
||||
def test_nonexistent_project(self):
|
||||
"""Unsaved projects don't have data."""
|
||||
p = mock.MagicMock(relpath="projC")
|
||||
self.assertEqual(self.state.GetFetchTime(p), None)
|
||||
self.assertEqual(self.state.GetCheckoutTime(p), None)
|
||||
|
||||
def test_prune_removed_projects(self):
|
||||
"""Removed projects are pruned."""
|
||||
with open(self.state._path, "w") as f:
|
||||
f.write(
|
||||
"""
|
||||
{
|
||||
"projA": {
|
||||
"last_fetch": 5
|
||||
},
|
||||
"projB": {
|
||||
"last_fetch": 7
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
def mock_exists(path):
|
||||
if "projA" in path:
|
||||
return False
|
||||
return True
|
||||
|
||||
projA = mock.MagicMock(relpath="projA")
|
||||
projB = mock.MagicMock(relpath="projB")
|
||||
self.state = self._new_state()
|
||||
self.assertEqual(self.state.GetFetchTime(projA), 5)
|
||||
self.assertEqual(self.state.GetFetchTime(projB), 7)
|
||||
with mock.patch("os.path.exists", side_effect=mock_exists):
|
||||
self.state.PruneRemovedProjects()
|
||||
self.assertIsNone(self.state.GetFetchTime(projA))
|
||||
|
||||
self.state = self._new_state()
|
||||
self.assertIsNone(self.state.GetFetchTime(projA))
|
||||
self.assertEqual(self.state.GetFetchTime(projB), 7)
|
||||
|
||||
|
||||
class GetPreciousObjectsState(unittest.TestCase):
|
||||
"""Tests for _GetPreciousObjectsState."""
|
||||
|
Reference in New Issue
Block a user