summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatt Schulte <matsch@google.com>2023-11-30 11:00:16 -0800
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-11-30 22:36:41 +0000
commit0dd0a830b055e177a713bbc81fc7ecdda1605643 (patch)
treeec8edb979c4ef993e21eb2418686a4e8be6ff17a /tests
parent9f0ef5d926b29cabf8509be1b777c24c192c5e21 (diff)
downloadgit-repo-0dd0a830b055e177a713bbc81fc7ecdda1605643.tar.gz
git-repo-0dd0a830b055e177a713bbc81fc7ecdda1605643.zip
sync: Fix partial sync false positive
In the case of a project being removed from the manifest, and in the path in which the project used to exist, and symlink is place to another project repo will start to warn about partial syncs when a partial sync did not occur. Repro steps: 1) Create a manifest with two projects. Project a -> a/ and project b -> b/ 2) Run `repo sync` 3) Remove project b from the manifest. 4) Use `link` in the manifest to link all of Project a to b/ Bug: 314161804 Change-Id: I4a4ac4f70a7038bc7e0c4e0e51ae9fc942411a34 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/395640 Reviewed-by: Gavin Mak <gavinmak@google.com> Tested-by: Matt Schulte <matsch@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_subcmds_sync.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py
index 71e404898..af6bbef7e 100644
--- a/tests/test_subcmds_sync.py
+++ b/tests/test_subcmds_sync.py
@@ -265,6 +265,44 @@ class LocalSyncState(unittest.TestCase):
self.assertIsNone(self.state.GetFetchTime(projA))
self.assertEqual(self.state.GetFetchTime(projB), 7)
+ def test_prune_removed_and_symlinked_projects(self):
+ """Removed projects that still exists on disk as symlink are pruned."""
+ with open(self.state._path, "w") as f:
+ f.write(
+ """
+ {
+ "projA": {
+ "last_fetch": 5
+ },
+ "projB": {
+ "last_fetch": 7
+ }
+ }
+ """
+ )
+
+ def mock_exists(path):
+ return True
+
+ def mock_islink(path):
+ if "projB" in path:
+ return True
+ return False
+
+ 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):
+ with mock.patch("os.path.islink", side_effect=mock_islink):
+ self.state.PruneRemovedProjects()
+ self.assertIsNone(self.state.GetFetchTime(projB))
+
+ self.state = self._new_state()
+ self.assertIsNone(self.state.GetFetchTime(projB))
+ self.assertEqual(self.state.GetFetchTime(projA), 5)
+
class GetPreciousObjectsState(unittest.TestCase):
"""Tests for _GetPreciousObjectsState."""