git fetch + tests

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
2022-07-27 00:18:13 +02:00
parent 7689572edb
commit 54ed1ded30
2 changed files with 83 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
import logging
import git
import pytest
from cloner_test_fixtures import support_data_path
from pathlib import Path
@@ -67,6 +69,15 @@ def test_clone_initialized_repo(tmp_path, caplog, support_data_path):
assert r.message == "Trying to clone to initialized repository!"
def test_check_initialized(tmp_path, monkeypatch, caplog):
# hard testing directly, testing via fetch
rt = RepoTool(tmp_path.as_posix())
assert not rt.initialized
assert not rt.fetch()
assert caplog.records[1].levelname == "CRITICAL"
assert caplog.records[1].message == f"Repo {tmp_path.as_posix()} is not initialized!"
def test_clone_okay(tmp_path, caplog, support_data_path):
rt = RepoTool(tmp_path.as_posix())
assert not rt.initialized
@@ -105,3 +116,46 @@ def test_clone_okay(tmp_path, caplog, support_data_path):
assert compressing_cnt >= 2
assert receiving_cnt >= 2
assert resolving_cnt >= 2
def test_fetch_uninitialized(tmp_path, caplog):
repo_a = tmp_path.joinpath("A.git")
repo_b = tmp_path.joinpath("B.git")
repo_a.mkdir()
rt = RepoTool(repo_a.as_posix())
assert not rt.initialized
assert not rt.fetch()
assert f"Repo {repo_a.as_posix()} is not initialized!"
def test_fetch_no_remotes(tmp_path, caplog):
repo_a = tmp_path.joinpath("A.git")
git.Repo().init(repo_a.as_posix())
rt = RepoTool(repo_a.as_posix())
assert not rt.fetch()
assert caplog.records[0].levelname == "WARNING"
assert caplog.records[0].message == f"Repo: {repo_a.as_posix()} does not contain any remotes!"
def test_fetch_ok(tmp_path):
repo_a = tmp_path.joinpath("A.git")
repo_b = tmp_path.joinpath("B.git")
r = git.Repo().init(repo_a.as_posix())
rt = RepoTool(repo_b.as_posix())
assert rt.clone(repo_a.as_uri())
# new file
repo_a.joinpath(".gitignore").touch()
# commit it
r.git.add(".gitignore")
r.git.commit(message = "Test Commit", author = "Tester <test@a.b>")
hash = r.commit("master").hexsha
assert rt.fetch()
assert rt._repo.commit(hash)