Repository navigation
test: run the git-hook autostash tests on every platform - #3695
Merged
Merged
Conversation
The three tests that install a native git hook were gated `#[cfg(unix)]`, but nothing they assert is unix-specific. Git runs hooks through a shell it ships on every platform, so the incidental blockers were the executable bit (which Windows has none of) and a `root.display()` path whose backslashes would reach `sh` as escapes. Move both into `common::write_git_hook`, which gates only the chmod, and interpolate the root with `to_slash_lossy` — the form `step_prune.rs` already uses to embed a path in a hook command on Windows. Each test asserts its own hook fired (`INTERLOPER` present in the stash list; the target ref advanced), so a hook that silently fails to run on Windows fails the test rather than passing vacuously. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Aug 1, 2026
max-sixty
added a commit
that referenced
this pull request
Aug 2, 2026
…#3693) Follows #3684. The Windows test un-gating that was stacked here is split out into #3695, now merged; this PR is the exit-code change alone. ## Problem `wt merge` reported success when the target worktree's autostash failed to replay. The warning named the recovery command, but exit 0 said the user's uncommitted changes were back in their worktree while they were still in a stash — and that warning scrolls past under the worktree-removal and post-merge-hook output that follows it. ## Solution The restore outcome travels out through `PushResult`. The command finishes everything it started — ref advanced, worktree removed, hooks run, `--format=json` payload printed — and only then returns `AlreadyDisplayed { exit_code: 1 }`. Aborting at the restore instead would leave a landed merge with its cleanup half-done, trading a recoverable stash for a worse mess. The shell wrapper applies its `cd` directive whenever the directive file is non-empty, independent of exit code, so a non-zero exit strands nobody in a removed directory. Both output channels name the failure: the `--format=json` payloads of `wt merge` and `wt step push` carry `stash_restore_failed`, present on every payload like the other outcome booleans. The exit code alone would leave a consumer reading stdout with a success-shaped object and no signal. This also closes a gap the change surfaced: `handle_no_ff_merge`'s already-up-to-date early return never called `restore_stash`, so a dirty target worktree with nothing to merge restored through `Drop` and reported nothing. It restores on that path too now, which is what makes the guarantee hold — every remaining `Drop` of the guard happens on a path already returning an error. ## On diverging from git `git rebase --autostash` exits 0 in this situation: it prints "applying them resulted in conflicts" and still reports "Successfully rebased". The difference is what the user is left looking at. git's failure leaves conflict markers in the working tree, met immediately; a failed `git stash apply` here can leave the worktree untouched — an untracked path re-created underneath it, for instance — so nothing but the exit code outlives the warning. The reason is recorded on the field the exit code hangs off, so it doesn't read later as an oversight. ## Testing `test_merge_autostash_restore_failure_exits_non_zero_after_cleanup` covers the guarantee end to end: exit 1, `stash_restore_failed` in the JSON, ref advanced, source worktree removed, stash entry still present for recovery. `test_push_autostash_restore_failure_warns` moves from asserting `success()` to asserting exit 1 plus the push having landed. Also verified against a real build outside the suite, on both commands: the merge lands, the worktree is cleaned up, exit is 1, the JSON reports `"stash_restore_failed": true`, and the warning names the exact `git stash apply <sha>`. `wt step push --help` gained the failure contract, since it previously described only the success path; the generated mirrors are regenerated with it. Local (macOS): `cargo run -- hook pre-merge --yes` green — 4500 tests, clippy, fmt, doc sync. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #3693 so it can be reviewed on its own. Follows #3684.
Problem
The three tests that install a native git hook —
test_push_autostash_survives_concurrent_stash,test_push_autostash_restore_failure_warns, andtest_merge_target_diverges_during_receive_restores_autostash— were gated#[cfg(unix)], so the autostash regression they guard went unverified on Windows.Nothing they assert is unix-specific; git runs hooks through a shell it ships on every platform. The gate was carrying two incidental blockers:
std::os::unix::fs::PermissionsExt, for an executable bit Windows has none of.root.display()path interpolated into the hook script, whose Windows backslashes would reachshas escapes.Solution
common::write_git_hookwrites the hook and gates only the chmod, so the platform fact lives in one place instead of being re-derived per test. The repo root is interpolated withpath_slash'sto_slash_lossy— the formstep_prune.rsalready uses to embed a path in a hook command that runs on Windows.Why un-gating is safe
Each test asserts that its own hook fired: the push tests require
INTERLOPERin the stash list, and the merge test requires the target ref to have advanced. A hook that silently fails to run on Windows therefore fails the test rather than passing vacuously.Confirmed rather than assumed — on the stacked branch these tests ran green on
test (windows), and pulling that job's junit artifact shows all three present by name, so they executed rather than being filtered out.Sweep
The rest of the suite's platform gates were checked and left alone; the remaining ones are gated for real reasons: symlinks, signal delivery, unix permission bits,
lsof/fsmonitor daemon reaping, shell-scriptgitshims onPATH(Windows can't exec a shebang script that way), ConPTY output capture, and clap's differing[experimental]tag rendering in Windows snapshots (step_alias.rs,help.rs— already documented in-place). The#[ignore]s and elevated-privileges runtime skips are likewise documented and intentional.