Skip to content

docs: Add GitHub squash merge analogy to wt merge - #42

Merged
max-sixty merged 3 commits into
mainfrom
claude/improve-wt-merge-docs-01UR5KE9CRzxZEWYjVMVjnww
Nov 24, 2025
Merged

max-sixty merged 3 commits into
mainfrom
claude/improve-wt-merge-docs-01UR5KE9CRzxZEWYjVMVjnww

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Update both the help text and README to clarify that wt merge's squash
behavior is like GitHub's "Squash and merge" button. This helps users
quickly understand what the command does by drawing on their existing
familiarity with GitHub's merge workflows.

Changes:

  • Updated Squash section in wt merge --help
  • Updated corresponding README section
  • Updated snapshot test

Update both the help text and README to clarify that wt merge's squash
behavior is like GitHub's "Squash and merge" button. This helps users
quickly understand what the command does by drawing on their existing
familiarity with GitHub's merge workflows.

Changes:
- Updated Squash section in wt merge --help
- Updated corresponding README section
- Updated snapshot test
Move "with LLM-generated commit message" to the end of the sentence for
better flow and clarity. The GitHub analogy now sits in the middle,
providing context before the implementation detail.

Before: "...squashed into one with LLM message (like GitHub's...)"
After: "...squashed into one (like GitHub's...) with LLM-generated commit message"

This follows the pattern: [action] → [analogy] → [detail]
Use consistent terminology throughout the codebase and documentation:
- "with LLM message" → "with LLM commit message"
- "with LLM-generated commit message" → "with LLM commit message"
- "with LLM-generated messages" → "with LLM commit messages"

This makes the terminology clearer and more consistent across all help
text, documentation, and code comments.

Files updated:
- src/cli.rs: Merge and step command help text
- README.md: All references to LLM message generation
- tests/: Updated comments for consistency
- Snapshot tests updated
@max-sixty
max-sixty merged commit 3726913 into main Nov 24, 2025
@max-sixty
max-sixty deleted the claude/improve-wt-merge-docs-01UR5KE9CRzxZEWYjVMVjnww branch November 24, 2025 17:22
max-sixty added a commit that referenced this pull request Jun 28, 2026
## The bug

In the `wt switch --prs` interactive picker, removing a worktree row
with `alt-x` made the streamed PR/MR rows vanish from the list until the
user pressed `alt-r` to refresh. The worktree/branch rows survived; only
the `--prs` rows disappeared.

## Root cause

The `alt-x` removal rework (`d66bc6af5`) replaced the old `reload(remove
{})` with a synchronous `resync_pool` that rebuilds skim's item pool
from the picker's `shared_items` Vec. But `shared_items` only ever held
the skeleton (worktree/branch) rows: `on_skeleton` populates it, while
the `--prs` thread streams its rows straight to skim's item channel
(`prs::fetch_and_stream` → `tx.send`) and never recorded them in
`shared_items`. So when `resync_pool` rebuilt the pool from
`shared_items`, the PR rows were dropped. They only reappeared when
`alt-r` re-ran the whole collect + `--prs` pipeline. (The old `reload`
path had the same blind spot; it matters more now that `alt-x` is the
sole removal path.)

## The fix

The `--prs` thread now appends its PR/MR rows into `shared_items` as
well as streaming them to skim — the same way it already extends
`shortcut_table`. With `shared_items` holding the full row set (header +
worktree/branch + PR/MR rows), `resync_pool` preserves the PR rows on an
`alt-x` removal for free.

The append is guarded by a per-spawn epoch counter
(`PipelineFactory::prs_epoch`, handed to each spawn's `--prs` thread via
`PrsShared`). An `alt-r` refresh spawns a fresh `--prs` thread while the
prior spawn's forge call may still be in flight; without the guard, that
stale call (whose skim channel is already dropped) would re-add
now-duplicate rows to the list a newer spawn rebuilt. The epoch is read
under the `shared_items` lock so the check pairs with the next spawn's
`on_skeleton` overwrite, which holds the same lock. The append is
ordered before `tx.send` so the rows reach `shared_items` no later than
they reach skim's pool (favoring a sub-microsecond transient-duplicate
window over re-dropping rows, were the order reversed).

The no-flash cursor behavior from `d66bc6af5` is unchanged: the rebuilt
list is just longer, so the cursor holds its index and the row that
slides into the removed slot lands under it.

## Testing

New PTY regression test
`test_switch_picker_prs_rows_survive_alt_x_removal` drives the drop path
(a clean, integrated worktree) in `--prs` mode and asserts the `#42` PR
row survives the removal. The mock answers `gh pr list --state` (the
`--prs` fetch) with PR #42 but `gh pr list --head <branch>` (the
per-worktree CI fetch) with an empty list, so `#42` appears only as a
`--prs` row, never folded into a worktree row's CI cell. Confirmed: the
test fails without the fix and passes with it. Full pre-merge gate green
(4257 tests).

