Fixed bug in calling repo_fingerprint() like property

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
Václav Valíček 2022-08-09 14:02:06 +02:00
parent 27057beed4
commit 2557cd9a6e
Signed by: valicek
GPG Key ID: FF05BDCA0C73BB31
2 changed files with 12 additions and 10 deletions

View File

@ -110,24 +110,27 @@ class Cloner:
return submodule_list return submodule_list
def sync(self) -> bool: def sync(self) -> bool:
log.debug("cloner.sync() called")
if not self.__opened: if not self.__opened:
self._repo = RepoTool(self.main_repo_path) self._repo = RepoTool(self.main_repo_path)
if not self._repo.initialized: if not self._repo.initialized:
return False return False
# determine recursive behavior # determine recursive behavior
log.debug(f"determining >not< cloner._config.cloner_submodules ? {self._config.cloner_submodules}")
if not self._config.cloner_submodules: if not self._config.cloner_submodules:
log.debug(f"Just simple repo fetch - no submodules")
return self._repo.fetch() return self._repo.fetch()
fingerprint = self._repo.repo_fingerprint fingerprint = self._repo.repo_fingerprint()
# recursive now # recursive now
log.debug(f"Recursive repo fetch")
if not self._repo.fetch(): if not self._repo.fetch():
log.critical(f"Repo fetch failed for {self._config.cloner_project_name}") log.critical(f"Repo fetch failed for {self._config.cloner_project_name}")
return False return False
if fingerprint == self._repo.repo_fingerprint: if fingerprint == self._repo.repo_fingerprint():
log.info(f"Repo fingerpring unchanged - submodule discovery skipped") log.info(f"Repo fingerprint unchanged - submodule discovery skipped")
return True return True
log.debug(f"Loading submodules.cache") log.debug(f"Loading submodules.cache")

View File

@ -279,9 +279,8 @@ def test_sync_submodules_failed(cloner_dir_with_config, caplog):
with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks) as mock: with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks) as mock:
cl = Cloner(ds) cl = Cloner(ds)
assert not cl.sync() assert not cl.sync()
assert caplog.records[2].levelname == "CRITICAL"
assert caplog.records[1].levelname == "CRITICAL" assert caplog.records[2].message == "Repo fetch failed for Mocked Project"
assert caplog.records[1].message == "Repo fetch failed for Mocked Project"
def my_check_submodules_repo( def my_check_submodules_repo(
@ -309,7 +308,7 @@ def test_submodules_sync_succeed(cloner_dir_with_config, caplog):
'initialized': PropertyMock(side_effect = [True, False, True, True, True]), 'initialized': PropertyMock(side_effect = [True, False, True, True, True]),
'fetch': MagicMock(return_value = True), 'fetch': MagicMock(return_value = True),
'clone': MagicMock(return_value = True), 'clone': MagicMock(return_value = True),
'repo_fingerprint': PropertyMock(side_effect = ["fp1", "fp2", "fp3"]), 'repo_fingerprint': MagicMock(side_effect = ["fp1", "fp2", "fp3"]),
} }
with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks): with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks):
@ -336,7 +335,7 @@ def test_submodules_sync_unchanged_main_repo(cloner_dir_with_config, caplog):
'fetch': MagicMock(return_value = True), 'fetch': MagicMock(return_value = True),
'clone': MagicMock(return_value = True), 'clone': MagicMock(return_value = True),
# fingerprint is same for both queries, so nothing is fetched/synced afterwards # fingerprint is same for both queries, so nothing is fetched/synced afterwards
'repo_fingerprint': PropertyMock(return_value = "fp1"), 'repo_fingerprint': MagicMock(return_value = "fp1"),
} }
with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks): with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks):
@ -363,7 +362,7 @@ def test_submodules_sync_one_fail(cloner_dir_with_config, caplog):
'initialized': PropertyMock(return_value = True), 'initialized': PropertyMock(return_value = True),
'fetch': MagicMock(side_effect = [True, True, True, False, True]), 'fetch': MagicMock(side_effect = [True, True, True, False, True]),
'clone': MagicMock(return_value = True), 'clone': MagicMock(return_value = True),
'repo_fingerprint': PropertyMock(side_effect = ["fp1", "fp2", "fp3"]), 'repo_fingerprint': MagicMock(side_effect = ["fp1", "fp2", "fp3"]),
} }
with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks): with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks):