Skip to content

worktree-audit: read git refs by full name and hold a branch's open PR (2.2.8) - #70

Merged
chhoumann merged 6 commits into
mainfrom
fix/worktree-audit-refs
Nov 7, 2026
Merged

chhoumann merged 6 commits into
mainfrom
fix/worktree-audit-refs

Conversation

@chhoumann

@chhoumann chhoumann commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Why

The worktree audit should never call a worktree safe to prune while it holds unmerged work or an open PR. Two lookups let it. A local branch or tag named origin/main won git's short-name lookup over refs/remotes/origin/main, so the MERGED check read unmerged work as merged. And gh lists a branch's PRs newest first, so a newer closed or merged PR hid an older open one. Both were found and fixed in Michael Denyer's pstack-claude, #423 and #424, in its JavaScript audit. This makes the same fixes in our bash fork.

What changed

  • worktree-audit.sh reads a base that starts with a remote's name, and origin/<branch> in the REMOTE column, by their refs/remotes/ names. A -b that names a local ref, such as -b main, works as before. The branch name comes from the full refs/heads/ ref, so a tag with the same name no longer hides the branch's PR.
  • For each branch it takes the first PR record whose state is open or draft, else the first record, on both the gh and the Origin path.
  • Seven tests in tests/worktree-audit.test.mjs, six of which fail on main. Release 2.2.8 with the fork's why, CHANGES.md, the stamped manifests, and the README's tag example.

Scope

  • The review found the -b upstream/main case and the tag named like the branch. Both are the same short-name lookup, so they are fixed here. The REMOTE fix does not change the bucket.
  • Not fixed: the audit asks for at most 1,000 PRs, so an open PR older than the author's 1,000 newest in the repo goes unread. It needs a second query.
  • Lauren's upstream script has all three lookups. Proposing the fix there is a follow-up.

Verification

  • Repro with the real script in a throwaway repo, one unpushed commit on worktree branch topic. On main, git branch origin/main topic or git tag origin/main topic turns the row from no review into YES safe, also with -b origin/main. With this branch it stays no review. A real merge with a stale origin/main tag still reads YES safe.
  • Repro with a stub gh on PATH listing #12 closed then #11 open for topic, and the same records from a stub Origin CLI. On main the row reads #12/closed safe. With this branch it reads #11/open hold-open-pr on both paths.
  • bun tools/generate.mjs --check, GIT_CONFIG_GLOBAL=/dev/null bun test tests/ --timeout 30000 (561 pass, 0 fail), the sync dry-run for each component at c742dd6, shellcheck on the script, and markdownlint on the changed Markdown all pass.
  • Review by codex/gpt-6-astra at reasoningEffort=xhigh found three high issues. Two are fixed above with tests that failed first. The third is the PR limit in Scope.

Note

Low Risk
Bash audit tooling only; changes make prune recommendations more conservative and are covered by new tests, with no auth or runtime workflow impact.

Overview
Release 2.2.8 fixes three cases where worktree-audit.sh could mark a worktree safe while it still had unmerged work or an open PR.

The merge and remote columns now resolve bases like origin/main and origin/<branch> through explicit refs/remotes/ names so a local branch or tag with the same shorthand no longer wins over the remote-tracking ref. Branch names for PR lookup come from the full refs/heads/ name so a tag with the same name cannot blank the PR column. When PRs are listed newest-first, the script picks the first open or draft record for the branch instead of the newest row overall.

Seven tests in tests/worktree-audit.test.mjs cover these scenarios; version stamps and changelog/README examples move to 2.2.8.

Reviewed by Cursor Bugbot for commit e5ad5c7. Bugbot is set up for automated code reviews on this repo. Configure here.

…ad as safe

A local branch or tag named origin/main makes unmerged work read MERGED and
safe, and one named origin/<branch> makes an unpushed commit read pushed. A
newer closed or merged PR listed before an older open one buckets the worktree
safe. These tests fail on 2.2.7.
… open PR

A local branch or tag named origin/main won git's shorthand lookup over
refs/remotes/origin/main, so the MERGED check could read unmerged work as
merged and safe. An origin/* base and origin/<branch> are now read by their
refs/remotes/ names. A -b that names a local ref works as before.

gh and Origin list a branch's PRs newest first, and the audit took the first,
so a newer closed or merged PR hid an older open one and the worktree read
safe. The audit now takes the first open or draft record, else the first.

Same fixes as Michael Denyer's pstack-claude #423 and #424.
… the branch

A local ref named upstream/main still decides -b upstream/main, and an
origin/HEAD that points at refs/remotes/upstream/main reaches the same short
name. A tag named like the worktree's branch makes symbolic-ref --short print
heads/<branch>, so no PR matches and an open PR reads safe.
A local ref named upstream/main still decided -b upstream/main. A base that
starts with a configured remote's name is now read under refs/remotes/. The
branch name comes from symbolic-ref without --short, which prints heads/<name>
when a tag shares the name, so a tag no longer hides the branch's PR.
@chhoumann chhoumann changed the title worktree-audit: read origin refs by full name and hold a branch's open PR (2.2.8) worktree-audit: read git refs by full name and hold a branch's open PR (2.2.8) Nov 7, 2026
@chhoumann
chhoumann marked this pull request as ready for review November 7, 2026 22:05
@chhoumann
chhoumann merged commit f344cb6 into main Nov 7, 2026
12 checks passed
@chhoumann
chhoumann deleted the fix/worktree-audit-refs branch November 7, 2026 22:23
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.

1 participant