Review a change¶
uh review computes a diff, builds call and type graphs for the changed code, and shows them in the web UI in execution order. Input is a local repository (working tree, revision range, or patch file) or a GitHub pull request or commit URL.
TARGETis a repository directory, a GitHub PR URL, or a GitHub commit URL. It defaults to..RANGEis a git revision range,<base>..<head>or<base>...<head>, or a single revision.
This page covers input and output. Flags: CLI reference. UI: Web UI.
Review local changes¶
uh review # uncommitted changes in ., or the last commit if clean
uh review ~/src/myrepo # same, in another repository
uh review . main...HEAD # what this branch adds since it left main
uh review . HEAD~3..HEAD # the last three commits
uh review . main # same as main...HEAD
uh review --base main # same as main...HEAD
uh review --base main --head topic # same as main...topic
RANGE is the second positional argument, so a range needs a TARGET in front. uh review HEAD~1..HEAD treats HEAD~1..HEAD as a directory and fails:
Write uh review . HEAD~1..HEAD instead.
How the diff is chosen¶
uh review applies the first matching rule:
| Order | Input | Diff shown |
|---|---|---|
| 1 | TARGET is a GitHub PR URL |
The pull request. RANGE, --base, --head and --diff are ignored. |
| 2 | TARGET is a GitHub commit URL |
The commit against its first parent. RANGE, --base, --head and --diff are ignored. |
| 3 | --diff <path\|-> |
The patch file, or stdin for -. RANGE, --base and --head are ignored. |
| 4 | RANGE is <base>...<head> |
git merge-base <base> <head> to <head>. |
| 5 | RANGE is <base>..<head> |
<base> to <head> directly, no merge base. |
| 6 | RANGE is a single revision <rev> |
git merge-base <rev> HEAD to HEAD, the same as <rev>...HEAD. |
| 7 | --base <rev> |
git merge-base <rev> <head> to <head>, where <head> is --head or HEAD. |
| 8 | Uncommitted changes exist | git diff HEAD: staged and unstaged changes to tracked files. Untracked files are not included. |
| 9 | Clean working tree | HEAD~1 to HEAD, the last commit. |
An empty head side means HEAD: main... is main...HEAD and main.. is main..HEAD.
--head only applies with --base. Without --base, it is ignored and the working-tree rule applies.
.. versus ...
main..topic diffs the two tips directly. If main has moved on since topic branched, its new commits appear as reversed changes. main...topic, a single revision and --base diff from the merge base, showing only what topic added. This matches a pull request.
For every local revision comparison, uh review also runs git merge-tree --write-tree to find files that conflict when head merges into base. It leaves the working tree and index alone. It is skipped silently on git older than 2.38.
Review a patch file¶
--diff reads a unified diff in git diff format. Each file needs a diff --git header, as git diff or gh pr diff produces.
uh review --diff change.patch
git diff main | uh review --diff -
uh review ~/src/myrepo --diff /tmp/change.patch
The patch is not applied. TARGET (default .) supplies the graphs: its working tree is the head side and its HEAD is the base side. The patch must describe changes already in that tree.
Review a GitHub pull request¶
The URL form is http(s)://<host>/<owner>/<repo>/pull/<number>. Extra path segments, query strings and fragments are ignored, so a URL copied from the Files tab (.../pull/123/files?w=1) works. Any host is accepted. GitHub Enterprise works if gh is logged in to that host.
uh review reads the pull request with the gh CLI:
gh pr viewfor the title, body, state, labels, author, base and head branches and SHAs, mergeability, and the list of changed files.gh pr difffor the patch.- Contents of the first 80 changed files at the base and head commits, read from the clone cache. The cache fetches
refs/pull/<number>/head, so fork PRs work. Commits missing from the cache are fetched withgh api.
The PR is marked as conflicting when GitHub reports it as CONFLICTING.
Review a GitHub commit¶
The URL form is https://<host>/<owner>/<repo>/commit/<sha>, where <sha> is 7 to 40 hex characters. Only https:// is accepted. The commit is diffed against its first parent. A root commit is diffed against the empty tree, labeled empty in the UI.
The commit is fetched into the clone cache. If a short SHA cannot be fetched directly, gh api repos/<owner>/<repo>/commits/<sha> resolves it to the full SHA. That call also returns the author's GitHub login.
GitHub authentication¶
GitHub URLs need the gh CLI installed and logged in to the URL's host:
uh review never changes the gh configuration. It reads gh auth status --json hosts for the host's logged-in accounts, picks one, and passes its token to each gh and git call.
Choosing the account¶
The account is chosen in this order:
--gh-account <login>.- The saved default account, if it is one of the logged-in accounts for the host (or if
ghlists no accounts). - The account
ghmarks as active for the host. - The first logged-in account for the host.
To save a default account:
This writes default_gh_account to the config file (config.toml), prints Saved default GitHub account '<login>' to <path>, and exits. If the command also has a TARGET, --diff or --base, it saves the default, then runs the review. Pass an empty string to clear it:
The config file is the one uh config path prints, or the --settings-path value. uh config set default_gh_account <login> sets the same key. See Configuration.
Token from the environment¶
For the chosen account, the token comes from gh auth token --hostname <host> --user <login>. If that returns nothing (for example, gh authenticated only by an environment token in CI), the first variable set is read:
| Host | Variables checked, in order |
|---|---|
github.com |
GH_TOKEN, GITHUB_TOKEN |
| Any other host | GH_ENTERPRISE_TOKEN, GH_TOKEN, GITHUB_TOKEN |
If neither source has a token, the review fails with gh auth token for '<login>' on '<host>' failed: ....
Clone cache¶
GitHub pull requests and commits use a persistent bare clone, so later reviews fetch only missing commits. The first clone is partial (--filter=blob:none) when the remote supports it, else full. Clones live at <cache root>/<host>/<owner>/<repo>.git. Concurrent uh processes share a clone through a lock file next to it.
The cache root is the first of:
- The
repo_cache_dirconfig key (uh config set repo_cache_dir <path>). $UHDIFF_REPO_CACHE_DIR.$XDG_CACHE_HOME/uhdiff/repos.~/.cache/uhdiff/repos.
A commit review needs the cache and fails if the clone fails. A pull request review falls back to gh api for file contents when the cache is unavailable.
Outputs¶
By default uh review serves the UI. --json and --dump-html write output and exit without a server. If both are given, --json wins.
| Command | Result |
|---|---|
uh review |
Serves the UI on 127.0.0.1 until Ctrl-C. |
uh review --open |
Same, and opens the URL in the default browser. |
uh review --port 8080 |
Serves on 127.0.0.1:8080. |
uh review --dump-html review.html |
Writes one self-contained HTML file and exits. |
uh review --json |
Prints the review payload as JSON to stdout and exits. |
Local server¶
The server binds only to 127.0.0.1. --port 0, the default, picks a free port. Once ready, uh review prints the URL:
--open runs open <url> on macOS, xdg-open <url> elsewhere. A browser failure is ignored; the server keeps running.
While running, the server answers on-demand UI requests (definition peeks, symbol links, scoped AST diffs), saves UI settings to the config file, and posts review comments to GitHub when asked from the UI.
Self-contained HTML¶
--dump-html creates missing parent directories, writes the file, prints Wrote <path>, and exits. Links, definition peeks and scoped AST diffs are computed ahead and embedded, so the file works offline. Use it to attach a review to a ticket, archive it, or host it as a static page. The live demos are made this way.
JSON payload¶
--json prints the payload the UI loads, pretty-printed. Top-level keys: schema_version, mode ("diff"), source, gh_auth, ui_settings, files, functions_dag and types_dag. source describes the input:
{
"kind": "git",
"title": "HEAD~1..HEAD",
"repo": "uhdiff",
"base_ref": "HEAD~1",
"head_ref": "HEAD",
"merge_base_sha": "639c9bef95f5740914611c1b0fff8884de9b416e",
"base_sha": "639c9bef95f5740914611c1b0fff8884de9b416e",
"head_sha": "d40edaf4d9ac0964f174a94346d6dffbfd28be31",
"has_conflict": false,
"repo_path": "/home/me/src/uhdiff"
}
kind is git for local input, github_pr for a pull request, and github_commit for a commit. PR and commit payloads also carry fields such as pr_url, author and description_md. For a working-tree diff, head_ref is working-tree; for --diff, base_ref is patch.
For machine-readable graphs without the review UI payload, see uh graph.
Startup UI modes¶
These flags set how the UI opens for this run. They apply to the served UI and --dump-html files, not to saved settings.
| Flag | Effect |
|---|---|
--ast-diff |
Turns on scoped structural AST diff highlighting. Off by default. |
--classic |
Opens in classic mode: a flat, file-order diff with inline definition peeks. |
--inlay-diffs |
Turns on inline type and call diff inlays. On by default, so this matters only when they were turned off and saved in settings. |
uh review https://github.com/OWNER/REPO/pull/123 --ast-diff --open
uh review . main...HEAD --classic --dump-html classic.html
All three can be toggled in the UI. See Web UI for what each mode shows.
Progress¶
When stderr is a terminal, uh review shows a progress bar while it fetches, diffs and extracts. To turn it off, set progress = false in the config file (uh config set progress false). See Configuration.