mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
sync: Ignore repo project when checking partial syncs
The repo project is fetched at most once a day and should be ignored when checking if the tree is partially synced. Bug: b/286126621, b/271507654 Change-Id: I684ed1669c3b3b9605162f8cc9d57185bb3dfe8e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/383494 Commit-Queue: Gavin Mak <gavinmak@google.com> Tested-by: Gavin Mak <gavinmak@google.com> Reviewed-by: Josip Sokcevic <sokcevic@google.com>
This commit is contained in:
parent
5a3a5f7cec
commit
321b7934b5
@ -2007,7 +2007,11 @@ class _LocalSyncState(object):
|
|||||||
"""Return whether a partial sync state is detected."""
|
"""Return whether a partial sync state is detected."""
|
||||||
self._Load()
|
self._Load()
|
||||||
prev_checkout_t = None
|
prev_checkout_t = None
|
||||||
for data in self._state.values():
|
for path, data in self._state.items():
|
||||||
|
if path == self._manifest.repoProject.relpath:
|
||||||
|
# The repo project isn't included in most syncs so we should
|
||||||
|
# ignore it here.
|
||||||
|
continue
|
||||||
checkout_t = data.get(self._LAST_CHECKOUT)
|
checkout_t = data.get(self._LAST_CHECKOUT)
|
||||||
if not checkout_t:
|
if not checkout_t:
|
||||||
return True
|
return True
|
||||||
|
@ -119,6 +119,7 @@ class LocalSyncState(unittest.TestCase):
|
|||||||
self.repodir = tempfile.mkdtemp(".repo")
|
self.repodir = tempfile.mkdtemp(".repo")
|
||||||
self.manifest = mock.MagicMock(
|
self.manifest = mock.MagicMock(
|
||||||
repodir=self.repodir,
|
repodir=self.repodir,
|
||||||
|
repoProject=mock.MagicMock(relpath=".repo/repo"),
|
||||||
)
|
)
|
||||||
self.state = self._new_state()
|
self.state = self._new_state()
|
||||||
|
|
||||||
@ -126,8 +127,8 @@ class LocalSyncState(unittest.TestCase):
|
|||||||
"""Common teardown."""
|
"""Common teardown."""
|
||||||
shutil.rmtree(self.repodir)
|
shutil.rmtree(self.repodir)
|
||||||
|
|
||||||
def _new_state(self):
|
def _new_state(self, time=_TIME):
|
||||||
with mock.patch("time.time", return_value=self._TIME):
|
with mock.patch("time.time", return_value=time):
|
||||||
return sync._LocalSyncState(self.manifest)
|
return sync._LocalSyncState(self.manifest)
|
||||||
|
|
||||||
def test_set(self):
|
def test_set(self):
|
||||||
@ -202,6 +203,23 @@ class LocalSyncState(unittest.TestCase):
|
|||||||
self.state.SetCheckoutTime(projB)
|
self.state.SetCheckoutTime(projB)
|
||||||
self.assertEqual(self.state.IsPartiallySynced(), True)
|
self.assertEqual(self.state.IsPartiallySynced(), True)
|
||||||
|
|
||||||
|
def test_ignore_repo_project(self):
|
||||||
|
"""Sync data for repo project is ignored when checking partial sync."""
|
||||||
|
p = mock.MagicMock(relpath="projA")
|
||||||
|
self.state.SetFetchTime(p)
|
||||||
|
self.state.SetCheckoutTime(p)
|
||||||
|
self.state.SetFetchTime(self.manifest.repoProject)
|
||||||
|
self.state.Save()
|
||||||
|
self.assertEqual(self.state.IsPartiallySynced(), False)
|
||||||
|
|
||||||
|
self.state = self._new_state(self._TIME + 1)
|
||||||
|
self.state.SetFetchTime(self.manifest.repoProject)
|
||||||
|
self.assertEqual(
|
||||||
|
self.state.GetFetchTime(self.manifest.repoProject), self._TIME + 1
|
||||||
|
)
|
||||||
|
self.assertEqual(self.state.GetFetchTime(p), self._TIME)
|
||||||
|
self.assertEqual(self.state.IsPartiallySynced(), False)
|
||||||
|
|
||||||
def test_nonexistent_project(self):
|
def test_nonexistent_project(self):
|
||||||
"""Unsaved projects don't have data."""
|
"""Unsaved projects don't have data."""
|
||||||
p = mock.MagicMock(relpath="projC")
|
p = mock.MagicMock(relpath="projC")
|
||||||
|
Loading…
Reference in New Issue
Block a user