diff --git a/README.md b/README.md index cebd185..8be8cc9 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,14 @@ gh pr-review [options] Inside a repo clone, a bare number works: `gh pr-review 42`. +``` +gh pr-review rounds [--json] [-u ] +gh pr-review gc [--dry-run] [-u ] +``` + +`rounds` shows a PR's round history (see [Round history](#round-history)). `gc` removes the review worktrees and +private refs of merged and closed PRs (see [Cleaning up](#cleaning-up)). + | Option | Default | Purpose | | --- | --- | --- | | `--model ` | `github-copilot/gpt-5.6-sol` | Any pi model ID | @@ -64,9 +72,9 @@ Inside a repo clone, a bare number works: `gh pr-review 42`. | `--json` | off | With `--check`: print the decision as JSON on stdout | | `--force-round` | off | Run a round even when the loop check stops it or nothing changed | | `--full` | off | Review the whole PR again, as in round 1. Earlier findings are still re-checked by ID | -| `--clone ` | looked up | Review in a worktree of this local clone (see Artifacts) | +| `--clone ` | looked up | Review in a worktree of this local clone (see [Where reviews run](#where-reviews-run)) | | `--fresh` | off | Review in a throwaway depth-50 clone in the run folder, as earlier versions did | -| `--doctor` | — | Check prerequisites and exit | +| `--doctor` | — | Check prerequisites, print the state folder, the config file and the clone roots, and exit | Environment variables: `GH_PR_REVIEW_MODEL` (default model), `GH_PR_REVIEW_USER` (default `--user`), @@ -109,66 +117,76 @@ point; this PR branches inside the JSON exporter instead ... **Ready to merge?** No ``` -## Artifacts +## Where reviews run + +### The clone + +The review runs in a worktree of a local clone of the repository. The run looks for the clone in this order, and +prints the one it picked: + +1. `--clone `. A clone it can't use (see below) is an error. +2. The config's `clones` map (see [The config file](#the-config-file)). A clone it can't use is skipped, with a note. +3. The clone that the last scan picked for the repo, kept in `/clones.json`, while it is still usable and + still has a matching remote. +4. A scan of the config's `roots` (default `["~/repos"]`) for clones up to 4 folders below a root (not in + `node_modules` or `*.reviews` folders): the newest-fetched clone with a matching remote. Clones it can't use are + skipped, with a note. +5. A cache clone, `${XDG_CACHE_HOME:-~/.cache}/gh-pr-review/clones///`: a bare clone, made on the + first run that needs it. + +A remote matches when it names the host, owner and repo, whatever the remote's name; for a host with a port (GitHub +Enterprise at `ghe.local:8443`), an `https` remote must have that port, an `ssh` one any port (its own is the SSH +server's). `:443`, the `https` default, is the same as no port, in the host and in a remote: `ghe.local:443` is +`ghe.local`, in the clones map and the cache folder too. A path inside a clone (a subfolder, a linked worktree) stands +for that clone. + +A clone can't be used when it is shallow or partial (git would fetch what is missing on demand, with credentials the +reviewer's git does not have) or sparse (its worktree would lack files), when it is inside another clone's working +tree, or when a folder it is in has a `.git` of any kind, even one git cannot read (a linked worktree whose clone is +gone or not mounted, a broken symlink): its `.reviews` folder would land in a checkout. + +A cache clone is made by one run at a time (others wait for it), in a folder beside its place +(`~clone.`), and renamed into place once complete. One there that is not a usable bare clone of the repo +is reported, with the `mv` command that moves it away, and left as it is. + +### The review worktree and the private refs + +The review worktree is `.reviews/////`, next to the clone's real folder +(symlinks resolved), detached at the PR head, and reused (reset and cleaned) from round to round. `` is the +PR's head branch with anything but letters, digits, `.`, `_` and `-` made a `-`, at most 60 characters. A clone that +serves a repo and its fork keeps their PRs apart. + +The run fetches the PR into `refs/pr-review/////head` and `…/base`, and keeps each posted +round's commits as `…//round-` and `…//round--base`, so a force-push leaves the next round incremental. +It changes nothing else in the clone: not its branches, remote-tracking refs, `HEAD`, index, stash, config or files. +Its git commands run with the clone's hooks, fsmonitor and automatic maintenance off. + +`.reviews` and the cache folder are yours only (`0700`), and so are the folders and files the run makes in them: a +clone kept in a private folder gets no readable copy next to it. A worktree is reused only inside `.reviews`: a saved +one elsewhere (an earlier version made it next to a symlink to the clone, readable by others) is left as it is, with a +warning that says how to remove it. A folder in the way of a new worktree is never deleted. + +A `.reviews` that is not the tool's folder (a symlink, someone else's folder, a checkout or a folder inside +one, or a folder in it that leads elsewhere) is refused, naming it, before anything is made or changed in it. A `.git` +of any kind counts as a checkout: in `.reviews`, in every folder above it (up to `/`: a clone anywhere under a `~` with +a `.git` is refused, `--fresh` still works), and in the folders on the way to a lock or worktree in it. + +### The state folder Each PR has one state folder, `/////`, where `` is `$GH_PR_REVIEW_STATE` (a relative path is taken from the folder the command runs in), else `${XDG_STATE_HOME:-~/.local/state}/gh-pr-review` (a -relative `XDG_STATE_HOME` is ignored, as the XDG spec says). ``, here and in the PR's lock, refs and review -worktree below, is the PR URL's host in lowercase, with its port but not `:443`, the `https` default: a run given +relative `XDG_STATE_HOME` is ignored, as the XDG spec says). ``, here and in the PR's refs, review worktree and +clone lock, is the PR URL's host in lowercase, with its port but not `:443`: a run given `https://ghe.local:443/o/r/pull/7` and one given `https://GHE.local/o/r/pull/7` share the PR's folder, lock, worktree and round pins, while `ghe.local:8443` is another host. Calls to GitHub use the host as the URL gives it. The PR's -folder and its run folders are readable by you only (0700), whatever the umask: +folder and its run folders are readable by you only (`0700`), whatever the umask. It holds: - `round-/`: the files of the run that posted round K; `preview-