Repository navigation
Conversation
…ranch `wt step squash` and `wt merge`'s squash step ran `git reset --soft <merge-base>` and then `git commit`. When the commit failed (a `pre-commit` hook rejecting it, a broken signing setup), the branch was left rewound to the merge base with its commits collapsed into staged changes. The squash now rewrites history the way `git rebase` does: it detaches HEAD onto the merge base with `update-ref --no-deref`, which leaves the branch, the index and the working tree untouched, commits there, then moves the branch to the new commit with one compare-and-swap `update-ref` and puts HEAD back on it. The branch keeps its commits until the commit exists, so a rejected or failed commit leaves it exactly as it was; the reattach restores HEAD. Committing through `git commit` rather than plumbing keeps git's own hooks, `commit.cleanup`, signing and identity resolution behaving as they do for any other commit — those hooks see a detached HEAD, as they do under `git rebase`. ORIG_HEAD still records the pre-squash tip, as `git reset` left it. The no-net-changes check compares the index tree against the merge base's tree instead of asking `git diff --cached`, so a squash whose only change is a submodule pointer hidden by `submodule.<name>.ignore` is committed rather than reported as empty. That path still leaves the branch at the merge base. `signs_commits` now asks git from the current worktree instead of reading the cached config map, which is read from the common dir and so missed worktree-scoped config, and which read a valueless `gpgsign` as false where git reads it as true. `wt merge --no-ff` builds its merge commit with `commit-tree` and asks this helper whether to sign it. The failure mode was found in #4193. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The squash detaches HEAD to build its commit, and every path that puts HEAD back now reports the same recovery line when that fails — including the one after a successful squash, which said only that it had failed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Two things worth a decision before this merges.
The ORIG_HEAD write can report a squash that landed as a failure. move_branch writes ORIG_HEAD after the compare-and-swap that moves the branch, and both errors return through the same path. If the branch update succeeds and the ORIG_HEAD write then fails — a ref lock held by something else in the worktree, ENOSPC, a read-only object store — handle_squash returns Err with the branch already at the squash commit and HEAD reattached to it. wt step squash exits non-zero on a squash that landed, and wt merge aborts before the rebase with the branch already rewritten. The same line reaches the no-net-changes path, where the branch has already been rewound to the merge base when the error goes out. That also makes reattach_after_failure's docstring wrong for this call site: "The branch never moved, so a successful reattach restores the worktree exactly as it was" holds for the commit failure above it, not for a move_branch error raised after the swap. Inline suggestion below makes the ORIG_HEAD write best-effort, which keeps the PR's own invariant in both directions — nothing written when the squash doesn't land, and a cosmetic write failure doesn't mask one that did.
codecov/patch is red at 92.85% against a base project coverage of 98.32%, so it needs the maintainer call the root CLAUDE.md → Coverage requires. Five lines are missed:
| Line | Path |
|---|---|
src/git/repository/mod.rs:1749 |
signs_commits's non-0/non-1 exit arm |
src/commands/step/squash.rs:376 |
the move_branch failure arm after the commit |
src/commands/step/squash.rs:406, :409, :425 |
reattach_head's context closure and reattach_after_failure's Err arm |
Two of them have deterministic triggers and are worth covering on their own merits, since both pin safety properties this PR introduces rather than just moving the number: commit.gpgSign = maybe makes git config --type=bool --get exit 128, which drives mod.rs:1749 straight from the new unit test; and a .git/hooks/pre-commit that runs git update-ref refs/heads/feature <other-sha> moves the branch inside the detached window, which is the only way to show the compare-and-swap actually refuses. That still leaves reattach_head failing with no deterministic trigger, so the patch would come to 95.71% (67/70) — under target either way.
One smaller thing: the replaced code carried a note that an external process could modify the index between the state mutation and the commit, and why that was accepted. The new sequence has the same window — write-tree snapshots the index for the emptiness check, then git commit re-reads it — but the comment block above it only speaks to the branch race the compare-and-swap covers. Worth carrying the index-race note across so the next reader doesn't re-derive it.
…ure paths The branch has already moved by the time ORIG_HEAD is written, so failing there reported a squash that landed as an error. `git reset` makes the same write best-effort — it exits 0 and silently skips ORIG_HEAD when it cannot be written — so this does too. Tests cover the paths the change introduced: a `commit.gpgSign` value git cannot read as a boolean, a branch moved by a concurrent writer while the squash commit is being made, and a reattach that cannot write HEAD. The TOCTOU note on the index window is back, rewritten for the new sequence. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Both inline fixes read as claimed: Required checks passed on that head ( |
Bumps 0.79.0 → 0.80.0 and adds the `## 0.80.0` changelog section, cut from `12efb5159`. The bump is minor because the library API breaks (see Verification). ## Verification - `cargo run -- hook pre-merge --yes` on the cut tip: 4985 passed. - `nightly.yaml` on `12efb5159`, all jobs green including feature-powerset: https://github.com/max-sixty/worktrunk/actions/runs/36338233859 - `cargo semver-checks check-release -p worktrunk` reports five major-level lints, the removals and signature changes listed in the Internal entry. - Changelog: repeated verification passes against source until one came back clean. Fixed headlines name the condition a bug needed rather than its worst case, and near-zero-reach fixes are folded into two roll-up bullets, per #4295. - Data-loss surface review over `v0.79.0..HEAD` with independent finders. The one real finding, a nested stale detached worktree read as the enclosing repo's rebase so `wt step prune` could unregister it, was fixed in #4302. The review also found a squash regression in the backup path, fixed in #4303. The remaining candidates were adjudicated acceptable and signed off: #4228 unregistering stale worktrees whose directory remains (files stay on disk; the branch is deleted only if integrated), #4206 leaving a detached `HEAD` on Ctrl-C during a slow commit hook, #4251 allowing `--no-squash` merges with untracked files, #4219 dropping `--no-hooks` from the skill example, and #4279's `docker stop` recipe. #4252 closes a submodule data-loss path. > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
wt step squashandwt merge's squash step rangit reset --soft <merge-base>and thengit commit. When the commit failed — apre-commithook rejecting it, a broken signing setup — the branch was left rewound to the merge base with its commits collapsed into anonymous staged changes, on a path that reported failure. #4193 found it.The squash now rewrites history the way
git rebasedoes. It detaches HEAD onto the merge base withupdate-ref --no-deref, which leaves the branch, the index and the working tree untouched; commits there; then moves the branch to the new commit with one compare-and-swapupdate-refand puts HEAD back on it. The branch keeps its commits until the commit exists, so a rejected or failed commit leaves it exactly as it was, and the reattach restores HEAD.Committing through
git commitrather than plumbing is what keeps git's own hooks,commit.cleanup, signing and identity resolution behaving as they do for any other commit. Those hooks see a detached HEAD, as they do undergit rebase— verified on git 2.55, where a realrebase -isquash runsprepare-commit-msgandpost-commitwith no current branch and skipspre-commitandcommit-msgentirely. Thewt step squashhelp says so.Two smaller changes ride along:
git diff --cached, which is porcelain and readssubmodule.<name>.ignore. A squash whose only change is a submodule pointer hidden by that setting is now committed rather than reported as empty. That path still leaves the branch at the merge base, sowt mergegoes on treating a branch whose commits cancel out as already integrated.signs_commitsasks git from the current worktree instead of reading the cached config map, which is read from the common dir and so missed worktree-scoped config, and which read a valuelessgpgsignas false where git reads it as true.wt merge --no-ffbuilds its merge commit withcommit-treeand asks this helper whether to sign it.test_step_squash_failed_commit_leaves_branch_intactcovers the path end to end: a.git/hooks/pre-committhat exits 1 fails the squash and leaves the branch, HEAD and the history untouched; without the hook the same squash lands. It fails against the old code on the branch-tip assertion, and against a plumbing-based squash on the hook assertion. Two more hooks drive the failure paths the new sequence adds: one moves the branch mid-squash, so the compare-and-swap refuses rather than clobbering the other write, and one seals the worktree's git directory before rejecting the commit, so the reattach fails and has to say how to put HEAD back. The ORIG_HEAD write is best-effort, asgit resetmakes it — the branch has already moved by then, so failing there would report a squash that landed as an error.