feat: Use mirror git cloning
Test and coverage / build (push) Failing after 54s

This commit is contained in:
2026-06-28 01:58:52 +03:00
parent 846ac52854
commit e06ad4aa4e
5 changed files with 65 additions and 32 deletions
+13 -7
View File
@@ -2,7 +2,7 @@ import base64
import os
import subprocess
from src.git import git_clone, git_pull, http_git_env, ssh_git_env
from src.git import git_clone, git_update_mirror, http_git_env, ssh_git_env
def test_ssh_git_env_uses_requested_identity_file():
@@ -32,7 +32,7 @@ def test_http_git_env_uses_basic_auth_header_without_url_credentials():
}
def test_git_clone_passes_url_and_env_to_git(monkeypatch, tmp_path):
def test_git_clone_uses_mirror_clone(monkeypatch, tmp_path):
calls = []
env = {"GIT_SSH_COMMAND": "ssh -i /tmp/test_key -o IdentitiesOnly=yes"}
@@ -48,13 +48,19 @@ def test_git_clone_passes_url_and_env_to_git(monkeypatch, tmp_path):
)
args, cwd, actual_env = calls[0]
assert args == ["git", "clone", "ssh://git@example.com/owner/repo.git", "."]
assert cwd == str(tmp_path)
assert args == [
"git",
"clone",
"--mirror",
"ssh://git@example.com/owner/repo.git",
str(tmp_path),
]
assert cwd is None
assert os.environ.items() <= actual_env.items()
assert env.items() <= actual_env.items()
def test_git_pull_passes_env_to_git(monkeypatch, tmp_path):
def test_git_update_mirror_prunes_remote_refs(monkeypatch, tmp_path):
calls = []
env = {"GIT_CONFIG_COUNT": "1"}
@@ -63,10 +69,10 @@ def test_git_pull_passes_env_to_git(monkeypatch, tmp_path):
monkeypatch.setattr(subprocess, "check_call", fake_check_call)
assert git_pull(repository=str(tmp_path), env=env)
assert git_update_mirror(repository=str(tmp_path), env=env)
args, cwd, actual_env = calls[0]
assert args == ["git", "pull"]
assert args == ["git", "remote", "update", "--prune"]
assert cwd == str(tmp_path)
assert os.environ.items() <= actual_env.items()
assert env.items() <= actual_env.items()
+18 -9
View File
@@ -79,16 +79,20 @@ def test_process_repo_clones_with_https_url_and_auth_env(monkeypatch, tmp_path):
assert env["GIT_CONFIG_VALUE_0"].startswith("Authorization: Basic ")
def test_process_repo_pulls_existing_repo_with_fetch_env(monkeypatch, tmp_path):
def test_process_repo_updates_existing_mirror_with_fetch_env(
monkeypatch,
tmp_path,
):
calls = []
repo_path = tmp_path / "alex" / "repo" / ".git"
repo_path.mkdir(parents=True)
repo_path = tmp_path / "alex" / "repo"
(repo_path / "objects").mkdir(parents=True)
(repo_path / "config").write_text("[core]\nrepositoryformatversion = 0\n")
def fake_git_pull(repository, env):
def fake_git_update_mirror(repository, env):
calls.append((repository, env))
return True
monkeypatch.setattr(cli, "git_pull", fake_git_pull)
monkeypatch.setattr(cli, "git_update_mirror", fake_git_update_mirror)
assert cli.process_repo(
config=make_config(tmp_path, FetchConfig(ssh_key="/tmp/test_key")),
@@ -116,10 +120,15 @@ def test_process_repo_returns_false_when_clone_fails(monkeypatch, tmp_path):
)
def test_process_repo_returns_false_when_pull_fails(monkeypatch, tmp_path):
repo_path = tmp_path / "alex" / "repo" / ".git"
repo_path.mkdir(parents=True)
monkeypatch.setattr(cli, "git_pull", lambda repository, env: False)
def test_process_repo_returns_false_when_update_fails(monkeypatch, tmp_path):
repo_path = tmp_path / "alex" / "repo"
(repo_path / "objects").mkdir(parents=True)
(repo_path / "config").write_text("[core]\nrepositoryformatversion = 0\n")
monkeypatch.setattr(
cli,
"git_update_mirror",
lambda repository, env: False,
)
assert not cli.process_repo(
config=make_config(tmp_path, FetchConfig(ssh_key="/tmp/test_key")),