Repo cloner: list submodules

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
2022-07-29 04:22:05 +02:00
parent d0c808ab0f
commit 8a150c63c5
2 changed files with 94 additions and 0 deletions

View File

@@ -419,3 +419,62 @@ def test_fingerprint(support_data_path: Path, repo: str, hash):
assert not rt.initialized
assert rt.repo_fingerprint() == hash
def test_list_submodules_no_submodules(cloned_base_repo_obj):
assert cloned_base_repo_obj.list_submodules() == []
def test_list_submodules_ok(tmp_path, support_data_path):
rt = RepoTool(tmp_path.joinpath("repo.git").as_posix())
rt.clone(support_data_path.joinpath("test-repo-submodules").as_uri())
assert rt.list_submodules() == ['https://git.sw3.cz/kamikaze/test-repo-base.git']
assert rt.list_submodules("HEAD") == ['https://git.sw3.cz/kamikaze/test-repo-base.git']
assert rt.list_submodules("cc58d514348d0d2c8f0b75ad1f7ff96eb02781d5") == [
'https://git.sw3.cz/kamikaze/test-repo-base.git',
'https://git.sw3.cz/kamikaze/test-repo-reduced.git'
]
def test_list_submodules_history(tmp_path, support_data_path):
rt = RepoTool(tmp_path.joinpath("repo.git").as_posix())
rt.clone(support_data_path.joinpath("test-repo-submodules").as_uri())
history = rt.list_submodules_history()
history.sort()
assert history == [
'https://git.sw3.cz/kamikaze/test-repo-base.git',
'https://git.sw3.cz/kamikaze/test-repo-different-tags.git',
'https://git.sw3.cz/kamikaze/test-repo-reduced.git',
]
assert rt.list_submodules_history(100) == []
assert rt.list_submodules_history(120) == ['https://git.sw3.cz/kamikaze/test-repo-different-tags.git']
history = rt.list_submodules_history(320)
history.sort()
assert history == [
'https://git.sw3.cz/kamikaze/test-repo-base.git',
'https://git.sw3.cz/kamikaze/test-repo-different-tags.git',
'https://git.sw3.cz/kamikaze/test-repo-reduced.git',
]
def test_list_submodules_history_progress(support_data_path, caplog, monkeypatch):
mocked_time = 1659059078
def fake_time() -> float:
nonlocal mocked_time
mocked_time += 0.2
return mocked_time
rt = RepoTool(support_data_path.joinpath("test-repo-submodules-long").as_posix())
caplog.set_level(logging.INFO)
caplog.clear()
with monkeypatch.context() as m:
import time
m.setattr(time, "time", fake_time)
rt.list_submodules_history(22)
assert all(x.levelname == "INFO" for x in caplog.records)
import re
regex = re.compile("Submodule discovery: \\d+ commits finished, 1 discovered")
assert 8 == len(caplog.records)
assert 7 == sum(1 if regex.match(x.message) else 0 for x in caplog.records)