From 5554572f02537b8646139d59ab520e59e1d5f7b3 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Thu, 22 Feb 2024 16:38:00 -0800 Subject: sync: Introduce git checkout levels If a repo manifest is updated so that project B is placed within a project A, and if project A had content in new B's location in the old checkout, then repo sync could break depending on checkout order, since B can't be checked out before A. This change introduces checkout levels which enforces right sequence of checkouts while still allowing for parallel checkout. In an example above, A will always be checked out first before B. BUG=b:325119758 TEST=./run_tests, manual sync on ChromeOS repository Change-Id: Ib3b5e4d2639ca56620a1e4c6bf76d7b1ab805250 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/410421 Tested-by: Josip Sokcevic Reviewed-by: Greg Edelston Commit-Queue: Josip Sokcevic Reviewed-by: Gavin Mak --- tests/test_subcmds_sync.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/test_subcmds_sync.py') diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index af6bbef7..13e23e34 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py @@ -304,6 +304,32 @@ class LocalSyncState(unittest.TestCase): self.assertEqual(self.state.GetFetchTime(projA), 5) +class SafeCheckoutOrder(unittest.TestCase): + def test_no_nested(self): + p_f = mock.MagicMock(relpath="f") + p_foo = mock.MagicMock(relpath="foo") + out = sync._SafeCheckoutOrder([p_f, p_foo]) + self.assertEqual(out, [[p_f, p_foo]]) + + def test_basic_nested(self): + p_foo = p_foo = mock.MagicMock(relpath="foo") + p_foo_bar = mock.MagicMock(relpath="foo/bar") + out = sync._SafeCheckoutOrder([p_foo, p_foo_bar]) + self.assertEqual(out, [[p_foo], [p_foo_bar]]) + + def test_complex_nested(self): + p_foo = mock.MagicMock(relpath="foo") + p_foo_bar = mock.MagicMock(relpath="foo/bar") + p_foo_bar_baz_baq = mock.MagicMock(relpath="foo/bar/baz/baq") + p_bar = mock.MagicMock(relpath="bar") + out = sync._SafeCheckoutOrder( + [p_foo_bar_baz_baq, p_foo, p_foo_bar, p_bar] + ) + self.assertEqual( + out, [[p_bar, p_foo], [p_foo_bar], [p_foo_bar_baz_baq]] + ) + + class GetPreciousObjectsState(unittest.TestCase): """Tests for _GetPreciousObjectsState.""" -- cgit v1.2.3-54-g00ecf