> _This was written by Claude Code on behalf of max_

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
max-sixty pushed a commit that referenced this pull request Jul 25, 2026
#3532)

## Problem

`test_switch_picker_prs_shows_loading_marker` intermittently times out
on `test (windows)` — it flaked on #3531 (a docs-only change), which is
what prompted this fix.

The test asserts a *transient* frame: while a mocked, delayed `gh pr
list` is in flight, the picker header shows `↳ Loading open PRs…` and
the `#42` row has not yet streamed in. The mock held that loading state
for a fixed time (originally 3s). On a loaded Windows runner, the PTY
boot sequence — `boot_picker_pty`'s skim-ready wait plus its initial
`wait_for_stable`, together with the async worktree-column churn (`·`
placeholders resolving) — can consume that whole window. By the time the
stabilization helper first polls for `Loading open PRs`, the mocked
fetch has already returned and the rows have streamed in, so the marker
is gone and the wait times out at `STABILIZE_TIMEOUT` (30s).

## Fix

Per review feedback
([comment](#3532 (comment))),
tie the marker's lifetime to the picker's, with **no timing number at
all** — the file's "poll, don't pick a time" rule applied to the
producer side.

`mock-stub` gains a `hold_until_parent_exit` response mode: the mocked
`gh pr list` holds until `wt` exits instead of sleeping a fixed
`delay_ms`. Detection needs no platform primitive (`getppid` /
`OpenProcess`):

- While `wt` lives, its `--prs` fetch thread runs the mock with a piped
stdout and blocks reading that pipe to EOF, so as long as the mock
neither writes a full response nor exits, the loading marker stays.
- When the picker aborts, `wt` detaches the fetch thread
(`drop(prs_handle)`) and exits, which closes the read end of the mock's
stdout pipe. The mock's next write then fails with `BrokenPipe` (Rust
ignores `SIGPIPE`, so the broken write surfaces as an `Err` rather than
killing the process), and the mock exits.

Polling for that write error is a **causal** parent-death signal —
release is tied to `wt` exiting, not to a timer — and it behaves
identically on Unix and Windows, so there's no platform-specific FFI to
get right. The one-byte probes written into stdout are never observed
(this mode's contract is that the parent aborts without parsing the
response, and the fetch thread drains the pipe until process exit). A
60s poll cap bounds a stuck orphan if the pipe somehow never breaks.

This removes the race the earlier 30s bump only widened: the marker is
present for the entire window the poll could observe it, on any boot
latency, and no orphaned sleeper is left behind — the mock exits the
moment the picker does.

## Testing

`cargo test --test integration --features shell-integration-tests
test_switch_picker_prs_shows_loading_marker` passes in ~1.3s, confirming
the capture-and-abort path stays fast and the mock releases promptly on
`wt` exit. The sibling `--prs` tests
(`test_switch_picker_prs_{github,gitlab}_list`,
`..._rows_survive_alt_x_removal`) still pass through the refactored
`mock_forge_env` helper. Reasoning is documented inline at the mock-stub
call site and in `wait_for_parent_exit`.

---------

Co-authored-by: worktrunk-bot <[email protected]>
max-sixty added a commit that referenced this pull request Sep 2, 2026
## The bug

`wt switch pr:N` / `mr:N` against a **fork** PR/MR took the
`CreationMethod::ForkRef`
path, which built the branch, its tracking config, and its worktree as
four separate
git calls and compensated for that decomposition on any error:

```rust
if let Err(e) = setup_result {
    // Cleanup: try to delete the branch if it was created
    let _ = repo.run_command(&["branch", "-D", "--", &branch]);
    return Err(e);
}
```

The rollback was only ever valid if the *first* call — `git branch --
<b> FETCH_HEAD` —
had succeeded. Its likeliest failure is git refusing a name that is
already taken, and
in that case `wt` force-deleted a branch it had not created, discarding
the result of
the deletion.

## The reachability window

The branch name comes from the PR's head ref. Whether it is free is
decided in
`resolve_fork_ref`, which runs during `resolve_ref_shortcut_target` —
**before** the
`pre-switch` hooks and before `plan_switch`. The branch is created
later, inside
`execute_switch`. Anything that claims the name in between selects the
fork path and
then fails it: a `pre-switch` hook, or another session in another
worktree of the same
repo.

When that happened, `git branch -D` dropped the branch, and with it any
commits only
that branch held — the reflog goes too, so recovery is `git fsck
--lost-found`. The
error printed immediately *afterwards* was:

```
✗ Failed to create local branch feature-fix from PR #42
  fatal: a branch named 'feature-fix' already exists
```

which reads as though nothing happened, and the obvious response —
re-run — succeeds
the second time, erasing the evidence.

## The fix: remove the rollback, don't guard it

The rollback existed only to compensate for a decomposition that
shouldn't exist. The
sibling `CreationMethod::Regular` arm already builds a single
`git worktree add -b <branch> -- <path> <ref>` and has no rollback at
all, because git
owns the atomicity. `ForkRef` now uses the same shape:

```
git worktree add -b <branch> -- <path> FETCH_HEAD
```

Git writes nothing when the name is taken (verified: the branch keeps
its SHA and no
directory is left behind), so on the one failure that lands on a branch
`wt` did not
create there is nothing to roll back. Guarding the delete with "only if
we created it"
would have kept a destructive path alive to fix a case where the
destructive path was
never needed.

This is not a claim that `git worktree add -b` is atomic in general —
with the
destination path occupied it creates the branch and *then* dies on the
path (verified on
git 2.55). That leftover is a stray branch at the PR head, which the
`Regular` arm
already accepts, and it is not someone's work. It does carry the same
follow-on cost as
a failed tracking write below — no config written, so the next `wt
switch pr:N` takes
the prefixed-branch path or errors — and the docstring now says so in
both places. The
old code rolled back cleanly in this one case, its own branch being the
only thing it
could have deleted, but distinguishing it needs the very
did-we-create-it reasoning that
produced the bug.

Tracking config (`branch.<b>.remote` / `.merge` / `.pushRemote`) now
follows the
worktree instead of preceding it, and the ordering is load-bearing:
writing tracking
first would rewrite the *existing* branch's upstream on exactly the
collision above —
the same class of bug as the rollback. If a tracking write fails, the
user is left with
a branch plus worktree at the PR head and incomplete config. Nothing is
lost, and a
re-run is non-destructive: `branch_tracks_ref` reads the branch as
tracking something
else, so the next `wt switch pr:N` takes the prefixed-branch path
(GitHub/Gitea) or
reports `BranchTracksDifferentRef` (GitLab/Azure DevOps). That is
strictly better than
deleting their branch. This matches the repo's stated rules: *prefer
failure over silent
loss*, *no implicit destructive side effects*, and one canonical path
for worktree
creation.

`branch.autoSetupMerge` is inert on this path — git sets up tracking
only where the
start point resolves under `refs/heads/` or `refs/remotes/`, and
`FETCH_HEAD` resolves
as itself, so no value of it (`true`, `always`, `inherit`, `simple`,
`false`) writes
tracking config here. The `-c branch.autoSetupMerge=simple` the
`Regular` arm needs
would be redundant.
`git worktree add -b` also has a known DWIM footgun where a bare
remote-only start point
creates the remote's branch name instead of `-b`'s; `FETCH_HEAD` is not
a
remote-tracking ref, and the new test covers the case rather than
assuming it.

## Test

`test_switch_pr_fork_failure_keeps_existing_branch` pins the safety
property: **a
pre-existing branch survives a failed `pr:N` switch.** It uses the
existing mock-`gh`
fork-PR fixture, plus a `pre-switch` hook that renames a never-pushed
local branch onto
the PR's branch name — occupying it after the forge answered (which is
what selects the
fork path) and before the worktree is created, standing in for the
concurrent session
that does the same in real use. The test then asserts the switch failed
*and* that
`refs/heads/feature-fix` still points at the unpushed commit.

