diff --git a/.gitignore b/.gitignore index 305f680..f5d67bd 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,6 @@ build/ .claude/worktrees/ .DS_Store -# local SQLite DB (bot without Docker) +# local run without Docker: SQLite DB, uploads clone, demo repo *.db +data/ diff --git a/Makefile b/Makefile index b26395f..b710408 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: install lint fmt typecheck test cov up down logs ps +.PHONY: install lint fmt typecheck test cov up down logs ps run demo-repo install: uv sync @@ -30,3 +30,18 @@ logs: ps: docker compose ps + +# Run the bot on this machine without Docker: SQLite (./tgit.db) and the settings from .env +run: + uv run python -m app + +# A local uploads repo seeded from the template — try the bot without SourceCraft: +# make demo-repo → put the printed GIT_UPLOADS_URL into .env → make run +DEMO_REPO := $(CURDIR)/data/demo-uploads.git +demo-repo: + @test ! -e $(DEMO_REPO) || { echo "$(DEMO_REPO) already exists"; exit 1; } + @rm -rf data/demo-seed && mkdir -p data && cp -r infra/uploads-template data/demo-seed + @cd data/demo-seed && git init -q -b main && git add -A \ + && git -c user.name=tgit-bot -c user.email=tgit-bot@users.noreply.tgit commit -qm "init: uploads template" + @git clone -q --bare data/demo-seed $(DEMO_REPO) && rm -rf data/demo-seed + @echo "GIT_UPLOADS_URL=$(DEMO_REPO)" diff --git a/app/repo/git.py b/app/repo/git.py index f1bfeb9..dd26114 100644 --- a/app/repo/git.py +++ b/app/repo/git.py @@ -47,7 +47,8 @@ class CommitInfo: class UploadsRepo: def __init__(self, settings: GitSettings) -> None: self._s = settings - self._dir = settings.clone_dir + # absolute: git clone runs from the parent dir, a relative path would land one level deeper + self._dir = settings.clone_dir.resolve() self._lock = asyncio.Lock() self._fetched_at: float | None = None self._key_path = self._materialize_key() diff --git a/tests/repo/test_git.py b/tests/repo/test_git.py index 98a0be4..68acac2 100644 --- a/tests/repo/test_git.py +++ b/tests/repo/test_git.py @@ -83,3 +83,14 @@ async def test_unreachable_remote(tmp_path: Path) -> None: broken = UploadsRepo(GitSettings(uploads_url=str(tmp_path / "missing.git"), clone_dir=tmp_path / "c3")) with pytest.raises(GitError, match="clone"): await broken.refresh() + + +async def test_relative_clone_dir(remote: Path, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + from app.config import GitSettings + + monkeypatch.chdir(tmp_path) + relative = UploadsRepo(GitSettings(uploads_url=str(remote), clone_dir=Path("data/uploads"))) + await relative.refresh() + + assert (tmp_path / "data" / "uploads" / ".git").is_dir() + assert "README.md" in [e.name for e in await relative.list_dir()]