Files
repo-scoping/tests/test_git_ingestion.py

48 lines
1.4 KiB
Python

import subprocess
from repo_registry.repo_ingestion.git import GitIngestionService
def run(command, cwd):
subprocess.run(command, cwd=cwd, check=True, capture_output=True, text=True)
def make_git_repo(path):
path.mkdir()
run(["git", "init", "-b", "main"], path)
run(["git", "config", "user.email", "tests@example.com"], path)
run(["git", "config", "user.name", "Tests"], path)
(path / "README.md").write_text("# Clone Me\n", encoding="utf-8")
(path / "app.py").write_text("print('ok')\n", encoding="utf-8")
run(["git", "add", "."], path)
run(["git", "commit", "-m", "initial"], path)
def test_ingestion_keeps_local_paths_local(tmp_path):
source = tmp_path / "source"
source.mkdir()
checkout = GitIngestionService(tmp_path / "checkouts").resolve(str(source))
assert checkout.source_path == source.resolve()
assert checkout.was_cloned is False
def test_ingestion_clones_file_url(tmp_path):
source = tmp_path / "source"
make_git_repo(source)
checkout = GitIngestionService(tmp_path / "checkouts").resolve(source.as_uri())
assert checkout.was_cloned is True
assert checkout.source_path != source.resolve()
assert (checkout.source_path / "README.md").exists()
branch = subprocess.run(
["git", "branch", "--show-current"],
cwd=checkout.source_path,
check=True,
capture_output=True,
text=True,
).stdout.strip()
assert branch == "main"