--- name: dgit-repo-management description: Manage git repositories on a dgit host (create, push, configure, inspect, gc, delete, list). Use when an agent needs to set up or administer repositories served by dgit / durable-git, whether through the dgit-repo CLI or the raw HTTP admin endpoints. --- # Managing repositories on a dgit host dgit is a git server where each repository is a Cloudflare Durable Object. Key behaviors that differ from GitHub-style hosts: - **Push-to-create.** Pushing to a name that does not exist creates the repository — and it is **public** on arrival. - **Private-by-default requires pre-registration.** To keep a repository private from the first push, register it with `private: true` before pushing (`dgit-repo create`, or a `PUT //config`). - **Reads of public repositories are open.** Pushes, admin operations, and everything on a private repository require the token. ## Setup The host and credentials come from the environment, not flags: 1. Host: `$DGIT_HOST`, else `git config --global dgit.host `. 2. Auth: a git credential helper must hold the token for `https://` (username is arbitrary; the password is the `GIT_TOKEN`). Both `git push` and `dgit-repo` resolve credentials the same way, via `git credential fill`. If neither is configured, report the blocker to the user — do not guess hosts or tokens. ## Preferred: the dgit-repo CLI `scripts/dgit-repo` in this repository wraps every admin endpoint. It needs `bash`, `curl`, `jq`, and `git`. ```sh scripts/dgit-repo create NAME [--public] [-d DESC] [-s SECTION] [-o OWNER] scripts/dgit-repo config NAME [--private|--public] [-d DESC] [-s SECTION] [-o OWNER] scripts/dgit-repo show NAME scripts/dgit-repo gc NAME scripts/dgit-repo delete NAME [--yes] scripts/dgit-repo list ``` Safety rails worth knowing (they surface as errors, not prompts): - `create` refuses a name that already exists; it cannot silently flip an existing repository private-to-public or back. - `config` refuses a name that does not exist, so a typo cannot create a stray repository. - `delete` asks to type the repository name unless `--yes` is passed. Deletion is irreversible — never add `--yes` without an explicit user request to delete. ## Typical workflows New private repository, then first push: ```sh dgit-repo create myrepo -d "One-line description" -s tools git remote add origin https:///myrepo.git git push -u origin main ``` New public repository: same, plus `--public`. Publish an already-pushed repository (it was created public by a push): ```sh dgit-repo config myrepo --private # or --public, -d, -s, -o ``` ## Raw HTTP fallback Without the CLI, the same operations are plain authenticated HTTP (-u x:$GIT_TOKEN; config bodies are JSON): ```sh curl -X PUT -u x:$GIT_TOKEN -H 'content-type: application/json' \ -d '{"description":"...","section":"tools","private":true}' \ https:///myrepo/config curl -X POST -u x:$GIT_TOKEN https:///myrepo/gc curl -X DELETE -u x:$GIT_TOKEN https:///myrepo curl -s https:///api/repos # public index (no auth) ``` The JSON content API (`//api/refs|log|commit|tree|blob|diff`) is read-only and gated like the repository's pages; see `docs/api.md`. ## Gotchas - A name must match `[A-Za-z0-9][A-Za-z0-9._-]*`; `api`, `info`, and a few protocol paths are reserved. - Failed authentications are rate-limited per IP (10 failures per minute): after several 401s, wait instead of retrying in a loop. - Unreachable objects are pruned automatically after forced updates and ref deletions; `gc` is only needed manually after large rewrites. - Repository metadata changes can lag a few seconds in per-isolate caches; do not treat a stale index listing as a failed update.