worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

`wt list` loses every row's commit details when one worktree's HEAD object is missing

Open max-sixty opened this issue 2 weeks ago • 1 comments

When one worktree's HEAD names an object the repository doesn't have, wt list shows no Commit, Age or Message for any row, including the rows whose commits are intact. In --format=json, every item's head has "short_sha": "", "subject": null and "committed_at": null.

Reproduce

cd "$(mktemp -d)"
git init -q -b main repo
git -C repo commit -q --allow-empty -m first
git -C repo worktree add -q -b healthy ../repo.healthy
git -C repo worktree add -q --detach ../repo.bad
echo 1234567890123456789012345678901234567890 > repo/.git/worktrees/repo.bad/HEAD
wt -C repo list
wt -C repo list --format=json | jq -c '.items[] | {branch, head}'

Before the echo, all three rows show the commit first. After it, wt -C repo list prints:

▲ Failed to batch-fetch commit details: fatal: bad object 1234567890123456789012345678901234567890
  Branch   Status       @±        ^↕        ^…±     Remote⇅  Path             Commit   Age  Message
@ main         ^                                             .                           ·  ·
+          ·  ··         ·         ·         ·               ../repo.bad                 ·  ·
+ healthy      _                                             ../repo.healthy             ·  ·

○ Showing 3 worktrees
▲ 7 tasks failed:
  (detached): ahead/behind counts (fatal: Not a valid commit name 1234567890123456789012345678901234567890)
  (detached): trees-match check (fatal: Needed a single revision)
  (detached): ancestor check (fatal: Not a valid commit name 1234567890123456789012345678901234567890)
  (detached): branch diff (fatal: Not a valid commit name 1234567890123456789012345678901234567890)
  (detached): working-tree diff (fatal: bad object HEAD)
  (detached): merge-conflict check (fatal: bad object HEAD)
  (detached): working-tree conflict check (fatal: bad object HEAD)
↳ To create a diagnostic file, run with -vv

The JSON items are:

{"branch":"main","head":{"sha":"bb994bc240f50a27d2b1800c5d5df1630a4521c4","short_sha":"","subject":null,"committed_at":null}}
{"branch":null,"head":{"sha":"1234567890123456789012345678901234567890","short_sha":"","subject":null,"committed_at":null}}
{"branch":"healthy","head":{"sha":"bb994bc240f50a27d2b1800c5d5df1630a4521c4","short_sha":"","subject":null,"committed_at":null}}

Expected

The main and healthy rows keep their Commit, Age and Message, and only the row whose HEAD can't be read goes without them.

In JSON, a short_sha that wasn't determined is null, like the subject and committed_at beside it. wt list --help describes short_sha as the abbreviated SHA and defines null as "requested but not determined". "" is neither.

Cause and a possible fix

commit_details_many fetches the details for every row with one git log --no-walk <sha>… call, and git refuses the whole call when one SHA names a missing object. Its doc comment and the test commit_details_many_fails_loudly_on_unknown_sha record that as intended. The caller is meant to warn rather than fall back to a fetch per SHA, so that empty cells never appear without an explanation.

git log --no-walk --ignore-missing keeps the single call. Given a readable SHA, a missing one and the null OID, it prints the readable commit and exits 0 (checked on git 2.44). wt list could then warn about each SHA that it asked for and git didn't return, which keeps the explanation and limits the empty cells to the broken row. The filter that drops an unborn branch's null OID before the call would no longer be needed.

Seen on worktrunk wt v0.82.0.

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

max-sixty avatar Nov 20 '26 02:11 max-sixty

Fix is up in #4852 and its CI is green, codecov/patch included. It is waiting for a maintainer to merge.

It takes the --ignore-missing route you suggested. One git log --no-walk call still fetches every row, and git now leaves out an absent object instead of refusing the whole call. wt list warns once for each SHA it asked for and didn't get back, so on your reproduction main and healthy keep first with their SHA and age, and only repo.bad is blank. In schema-2 JSON, head.short_sha is now null when it couldn't be determined, matching subject and committed_at. The help table and the generated schema say so too.

Two places where the fix goes beyond what you proposed:

  • --ignore-missing doesn't skip a corrupt loose object (git still exits 128), so the existing "Failed to batch-fetch commit details" warning can still happen. A new test covers that path.
  • The null-OID filter stays. git would accept the null OID under --ignore-missing, but the filter is what keeps unborn branches out of the new missing-commit warning.

worktrunk-bot avatar Nov 20 '26 08:11 worktrunk-bot