Skip to content

Report an empty listing in a bare repo instead of nothing - #3992

Merged
max-sixty merged 7 commits into
mainfrom
land/bare-repo-empty-list
Sep 3, 2026
Merged

max-sixty merged 7 commits into
mainfrom
land/bare-repo-empty-list

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

wt list in a bare repository with no linked worktrees printed nothing at all and exited 0, so an empty repository looked exactly like a command that had silently failed.

Collection returned early the moment the worktree list came back empty, before any branch rows were built. It now carries on. A bare repo with no worktrees still has branches to list under --branches, and a listing that ends up with no rows at all says so on stderr:

$ wt list                       # a git clone --bare, branches intact
○ No worktrees
↳ To see the branches, run wt list --branches; to check one out, run wt switch <branch>

$ wt list                       # a fresh git init --bare, no branches
○ No worktrees
↳ To create a worktree, run wt switch --create <branch>

The hint follows the branch inventory because --create on a branch that already exists errors, and git clone --bare — the shape that reaches this listing most often — keeps its branches.

stdout stays empty, so wt list | … is unaffected. --format json returns its envelope with "items": [] instead of nothing. wt list --branches lists the repo's branches, which it could not reach before.

The main-worktree lookup behind the old early return returned an error when nothing could be the main worktree. It now returns Option: no row is flagged main, and path shortening falls back to the repo root, which no row uses because a branch-only row has no path.

Dropping the early return also brought the stale-default-branch check into a shape it never used to reach — a bare repo with no branches at all. infer_default_branch_locally resolves symbolic-ref HEAD, so default_branch() answers main in a fresh git init --bare -b main even without refs/heads/main, and the check reported it as externally deleted. Worse, the hint's remedy looped: clearing the persisted value only let the next run re-infer it from HEAD. The warning is now gated on a non-empty branch inventory — an empty one is a repo with no commits, not a deleted branch — and test_bare_repo_list_no_commits pins that shape.

UX survey items: #10.

Reviewable files: src/commands/list/collect/mod.rs, tests/integration_tests/bare_repository.rs. Generated mirrors and snapshots are regenerated.

This was written by Claude Code on behalf of max-sixty

🤖 Generated with Claude Code

https://claude.ai/code/session_01XAUYWFN9d9oh6jyoQiouHb

max-sixty and others added 4 commits September 1, 2026 16:12
`wt list` in a bare repository with no linked worktrees produced zero bytes
on both streams and exited 0. `list_worktrees` filters git's bare entry out,
so the porcelain list came back empty and `collect` returned `Ok(None)` before
it had collected anything — `handle_list` then had nothing to print, for every
format.

Two things were wrong with that early exit, and one gate replaces it.

It fired before branches were gathered, so `--branches` in a bare repo listed
nothing either, even though the branches are exactly what a fresh
`git clone --bare` has. The pipeline can't simply run past the old return
point: it resolved a main worktree with `ok_or_else(|| "No worktrees found")`
and threaded that id and path through sorting, the `is_main` flag, and layout.
Both are now `Option`/fallback — no row is flagged main, and path shortening
bases on the repo root, which no row consults because a branch-only row has no
path. The same relaxation retires an error path that a repo of entirely
prunable registrations could reach.

And it exited silently in JSON mode, where an empty stdout is not a parseable
answer. The new gate sits after `all_items` is assembled, so it fires only when
the whole listing is empty. It prints `No worktrees` plus the create hint to
stderr for the table (stdout stays empty — a lone header would be noise to a
pipe), and returns an empty `ListData` either way, so `--format json` emits
`[]` or a schema-2 envelope with `items: []`. The narration is table-only:
JSON already says it on stdout, and the picker owns the terminal.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The hint under `○ No worktrees` read "To create one", where "one" resolved
only against the info line above it. Hints render as separate messages, so
`writing-user-outputs` requires each to stand on its own; the house phrasing
for this suggestion already exists at the `WorktreeNotFound` hint in
`src/git/error.rs`, with the same `<underline>` command markup.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BGS51k25qzfeJEJ8dfxEEY
The doc comment framed the behavior against what `wt list` used to print,
which reads as a changelog entry rather than a description of the test.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BGS51k25qzfeJEJ8dfxEEY

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the git clone --bare shape end to end against a local build — wt list, --branches, and --format json all read clean there, and the main_worktree_id: Option rework holds up (nothing flags a row as main, and main_worktree_path only reaches shorten_path, which branch-only rows never hit). Two inline notes, plus one doc line that sits outside the diff.

