Cloner: sync - check fingerprint before costy discovery
Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
@@ -306,9 +306,10 @@ def test_submodules_sync_succeed(cloner_dir_with_config, caplog):
|
||||
|
||||
# mock almost everything
|
||||
mocks = {
|
||||
'initialized': PropertyMock(side_effect = [True, False, True, True, True]),
|
||||
'fetch': MagicMock(return_value = True),
|
||||
'clone': MagicMock(return_value = True),
|
||||
'initialized': PropertyMock(side_effect = [True, False, True, True, True]),
|
||||
'fetch': MagicMock(return_value = True),
|
||||
'clone': MagicMock(return_value = True),
|
||||
'repo_fingerprint': PropertyMock(side_effect = ["fp1", "fp2", "fp3"]),
|
||||
}
|
||||
|
||||
with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks):
|
||||
@@ -320,6 +321,33 @@ def test_submodules_sync_succeed(cloner_dir_with_config, caplog):
|
||||
assert repo_cloner.lib.cloner.RepoTool.clone.call_count == 1
|
||||
|
||||
|
||||
def test_submodules_sync_unchanged_main_repo(cloner_dir_with_config, caplog):
|
||||
caplog.set_level(0)
|
||||
cloner_dir_with_config.joinpath("cache", "submodules").mkdir(parents = True)
|
||||
cloner_dir_with_config.joinpath("cache", "submodules", "submodules.cache") \
|
||||
.write_text("https://git.hosting:previous/submodule.git")
|
||||
ds = MockDirStruct(cloner_dir_with_config)
|
||||
ds.config.cloner_repo_url = "https://git.hosting:namespace/whatever.git"
|
||||
ds.config.cloner_submodules = True
|
||||
|
||||
# mock almost everything
|
||||
mocks = {
|
||||
'initialized': PropertyMock(side_effect = [True, False, True, True, True]),
|
||||
'fetch': MagicMock(return_value = True),
|
||||
'clone': MagicMock(return_value = True),
|
||||
# fingerprint is same for both queries, so nothing is fetched/synced afterwards
|
||||
'repo_fingerprint': PropertyMock(return_value = "fp1"),
|
||||
}
|
||||
|
||||
with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks):
|
||||
Cloner.check_submodules_repo = my_check_submodules_repo
|
||||
cl = Cloner(ds)
|
||||
assert cl.sync()
|
||||
|
||||
assert repo_cloner.lib.cloner.RepoTool.fetch.call_count == 1
|
||||
assert repo_cloner.lib.cloner.RepoTool.clone.call_count == 0
|
||||
|
||||
|
||||
def test_submodules_sync_one_fail(cloner_dir_with_config, caplog):
|
||||
cloner_dir_with_config.joinpath("cache", "submodules").mkdir(parents = True)
|
||||
cloner_dir_with_config.joinpath("cache", "submodules", "submodules.cache") \
|
||||
@@ -332,9 +360,10 @@ def test_submodules_sync_one_fail(cloner_dir_with_config, caplog):
|
||||
|
||||
# mock almost everything
|
||||
mocks = {
|
||||
'initialized': PropertyMock(return_value = True),
|
||||
'fetch': MagicMock(side_effect = [True, True, True, False, True]),
|
||||
'clone': MagicMock(return_value = True),
|
||||
'initialized': PropertyMock(return_value = True),
|
||||
'fetch': MagicMock(side_effect = [True, True, True, False, True]),
|
||||
'clone': MagicMock(return_value = True),
|
||||
'repo_fingerprint': PropertyMock(side_effect = ["fp1", "fp2", "fp3"]),
|
||||
}
|
||||
|
||||
with patch.multiple("repo_cloner.lib.cloner.RepoTool", **mocks):
|
||||
@@ -458,6 +487,7 @@ def test_clone_recursive(tmp_path, path_repo_base, caplog):
|
||||
patch_clone_recursive.assert_called_with(
|
||||
'https://repo', tmp_path.joinpath('cache', 'submodules').as_posix(), scan_depth = None)
|
||||
|
||||
|
||||
def test_detector_enabled(cloner_dir_with_config):
|
||||
ds = MockDirStruct(cloner_dir_with_config)
|
||||
ds.config.cloner_repo_url = "http://mock"
|
||||
@@ -465,4 +495,3 @@ def test_detector_enabled(cloner_dir_with_config):
|
||||
assert not cl.detector_enabled
|
||||
Path(cloner_dir_with_config).joinpath("config", "detector.cfg").touch()
|
||||
assert cl.detector_enabled
|
||||
|
||||
|
||||
Reference in New Issue
Block a user