sindri / master / tests / test_git.py
import subprocess
from pathlib import Path
from sindri.git import GitManager
def test_create_bare_repo(tmp_path):
gm = GitManager(data_dir=tmp_path)
gm.create_repo("testrepo")
assert (tmp_path / "repos" / "testrepo.git").is_dir()
assert (tmp_path / "repos" / "testrepo.git" / "HEAD").exists()
def test_create_repo_idempotent(tmp_path):
gm = GitManager(data_dir=tmp_path)
gm.create_repo("testrepo")
gm.create_repo("testrepo") # Should not raise
def _push_commit(src: Path, bare: Path):
"""Helper: init a local repo, commit README, push to bare."""
subprocess.run(["git", "init", "-b", "main", str(src)], check=True, capture_output=True)
subprocess.run(["git", "config", "user.email", "test@test.com"], cwd=src, check=True, capture_output=True)
subprocess.run(["git", "config", "user.name", "Test"], cwd=src, check=True, capture_output=True)
(src / "README.md").write_text("hello")
subprocess.run(["git", "add", "."], cwd=src, check=True, capture_output=True)
subprocess.run(["git", "commit", "-m", "init"], cwd=src, check=True, capture_output=True)
subprocess.run(["git", "remote", "add", "origin", str(bare)], cwd=src, check=True, capture_output=True)
subprocess.run(["git", "push", "origin", "main"], cwd=src, check=True, capture_output=True)
def test_push_and_clone(tmp_path):
gm = GitManager(data_dir=tmp_path)
gm.create_repo("testrepo")
bare = gm.repo_path("testrepo")
_push_commit(tmp_path / "src", bare)
clone = tmp_path / "clone"
subprocess.run(["git", "clone", str(bare), str(clone)], check=True, capture_output=True)
assert (clone / "README.md").exists()
def test_create_and_remove_worktree(tmp_path):
gm = GitManager(data_dir=tmp_path)
gm.create_repo("testrepo")
bare = gm.repo_path("testrepo")
_push_commit(tmp_path / "src", bare)
wt_id, wt_path = gm.create_worktree("testrepo", "agent/fix-1")
assert wt_path.is_dir()
assert (wt_path / "README.md").exists()
gm.remove_worktree("testrepo", wt_id)
assert not wt_path.exists()