The PickerProgressHandler::on_collect_complete docstring in this file — search for Fired once before — is now wrong in both directions. It states the hook fires before every Ok(Some(_)) return, and lists "the zero-worktree Ok(None) return" as an exception to that. After this change the zero-worktree path returns Ok(Some(ListData { items: Vec::new(), .. })) and still doesn't fire the hook, so the stated rule no longer holds and the named exception no longer exists. Happy to push the correction if that's useful.

Comment thread src/commands/list/collect/mod.rs Resolved
Comment thread src/commands/list/collect/mod.rs Resolved
Dropping the empty-worktree early return brought `warn_stale_default` into a
shape it never used to reach: a bare repo with no branches at all.
`infer_default_branch_locally` resolves `symbolic-ref HEAD`, so
`default_branch()` answers `main` in a fresh `git init --bare -b main` even
though `refs/heads/main` doesn't exist, and the check reported it as externally
deleted. The hint's remedy looped — clearing the persisted value only let the
next run re-infer it from HEAD.

Gate the warning on a non-empty branch inventory, and pin the shape with a
fourth bare-repo test.

Also use color-print's `<<branch>>` escape for the literal angle brackets in
the hint, dropping the runtime placeholder binding, and correct the
`on_collect_complete` docstring: the empty listing now returns `Ok(Some(_))`
with no items, so neither its stated rule nor its named exception held.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XAUYWFN9d9oh6jyoQiouHb

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the increment. The <<branch>> escape and the on_collect_complete docstring both landed as described, and the new test_bare_repo_list_no_commits pins the shape it says it does (BareRepoTest::new() is git init --bare -b main with no commits, so the fixture matches the docstring).

One finding on the new gate, inline: warn_stale_default does double duty — it also drops the unresolvable default for downstream tasks — so gating it on a non-empty branch inventory silently keeps a nonexistent default in play on any repo with zero local branches. Reproduced against local builds of both commits; the bare-no-commits shape this PR targets isn't affected, but a detached-HEAD repo whose last branch was deleted is.

Comment thread src/commands/list/collect/mod.rs Resolved
`warn_stale_default` was doing two jobs: gating the warning, and gating the
drop that keeps downstream tasks off a branch that isn't there. Gating it on a
non-empty branch inventory suppressed both, so a repo with no local branches
carried the nonexistent default into the tasks that resolve against it — the
cascade the drop exists to prevent.

The bare-no-commits repo has no rows, so nothing fires there, but an empty
inventory isn't unique to it: a detached HEAD whose last branch was deleted has
one row and no branches, and `wt list` ended in three `fatal: Needed a single
revision` task failures.

Split the two decisions. `default_branch_missing` drives the drop;
`warn_stale_default` adds the non-empty-inventory condition and drives only the
message. `test_list_detached_with_no_branches_drops_stale_default` pins the
shape.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XAUYWFN9d9oh6jyoQiouHb

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at cfeceaf. The split lands as described, and I checked the new test isn't vacuous in either direction against a local build: pointing the drop back at warn_stale_default fails test_list_detached_with_no_branches_drops_stale_default with the three Needed a single revision failures, and removing the !all.is_empty() condition fails bare_repo_list_no_commits on the warning. default_branch_missing is now byte-identical to the base's warn_stale_default, so the drop reaches exactly what it reached before the PR and only the message is newly suppressed.

One finding on the empty-listing hint, inline — it isn't from this increment, but it's the shape the PR targets.

Comment thread src/commands/list/collect/mod.rs Resolved
`git clone --bare` is the shape that reaches the empty listing most often, and
it keeps its branches — so `wt switch --create <branch>` was the wrong command
to suggest: `--create` on a branch that already exists errors. The listing has
the answer it wasn't pointing at, since `wt switch <branch>` from there works.

A repo with branches now gets `wt list --branches` and `wt switch <branch>`; a
repo with none — the fresh `git init --bare` — keeps `--create`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XAUYWFN9d9oh6jyoQiouHb
@max-sixty
max-sixty merged commit 3e86e58 into main Sep 3, 2026
43 checks passed
@max-sixty
max-sixty deleted the land/bare-repo-empty-list branch September 3, 2026 01:10
max-sixty added a commit that referenced this pull request Sep 3, 2026
PR #3992's bare-repo and malformed-config listings picked up this branch's
header centring and right-aligned Age.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XAUYWFN9d9oh6jyoQiouHb
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.77.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes


