Repository navigation
fix(list, prune): degrade gracefully on unborn worktrees - #2937
Conversation
A linked worktree on an unborn branch (`git worktree add --orphan`) reports `HEAD 0000…` in `worktree list --porcelain`. Two paths then fail: - `wt list`: `WorkingTreeDiff` runs `git diff HEAD` and `WorkingTreeConflicts` runs `git merge-tree` against the null OID, surfacing `fatal: ambiguous argument 'HEAD'` and `fatal: 0000… is not a valid object`. Added both tasks to `COMMIT_TASKS` so they're skipped for `!has_commits()` worktrees, matching how the other commit-dependent columns degrade. - `wt step prune`: `integration_reason` calls `git rev-parse --verify <branch>` against the unborn branch and aborts the whole scan with `fatal: Needed a single revision`. Skip unborn worktrees in `gather_check_items` — they have no commits to integrate. Updates `test_list_shows_warning_on_git_error` and the diagnostic `corrupt_worktree_head` helper to use a non-null invalid SHA so the warning paths they exercise are not silenced by the new skip. Closes #2936 Co-Authored-By: Claude <[email protected]>
|
what is an unborn branch?! do we need to handle them elsewhere? are there any other git intricacies we should be aware of, like this? |
|
What is an unborn branch? A branch that has been named but has no commits yet: Do we need to handle them elsewhere? The codebase already has a fair bit of unborn-aware plumbing — I don't think the targeted commands ( Are there other git intricacies like this? Yes — there's a family of "weird worktree states" worth being aware of. Most are already handled, but they share the same lesson: iteration commands need per-row degradation, not whole-scan failure.
The throughline for the iteration commands ( |
v0.55.0. `cargo semver-checks` reports breaking library API changes (9 inherent methods removed from `Repository` / `ShellConfig` by the dead-code cut-overs in #2931 — `is_ancestor`, `same_commit`, `has_added_changes`, `trees_match`, `head_tree_matches_branch`, `has_merge_conflicts`, `has_merge_conflicts_by_tree`, `merge_integration_probe`, `is_posix`). None are intentional public API, but they force a minor bump pre-1.0. Headline user-visible changes: - `wt switch` accepts forge PR/MR URLs anywhere `pr:N` / `mr:N` works (#2898, thanks @thiagowfx for the request). - Claude Code plugin keeps unmerged branches during worktree cleanup — the `WorktreeRemove` hook drops `-D` (#2940, thanks @jbeda for reporting). - `wt list` and `wt step prune` degrade gracefully on unborn worktrees (#2937, thanks @nedtwigg for reporting). - `-vv` startup pointer now names `diagnostic.md` (#2919). - Doc-site and `--help` prose cleanup (#2922, #2925); internal cut-over of duplicated/dead code paths (#2931, #2932, #2934). Full CHANGELOG entry in this PR. > _This was written by Claude Code on behalf of max_
worktrunk 0.55.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 switch` accepts forge PR/MR URLs**: `wt switch https://github.com/owner/repo/pull/123` now resolves the same way as `wt switch pr:123`, and the URL form works anywhere a `pr:N` / `mr:N` shortcut does (positional argument and `--base`). Detection is shape-based, not host-based — any `http(s)://` URL whose path contains `/pull/N`, `/pulls/N`, `/-/merge_requests/N`, or `/pullrequest/N` matches, covering GitHub (including Enterprise), GitLab, Gitea, and Azure DevOps, including self-hosted instances. ([#2898](max-sixty/worktrunk#2898), thanks @thiagowfx for the request) - **`-vv` startup pointer names `diagnostic.md`**: The `-vv` pointer now lists the shared log directory once with all three files it will contain — `trace.log`, `subprocess.log`, and `diagnostic.md` — so the diagnostic bundle is discoverable at startup rather than only when the gist hint fires at exit. The pointer verb reads `Writing to …` instead of `Tracing to …`. ([#2919](max-sixty/worktrunk#2919)) ### Fixed - **Claude Code plugin keeps unmerged branches during worktree cleanup**: The plugin's `WorktreeRemove` hook passed `-D` (`--force-delete`) to `wt remove`, which removes a branch even when it carries commits that aren't merged or pushed. The hook now uses the default removal: a merged or integrated branch is removed cleanly, while one with unmerged commits is kept, with a `wt remove -D <branch>` hint for deleting it deliberately. ([#2940](max-sixty/worktrunk#2940), thanks @jbeda for reporting) - **`wt list` and `wt step prune` degrade gracefully on unborn worktrees**: A linked worktree created with `git worktree add --orphan` sits on an unborn branch whose `HEAD` is the null OID. `wt list` used to show `working-tree-diff (fatal: ambiguous argument 'HEAD')` and a merge-tree error in its columns, and `wt step prune` aborted its entire scan with `fatal: Needed a single revision`, blocking pruning of every other worktree. Both now treat an unborn worktree as having no commits: `wt list` renders `·` for the commit-dependent columns, and `wt step prune` skips it (as it does locked worktrees) and continues. ([#2937](max-sixty/worktrunk#2937), thanks @nedtwigg for reporting) ### Documentation - **Doc-site and `--help` prose cleanup**: A writing-prose pass across the FAQ, config, list, remove, Claude Code, hook, LLM-commits, and Tips & Patterns pages (some via `--help` text in `after_long_help`). ([#2922](max-sixty/worktrunk#2922), [#2925](max-sixty/worktrunk#2925)) ### Internal - **Collapsed duplicated code paths and removed dead code left by completed cut-overs**: A net reduction across the shell, git, and command layers. ([#2931](max-sixty/worktrunk#2931), [#2932](max-sixty/worktrunk#2932), [#2934](max-sixty/worktrunk#2934)) ## Install worktrunk 0.55.0 ### Install prebuilt binaries via shell script ```sh curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-installer.sh | sh && wt config shell install ``` ### Install prebuilt binaries via powershell script ```sh powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-installer.ps1 | iex"; git-wt config shell install ``` ### Install prebuilt binaries via Homebrew ```sh brew install worktrunk && wt config shell install ``` ## Download worktrunk 0.55.0 | File | Platform | Checksum | |--------|----------|----------| | [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) | | [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-x86_64-apple-darwin.tar.xz.sha256) | | [worktrunk-x86_64-pc-windows-msvc.zip](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-x86_64-pc-windows-msvc.zip.sha256) | | [worktrunk-aarch64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-aarch64-unknown-linux-musl.tar.xz.sha256) | | [worktrunk-x86_64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.55.0/worktrunk-x86_64-unknown-linux-musl.tar.xz.sha256) | ### Install via Cargo ```sh cargo install worktrunk && wt config shell install ``` ### Install via Winget (Windows) ```sh winget install max-sixty.worktrunk && git-wt config shell install ``` ### Install via AUR (Arch Linux) ```sh paru worktrunk-bin && wt config shell install ``` </pre> <p>View the full release notes at <a href="https://github.com/max-sixty/worktrunk/releases/tag/v0.55.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.55.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!9819
Problem
git worktree add --orphancreates a linked worktree on an unborn branch —worktree list --porcelainreports itsHEADas the null OID. Two paths then fail:wt listshowsworking-tree-diff (fatal: ambiguous argument 'HEAD')andworking-tree-conflicts (fatal: 0000… is not a valid object)because the diff and merge-tree probes try to resolve HEAD / treat the null OID as a commit.wt step pruneaborts the entire scan withfatal: Needed a single revisionbecauseintegration_reasonrunsgit rev-parse --verify <unborn-branch>, blocking pruning of any other worktrees in the repo.Solution
src/commands/list/collect/execution.rs: addWorkingTreeDiffandWorkingTreeConflictstoCOMMIT_TASKS. Both seed defaults (NoneandSome(None)) already exist and render as·, matching how the other commit-dependent columns degrade for unborn worktrees.src/commands/step/prune.rs: skip!wt.has_commits()worktrees ingather_check_items— they can't be integrated and aren't auto-prune candidates. Mirrors the existing skip for locked worktrees.Two existing tests (
test_list_shows_warning_on_git_errorand the diagnosticcorrupt_worktree_headhelper) used to write0000…into a ref/HEAD file and rely on the resulting error warnings. After the fix those inputs read as unborn and skip silently, so both are updated to use0000…001— a non-null invalid SHA that still exercises the warning surfacing they were written to test.Testing
test_list_unborn_worktree_no_task_failures— fails onmain, passes after the list fix.test_prune_skips_unborn_worktree— fails onmainwithNeeded a single revision, passes after the prune fix and leaves the unborn worktree in place while still pruning the merged sibling.cargo test --test integrationclean (skipping pre-existing nushell flakes wherenuisn't installed in this runner).cargo clippy --all-targets -- -D warningsclean;cargo fmt --checkclean.Closes #2936 — automated triage