Against the old code it fails at exactly that assertion, with the branch
gone.

## The same failure mapping as `Regular`

Creating the branch with `git worktree add -b` means the fork path now
hits the one
failure the `Regular` arm already translates: git stores refs as file
paths, so a fork
PR whose head ref is `feature-fix` can't create a branch in a repo that
already has
`feature-fix/nested`, and git says `fatal: cannot lock ref
'refs/heads/feature-fix'`.
The arm routes that through `detect_branch_namespace_conflict`, exactly
as `Regular`
does, so the user is told which local branch is in the way. It matters
more here than
there: a PR's head ref isn't the user's to rename, so the only
actionable move is to
rename the local branch, and the raw git text doesn't name it.

`test_switch_pr_fork_namespace_conflict` covers it — same mock-`gh`
fixture, with
`feature-fix/nested` created before the switch. It asserts
`BranchNamespaceConflict`'s own wording, `collides with existing
branch`, rather than
just the conflicting branch name: git's raw `cannot lock ref` text names
that branch
too, so the looser assertion passed against the unmapped error. Verified
by reverting
the mapping — the test fails.

## Validation

- `cargo run -- hook pre-merge --yes` — 4,715 tests passed, 1 skipped;
clippy, fmt,
  doc-sync, snapshot and lockfile checks green
- No help text or `after_long_help` changed, so no doc regeneration was
needed
- The FAQ's ["What can Worktrunk
delete?"](https://github.com/max-sixty/worktrunk/blob/main/docs/src/content/docs/faq.md)
never listed this `branch -D`, so no doc update is
needed — and its absence is more evidence the deletion was never
intended behaviour

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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