### Improved

- **`wt list` sizes and aligns its columns to the terminal width**: one long branch name no longer sizes the Branch column for every row — it caps at 32 characters and elides, so a narrow terminal keeps its other columns instead of degenerating into a branch list. `Remote⇅` stops holding blank space open in a repo with no remote, and alignment now follows the value type. `--format=json` still carries the whole name. ([#3998](max-sixty/worktrunk#3998))

- **`wt list` names what it hid and marks detached worktrees**: the summary reads `hidden: Path, Commit` instead of counting columns, a detached worktree shows `⊘` rather than borrowing `⚑`, and a prunable row leaves its cells blank instead of showing loading dots that never resolve. ([#3998](max-sixty/worktrunk#3998))

- **`wt list --format=json` gains a `marker` field and stops reporting `detached` twice**: the branch marker set by `wt config state marker` is now readable without parsing it out of `symbols`, and `state` no longer reports a detached worktree as `branch_worktree_mismatch` — the sibling `detached` boolean carries it. ([#3998](max-sixty/worktrunk#3998))

- **`wt list --format=json` now defaults to schema 2**: callers get the envelope with repository metadata and orthogonal per-item facts without configuring `[list] json-schema`. `wt list statusline --format=json` follows the same key. Set `json-schema = 1` to retain the original bare-array format. (Breaking.) ([#4038](max-sixty/worktrunk#4038))

- **`wt config show` fails on a broken config**: it exits 1 on an unreadable or invalid config, an invalid `[list] columns`, or an invalid `approvals.toml`. Unknown keys and deprecations stay warnings and still exit 0. A new `APPROVALS` section counts project commands awaiting approval. (Breaking: it always exited 0 before.) ([#3999](max-sixty/worktrunk#3999))

- **Config migration output names its destination**: `wt config update --output <path>` writes the migration artifact to that file instead of applying it in place, and `--output=-` writes it to stdout. Output mode includes project config when run from a linked worktree. (Breaking: `--print` was removed.) ([#4021](max-sixty/worktrunk#4021))

- **Pi joins the agent integrations**: `wt config plugins pi install` writes an activity hook to `~/.omp/agent/hooks/pre/worktrunk.ts`, so Pi sessions show 🤖/💬 markers in `wt list` like Claude Code, Codex, OpenCode, and Gemini. `$PI_CONFIG_DIR`, `$PI_CODING_AGENT_DIR`, and named `$OMP_PROFILE`/`$PI_PROFILE` profiles are honored. [Docs](https://worktrunk.dev/claude-code/) ([#3594](max-sixty/worktrunk#3594), thanks @adity982, and @ortonomy for the request)

- **`wt config plugins codex install` installs the plugin too**: it previously registered the marketplace and left you to run `/plugins` in Codex yourself. Uninstall follows for both Codex and Claude Code, removing the plugin and then the marketplace, so the two commands are inverses. (Breaking: Codex uninstall previously left an installed plugin alone; Claude uninstall now also removes the marketplace.) ([#4019](max-sixty/worktrunk#4019))

- **`wt step copy-ignored` says whether it reflinked or copied**: the summary now reads `(reflinked, no extra disk)`, `(full copy)`, or a partial count, so the same `29.5 GB` line distinguishes a free copy from one that actually wrote the bytes. `--format=json` gains `reflinked` and `written`; a `--dry-run` plan no longer reports `files`/`bytes`. ([#4025](max-sixty/worktrunk#4025))

- **`wt config update` removes keys its destination cannot hold**: migrating `[select]` or `[commit-generation]` drops keys the new section has no field for, reporting each one. Otherwise the key landed at a path the user never typed and warned on every command, with no way to clear it. ([#3994](max-sixty/worktrunk#3994))

### Fixed

- **A failed `wt switch pr:<n>` against a fork no longer deletes a branch it didn't create**: the rollback force-deleted the branch on any setup error, including the one case where the branch wasn't its own — a `pre-switch` hook or a concurrent session claiming the name in the window after the forge answered. Branch and worktree are now created in one `git worktree add -b`, which writes nothing when the name is taken. ([#3984](max-sixty/worktrunk#3984))

- **Codex on Windows: the activity hooks no longer fail on every event**: each hook led with a bare `bash`, which `cmd.exe` resolves to the WSL launcher rather than Git Bash, so every event raised a `Hook failed` banner. Hooks now run `wt.sh` through a shim that finds Git Bash by path. ([#4008](max-sixty/worktrunk#4008), fixes [#4007](max-sixty/worktrunk#4007), thanks @McNultyyy for reporting and diagnosing)

- **Templates leave `branch` unset in a detached worktree**: aliases and hooks rendered `{{ branch }}` as the literal `HEAD`, which git resolves, so an unguarded template ran against the wrong ref — the reported case ended in `git push origin --delete HEAD`, which git refused. `base` and `target` follow. (Breaking: an unguarded `{{ branch }}` now errors.) ([#4010](max-sixty/worktrunk#4010), fixes [#4009](max-sixty/worktrunk#4009))

- **The OpenCode plugin loads under OpenCode 2**: OpenCode 2's loader dropped the old bare-function export silently, so activity markers stopped appearing. The plugin now exports one object carrying both the v2 `setup` and v1 `server` entry points, and spawns `wt` through `node:child_process` rather than the Bun shell. Re-run `wt config plugins opencode install` to pick it up; the one file covers OpenCode 2 and OpenCode 1.16 or later. ([#4018](max-sixty/worktrunk#4018), thanks @pragmaticivan for the request)

- **`wt step commit --branch` builds its prompt from the worktree being committed**: prompt-building git plumbing ran in the invoking worktree, so with nothing staged there the generated message described none of the changes it committed. `wt step relocate --commit` had the same bug, and `--dry-run`/`--show-prompt` now preview the worktree `--branch` names. ([#3996](max-sixty/worktrunk#3996))

- **LLM commit messages keep diffs for quoted paths**: a file whose name git quotes in the `diff --git` header — any non-ASCII name under the default `core.quotePath` — had its whole diff section dropped from the prompt once the diff exceeded the 100 KB budget. ([#4041](max-sixty/worktrunk#4041))

- **An unparsable user config is reported, not a panic**: `wt config show --format=json` and `--full`, plus `wt step prune`, `relocate`, `eval`, and `for-each`, panicked on a debug build and printed a bare `✗ Command failed` on a release one. They now report `✗ Failed to load config` with the parser's caret diagram. ([#4002](max-sixty/worktrunk#4002))

- **`wt switch --execute` names the directory the program actually starts in**: the `Executing (--execute) @ …` header rendered the worktree the background hooks run in, not the program's own directory — which differs under `--no-cd` or a switch from a subdirectory. The path is omitted when the shell already stands there. ([#4043](max-sixty/worktrunk#4043), fixes [#4042](max-sixty/worktrunk#4042), thanks @yajo for reporting)

- **`wt config plugins claude|codex uninstall` is safe to re-run**: removing an already-absent marketplace reported a failure, and a Claude uninstall that removed the plugin and then failed left the marketplace with no way to clear it. Both now finish a half-done uninstall and succeed when there is nothing left to remove. ([#4033](max-sixty/worktrunk#4033), [#4034](max-sixty/worktrunk#4034))

- **`wt config state marker` set and clear no-op outside a git repository**: they exited 1 with a git error, so an agent plugin running outside a repository printed one every turn (the hook's `|| true` kept the session going). ([#3981](max-sixty/worktrunk#3981), thanks @mahirhir)

- **`wt list` produces output in a bare repo with no worktrees**: it printed nothing at all and exited 0. It now reports `○ No worktrees` with a hint, `--branches` lists the branches, and `--format json` emits the envelope with an empty `items`. ([#3992](max-sixty/worktrunk#3992))

- **`wt list` warns when it can't parse the project config** rather than ignoring it silently; the listing still succeeds. ([#3993](max-sixty/worktrunk#3993))

- **Relayed command output no longer prints ahead of the delayed-stream progress line**, and delayed-stream output routes through anstream so color is stripped consistently when redirected. ([#4037](max-sixty/worktrunk#4037), [#3995](max-sixty/worktrunk#3995))

- **A hook filter that matches nothing names the unconfigured source**, rather than reporting no match without saying which source was empty. ([#3997](max-sixty/worktrunk#3997))

### Documentation

- **`wt hook` says that `post-*` hooks from the two sources run concurrently**, so dependent commands belong in one source; `wt merge` records that `post-commit` can't run when the merge removes the worktree it anchors on. ([#4020](max-sixty/worktrunk#4020), [#4026](max-sixty/worktrunk#4026))

- **`wt step` help pages describe what the commands actually do**: `wt step prune` says it removes br

See merge request: Harmonybrew/homebrew-core!18763
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants