Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Explain discarded changes and provide safe squash recovery (#4347)
Maximilian Roos62b82ae923f5
diff --git a/docs/src/content/docs/merge.md b/docs/src/content/docs/merge.mdindex 522a542ec..05f213c8d 100644--- a/docs/src/content/docs/merge.md+++ b/docs/src/content/docs/merge.md@@ -78,7 +78,7 @@ $ wt merge --no-commit --no-rebase`wt merge` runs these steps:1. **Commit** — Pre-commit hooks run, then uncommitted changes are committed. Post-commit hooks run in the background. This step is skipped when squashing (the default) — changes are staged during the squash step instead. With `--no-squash`, this is the only commit step.-2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`. With `--no-squash`, individual commits are preserved.+2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`; see [`wt step squash`](/step/#wt-step-squash) for recovery. With `--no-squash`, individual commits are preserved.3. **Rebase** — Rebases onto target, skipping when nothing needs replaying ([`wt step rebase`](/step/#wt-step-rebase) gives the conditions). A conflict stops the merge with the rebase left open in the worktree, to resolve or abort. With `--no-rebase`, the graph produced by earlier commit/squash steps is preserved and the target must be able to fast-forward to its tip.4. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](/hook/).5. **Merge** — Fast-forward merge to the target branch ([`wt step push`](/step/#wt-step-push)). With `--no-ff`, a merge commit is created instead — semi-linear history after the default rebase, while explicit `--no-rebase` preserves the graph produced by earlier steps before adding the merge commit. Non-fast-forward merges are rejected.diff --git a/docs/src/content/docs/step.md b/docs/src/content/docs/step.mdindex ec80370a1..03c3792a4 100644--- a/docs/src/content/docs/step.md+++ b/docs/src/content/docs/step.md@@ -203,6 +203,12 @@ See [LLM-generated commit messages](/llm-commits/) for configuration and promptThe squash commit is made on a detached HEAD, as `git rebase` does, so git's own commit hooks run and see no current branch.+### Recovering staged changes++Before absorbing staged changes, Worktrunk backs up the index to `refs/wt-backup/<branch>`. The backup commit's parent preserves the branch tip before squashing. Unstaged and untracked files outside the selected staging mode stay in the original worktree and are not captured by the backup.++The output prints the backup ref and a command to open its saved commit on a recovery branch in a new worktree. That command uses the backup's immutable SHA and skips project hooks. It preserves current branches, files, and staging, and also works after `wt merge` removes the source worktree.+### Options#### Stagingdiff --git a/plugins/worktrunk/skills/worktrunk/reference/merge.md b/plugins/worktrunk/skills/worktrunk/reference/merge.mdindex 28affc94d..b3fa8a208 100644--- a/plugins/worktrunk/skills/worktrunk/reference/merge.md+++ b/plugins/worktrunk/skills/worktrunk/reference/merge.md@@ -64,7 +64,7 @@ $ wt merge --no-commit --no-rebase`wt merge` runs these steps:1. **Commit** — Pre-commit hooks run, then uncommitted changes are committed. Post-commit hooks run in the background. This step is skipped when squashing (the default) — changes are staged during the squash step instead. With `--no-squash`, this is the only commit step.-2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`. With `--no-squash`, individual commits are preserved.+2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`; see [`wt step squash`](https://worktrunk.dev/step/#wt-step-squash) for recovery. With `--no-squash`, individual commits are preserved.3. **Rebase** — Rebases onto target, skipping when nothing needs replaying ([`wt step rebase`](https://worktrunk.dev/step/#wt-step-rebase) gives the conditions). A conflict stops the merge with the rebase left open in the worktree, to resolve or abort. With `--no-rebase`, the graph produced by earlier commit/squash steps is preserved and the target must be able to fast-forward to its tip.4. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](https://worktrunk.dev/hook/).5. **Merge** — Fast-forward merge to the target branch ([`wt step push`](https://worktrunk.dev/step/#wt-step-push)). With `--no-ff`, a merge commit is created instead — semi-linear history after the default rebase, while explicit `--no-rebase` preserves the graph produced by earlier steps before adding the merge commit. Non-fast-forward merges are rejected.diff --git a/plugins/worktrunk/skills/worktrunk/reference/step.md b/plugins/worktrunk/skills/worktrunk/reference/step.mdindex 784db2890..4ea3b4cb0 100644--- a/plugins/worktrunk/skills/worktrunk/reference/step.md+++ b/plugins/worktrunk/skills/worktrunk/reference/step.md@@ -191,6 +191,12 @@ See [LLM-generated commit messages](https://worktrunk.dev/llm-commits/) for confThe squash commit is made on a detached HEAD, as `git rebase` does, so git's own commit hooks run and see no current branch.+### Recovering staged changes++Before absorbing staged changes, Worktrunk backs up the index to `refs/wt-backup/<branch>`. The backup commit's parent preserves the branch tip before squashing. Unstaged and untracked files outside the selected staging mode stay in the original worktree and are not captured by the backup.++The output prints the backup ref and a command to open its saved commit on a recovery branch in a new worktree. That command uses the backup's immutable SHA and skips project hooks. It preserves current branches, files, and staging, and also works after `wt merge` removes the source worktree.+### Options#### Stagingdiff --git a/skills/worktrunk/reference/merge.md b/skills/worktrunk/reference/merge.mdindex 28affc94d..b3fa8a208 100644--- a/skills/worktrunk/reference/merge.md+++ b/skills/worktrunk/reference/merge.md@@ -64,7 +64,7 @@ $ wt merge --no-commit --no-rebase`wt merge` runs these steps:1. **Commit** — Pre-commit hooks run, then uncommitted changes are committed. Post-commit hooks run in the background. This step is skipped when squashing (the default) — changes are staged during the squash step instead. With `--no-squash`, this is the only commit step.-2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`. With `--no-squash`, individual commits are preserved.+2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`; see [`wt step squash`](https://worktrunk.dev/step/#wt-step-squash) for recovery. With `--no-squash`, individual commits are preserved.3. **Rebase** — Rebases onto target, skipping when nothing needs replaying ([`wt step rebase`](https://worktrunk.dev/step/#wt-step-rebase) gives the conditions). A conflict stops the merge with the rebase left open in the worktree, to resolve or abort. With `--no-rebase`, the graph produced by earlier commit/squash steps is preserved and the target must be able to fast-forward to its tip.4. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](https://worktrunk.dev/hook/).5. **Merge** — Fast-forward merge to the target branch ([`wt step push`](https://worktrunk.dev/step/#wt-step-push)). With `--no-ff`, a merge commit is created instead — semi-linear history after the default rebase, while explicit `--no-rebase` preserves the graph produced by earlier steps before adding the merge commit. Non-fast-forward merges are rejected.diff --git a/skills/worktrunk/reference/step.md b/skills/worktrunk/reference/step.mdindex 784db2890..4ea3b4cb0 100644--- a/skills/worktrunk/reference/step.md+++ b/skills/worktrunk/reference/step.md@@ -191,6 +191,12 @@ See [LLM-generated commit messages](https://worktrunk.dev/llm-commits/) for confThe squash commit is made on a detached HEAD, as `git rebase` does, so git's own commit hooks run and see no current branch.+### Recovering staged changes++Before absorbing staged changes, Worktrunk backs up the index to `refs/wt-backup/<branch>`. The backup commit's parent preserves the branch tip before squashing. Unstaged and untracked files outside the selected staging mode stay in the original worktree and are not captured by the backup.++The output prints the backup ref and a command to open its saved commit on a recovery branch in a new worktree. That command uses the backup's immutable SHA and skips project hooks. It preserves current branches, files, and staging, and also works after `wt merge` removes the source worktree.+### Options#### Stagingdiff --git a/src/cli/mod.rs b/src/cli/mod.rsindex 2b994e9aa..763e54a6e 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -1497,7 +1497,7 @@ $ wt merge --no-commit --no-rebase`wt merge` runs these steps:1. **Commit** — Pre-commit hooks run, then uncommitted changes are committed. Post-commit hooks run in the background. This step is skipped when squashing (the default) — changes are staged during the squash step instead. With `--no-squash`, this is the only commit step.-2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`. With `--no-squash`, individual commits are preserved.+2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`; see [`wt step squash`](/step/#wt-step-squash) for recovery. With `--no-squash`, individual commits are preserved.3. **Rebase** — Rebases onto target, skipping when nothing needs replaying ([`wt step rebase`](/step/#wt-step-rebase) gives the conditions). A conflict stops the merge with the rebase left open in the worktree, to resolve or abort. With `--no-rebase`, the graph produced by earlier commit/squash steps is preserved and the target must be able to fast-forward to its tip.4. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](/hook/).5. **Merge** — Fast-forward merge to the target branch ([`wt step push`](/step/#wt-step-push)). With `--no-ff`, a merge commit is created instead — semi-linear history after the default rebase, while explicit `--no-rebase` preserves the graph produced by earlier steps before adding the merge commit. Non-fast-forward merges are rejected.diff --git a/src/cli/step.rs b/src/cli/step.rsindex 822be66aa..0fbe2a90b 100644--- a/src/cli/step.rs+++ b/src/cli/step.rs@@ -134,6 +134,12 @@ Three sections are printed: the rendered prompt, the shell command that would inThe squash commit is made on a detached HEAD, as `git rebase` does, so git's own commit hooks run and see no current branch.+## Recovering staged changes++Before absorbing staged changes, Worktrunk backs up the index to `refs/wt-backup/<branch>`. The backup commit's parent preserves the branch tip before squashing. Unstaged and untracked files outside the selected staging mode stay in the original worktree and are not captured by the backup.++The output prints the backup ref and a command to open its saved commit on a recovery branch in a new worktree. That command uses the backup's immutable SHA and skips project hooks. It preserves current branches, files, and staging, and also works after `wt merge` removes the source worktree.+## Options### Stagingdiff --git a/src/commands/step/squash.rs b/src/commands/step/squash.rsindex 0859b3c4c..dff89cccf 100644--- a/src/commands/step/squash.rs+++ b/src/commands/step/squash.rs@@ -7,7 +7,7 @@ use worktrunk::config::UserConfig;use worktrunk::git::{Repository, WorkingTree};use worktrunk::styling::{eprintln, format_with_gutter, hint_message, info_message, println, progress_message,- success_message,+ success_message, suggest_command,};use super::super::command_approval::{@@ -264,8 +264,27 @@ pub fn handle_squash(// Back up working-tree changes before the squash commit absorbs themif has_staged {let backup_message = format!("{} → {} (squash)", current_branch, span_target);- let sha = wt.create_safety_backup(&backup_message)?;- eprintln!("{}", hint_message(format!("Backup created @ {sha}")));+ let backup = wt.create_safety_backup(&backup_message)?;+ let short_sha = repo.short_sha(&backup.sha)?;+ eprintln!(+ "{}",+ hint_message(cformat!(+ "Backup created @ <underline>{}</> ({short_sha})",+ backup.ref_name+ ))+ );+ let recovery_branch = format!("recovery/{short_sha}");+ let command = suggest_command(+ "switch",+ &[&recovery_branch],+ &["--create", "--base", &backup.sha, "--no-hooks"],+ );+ eprintln!(+ "{}",+ hint_message(cformat!(+ "To recover in a new worktree, run <underline>{command}</>"+ ))+ );}// Get commit subjects and bodies for the squash messagediff --git a/src/git/error.rs b/src/git/error.rsindex dfaf8edc8..3d7b2302a 100644--- a/src/git/error.rs+++ b/src/git/error.rs@@ -1081,15 +1081,18 @@ impl GitError {..} => {let title = self.title();+ let keep = if dirty_files.iter().any(|line| line.starts_with("?? ")) {+ cformat!("Commit or run <underline>git stash -u</> in the dirty worktree first")+ } else {+ "Commit or stash changes first".to_string()+ };let hint = if *force_hint {// Construct full command: "wt remove [branch] --force"let args: Vec<&str> = branch.as_deref().into_iter().collect();let cmd = suggest_command("remove", &args, &["--force"]);- cformat!(- "Commit or stash changes first, or to lose uncommitted changes, run <underline>{cmd}</>"- )+ cformat!("{keep}, or to lose uncommitted changes, run <underline>{cmd}</>")} else {- "Commit or stash changes first".to_string()+ keep};write!(f, "{}", error_message(&title))?;if !dirty_files.is_empty() {@@ -2748,7 +2751,7 @@ mod tests {[31m✗[39m [31mCannot remove worktree after merge: [1mfeature-auth[22m has uncommitted changes[39m[107m [0m M auth.rs[107m [0m ?? .DS_Store- [2m↳[22m [2mCommit or stash changes first[22m+ [2m↳[22m [2mCommit or run [4mgit stash -u[24m in the dirty worktree first[22m");}diff --git a/src/git/mod.rs b/src/git/mod.rsindex f46739991..249df5e31 100644--- a/src/git/mod.rs+++ b/src/git/mod.rs@@ -101,9 +101,10 @@ pub use remove::{pub use repository::sha_cache;pub use repository::{Branch, BranchDiffSpec, CommitMessageDetail, InProgressOperation, IntegrationTargets,- PreparedDiff, RefSnapshot, Repository, ResolvedWorktree, Selector, StaleWorktreeWork,- TempIndex, WorkingTree, base_path, duplicated_branches, is_valid_branch_name,- normalize_selector, resolve_input_path, select_comparison_base, set_base_path,+ PreparedDiff, RefSnapshot, Repository, ResolvedWorktree, SafetyBackup, Selector,+ StaleWorktreeWork, TempIndex, WorkingTree, base_path, duplicated_branches,+ is_valid_branch_name, normalize_selector, resolve_input_path, select_comparison_base,+ set_base_path,};pub use url::parse_owner_repo;pub use url::{GitRemoteUrl, GitRepoInfo, GitRepoProvider};diff --git a/src/git/remove.rs b/src/git/remove.rsindex 83c7036ea..5fe3535e6 100644--- a/src/git/remove.rs+++ b/src/git/remove.rs@@ -26,8 +26,9 @@//! 1. **Lock and clean checks**. A `git worktree lock` is refused//! unconditionally (matching `git worktree remove`; `--force` does not//! override it). The dirty-worktree gate is skipped with-//! [`RemoveOptions::force_worktree`]. Why the dirty gate precedes the-//! stop below: [`stage_worktree_removal`], "Why this order".+//! [`RemoveOptions::force_worktree`], which reports the current uncommitted+//! paths, or why they could not be read, before deletion instead. Why the+//! dirty gate precedes the stop below: [`stage_worktree_removal`], "Why this order".//! 2. **fsmonitor daemon stopped** (best effort). [`stop_fsmonitor_daemon`]//! runs against the target worktree before its path disappears: it sends//! the graceful `git fsmonitor--daemon stop` IPC request, then verifies the@@ -100,8 +101,9 @@ use std::path::{Path, PathBuf};use std::time::Duration;use crate::git::repository::WorkingTree;-use crate::git::{GitError, IntegrationReason, Repository, WorktreeInfo, path_dir_name};+use crate::git::{ErrorExt, GitError, IntegrationReason, Repository, WorktreeInfo, path_dir_name};use crate::shell_exec::Cmd;+use crate::styling::{eprintln, format_with_gutter, warning_message};use crate::utils::epoch_now;/// Bound on the graceful `git fsmonitor--daemon stop` IPC request.@@ -481,7 +483,32 @@ pub fn stage_worktree_removal(.into());}- if !force_worktree {+ if force_worktree {+ // Disclosure does not veto the force removal, but an interrupted+ // status command still cancels before any directory is removed.+ match worktree.dirty_files() {+ Ok(dirty_files) if !dirty_files.is_empty() => {+ eprintln!(+ "{}",+ warning_message("Discarding uncommitted changes (--force):")+ );+ eprintln!("{}", format_with_gutter(&dirty_files.join("\n"), None));+ }+ Ok(_) => {}+ Err(error) => {+ if error.interrupt_signal().is_some() {+ return Err(error);+ }+ eprintln!(+ "{}",+ warning_message(+ "Cannot list uncommitted changes; discarding worktree contents (--force):"+ )+ );+ eprintln!("{}", format_with_gutter(&error.display_message(), None));+ }+ }+ } else {worktree.ensure_clean("remove worktree", branch, true)?;}diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rsindex 581732be5..b9bc0e3ea 100644--- a/src/git/repository/mod.rs+++ b/src/git/repository/mod.rs@@ -176,7 +176,7 @@ pub use integration::{BranchDiffSpec, IntegrationTargets, select_comparison_basepub use ref_snapshot::RefSnapshot;pub(super) use working_tree::path_to_logging_context;use working_tree::registration_worktree_path;-pub use working_tree::{InProgressOperation, TempIndex, WorkingTree};+pub use working_tree::{InProgressOperation, SafetyBackup, TempIndex, WorkingTree};pub use worktrees::{StaleWorktreeWork, duplicated_branches};// ============================================================================diff --git a/src/git/repository/working_tree.rs b/src/git/repository/working_tree.rsindex 49b0ed766..c9ead5447 100644--- a/src/git/repository/working_tree.rs+++ b/src/git/repository/working_tree.rs@@ -17,6 +17,14 @@ use crate::git::{CommandError, PlumbingDiff};const TEMP_INDEX_PREFIX: &str = "worktrunk-temp-index-";+/// A squash safety backup: an immutable snapshot of the index and the ref+/// whose reflog retains it. The backup commit's parent is the pre-squash HEAD.+#[derive(Debug)]+pub struct SafetyBackup {+ pub sha: String,+ pub ref_name: String,+}+#[derive(Debug)]struct NumstatEntry {diff: LineDiff,@@ -1164,7 +1172,7 @@ impl<'a> WorkingTree<'a> {/// `git read-tree <sha>` restores that index, `git checkout <sha> -- .` also/// restores the files, and `<sha>^` is the branch tip before the squash.///- /// Returns the short SHA of the backup commit.+ /// Returns the backup commit's SHA and the ref retaining it.////// # Example/// ```no_run@@ -1172,11 +1180,11 @@ impl<'a> WorkingTree<'a> {////// let repo = Repository::current()?;/// let wt = repo.current_worktree();- /// let sha = wt.create_safety_backup("feature → main (squash)")?;- /// println!("Backup created: {}", sha);+ /// let backup = wt.create_safety_backup("feature → main (squash)")?;+ /// println!("Backup created: {}", backup.sha);/// # Ok::<(), anyhow::Error>(())/// ```- pub fn create_safety_backup(&self, message: &str) -> anyhow::Result<String> {+ pub fn create_safety_backup(&self, message: &str) -> anyhow::Result<SafetyBackup> {let tree = self.run_command(&["write-tree"])?;let backup_sha = self.run_command(&[@@ -1214,7 +1222,10 @@ impl<'a> WorkingTree<'a> {]).context("Failed to create backup ref")?;- self.repo().short_sha(&backup_sha)+ Ok(SafetyBackup {+ sha: backup_sha,+ ref_name,+ })}}diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex 492f1cb4b..7933a683d 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -2681,6 +2681,239 @@ fn test_merge_squash_with_working_tree_creates_backup(mut repo_with_main_worktre"Expected backup in reflog, but reflog was: {}",reflog);++ wait_for_worktree_removed(&feature_wt);+ let merged_head = repo.git_output(&["rev-parse", "main"]);+ let backup = repo.git_output(&["rev-parse", "refs/wt-backup/feature"]);+ let repository = worktrunk::git::Repository::at(repo.root_path()).unwrap();+ let recovery_branch = format!("recovery/{}", repository.short_sha(&backup).unwrap());+ let output = repo+ .wt_command()+ .args([+ "switch",+ "--create",+ "--base",+ &backup,+ "--no-hooks",+ &recovery_branch,+ ])+ .output()+ .unwrap();+ assert!(+ output.status.success(),+ "{}",+ String::from_utf8_lossy(&output.stderr)+ );+ let recovered = repository+ .worktree_for_branch(&recovery_branch)+ .unwrap()+ .unwrap();+ assert_eq!(+ fs::read_to_string(recovered.join("file1.txt")).unwrap(),+ "updated content 1"+ );+ assert_eq!(repo.git_output(&["rev-parse", "main"]), merged_head);+}++/// The printed backup recovery command restores captured content and history+/// in another worktree, preserving edits and staging made after the squash.+#[rstest]+fn test_squash_backup_recovery_preserves_live_changes(mut repo: TestRepo) {+ fs::write(repo.root_path().join("tracked.txt"), "base\n").unwrap();+ fs::write(repo.root_path().join("unstaged.txt"), "base\n").unwrap();+ repo.commit("base files");+ let branch = "feature/recovery";+ let worktree = repo.add_worktree(branch);+ fs::write(worktree.join("tracked.txt"), "first\n").unwrap();+ repo.run_git_in(&worktree, &["add", "."]);+ repo.run_git_in(&worktree, &["commit", "-m", "first"]);+ fs::write(worktree.join("committed.txt"), "second\n").unwrap();+ repo.run_git_in(&worktree, &["add", "."]);+ repo.run_git_in(&worktree, &["commit", "-m", "second"]);+ let old_head = repo.git_output(&["rev-parse", branch]);++ fs::write(worktree.join("tracked.txt"), "staged snapshot\n").unwrap();+ repo.run_git_in(&worktree, &["add", "tracked.txt"]);+ fs::write(worktree.join("unstaged.txt"), "unstaged draft\n").unwrap();+ fs::write(worktree.join("draft.txt"), "untracked draft\n").unwrap();++ let output = repo+ .wt_command()+ .args(["step", "squash", "--stage=none", "--no-hooks"])+ .current_dir(&worktree)+ .output()+ .unwrap();+ let stderr = String::from_utf8_lossy(&output.stderr)+ .ansi_strip()+ .into_owned();+ assert!(output.status.success(), "{stderr}");+ assert!(+ stderr.contains("refs/wt-backup/feature/recovery"),+ "{stderr}"+ );+ let recovery = stderr+ .lines()+ .find_map(|line| line.strip_prefix("↳ To recover in a new worktree, run "))+ .expect("a copyable backup recovery command");++ // Running the advice from main must not move main to the old feature tip.+ let main_before = repo.git_output(&["rev-parse", "main"]);+ let feature_before = repo.git_output(&["rev-parse", branch]);+ // A later backup can advance the named ref; the printed SHA still selects+ // the original saved index and history.+ repo.run_git(&[+ "update-ref",+ "refs/wt-backup/feature/recovery",+ &main_before,+ ]);+ fs::write(worktree.join("tracked.txt"), "new staged edit\n").unwrap();+ repo.run_git_in(&worktree, &["add", "tracked.txt"]);+ let index_before = repo+ .git_command()+ .args(["write-tree"])+ .current_dir(&worktree)+ .run()+ .unwrap()+ .stdout;++ let output = repo+ .wt_command()+ .args(recovery.strip_prefix("wt ").unwrap().split_whitespace())+ .output()+ .unwrap();+ assert!(+ output.status.success(),+ "{}",+ String::from_utf8_lossy(&output.stderr)+ );+ let recovery_branch = recovery.split_whitespace().last().unwrap();+ let recovered = worktrunk::git::Repository::at(repo.root_path())+ .unwrap()+ .worktree_for_branch(recovery_branch)+ .unwrap()+ .unwrap();+ assert_eq!(+ repo.git_output(&["rev-parse", &format!("{recovery_branch}^")]),+ old_head+ );+ assert_eq!(+ fs::read_to_string(recovered.join("tracked.txt")).unwrap(),+ "staged snapshot\n"+ );+ assert_eq!(+ fs::read_to_string(recovered.join("unstaged.txt")).unwrap(),+ "base\n"+ );+ assert!(!recovered.join("draft.txt").exists());+ assert_eq!(repo.git_output(&["rev-parse", "main"]), main_before);+ assert_eq!(repo.git_output(&["rev-parse", branch]), feature_before);+ assert_eq!(+ repo.git_command()+ .args(["write-tree"])+ .current_dir(&worktree)+ .run()+ .unwrap()+ .stdout,+ index_before+ );+ assert_eq!(+ fs::read_to_string(worktree.join("unstaged.txt")).unwrap(),+ "unstaged draft\n"+ );+ assert_eq!(+ fs::read_to_string(worktree.join("tracked.txt")).unwrap(),+ "new staged edit\n"+ );+ assert_eq!(+ fs::read_to_string(worktree.join("draft.txt")).unwrap(),+ "untracked draft\n"+ );++ // Squash another staged edit on the same source, then follow its new+ // recovery advice. An earlier recovery must not block the later snapshot.+ let first_recovery_head = repo.git_output(&["rev-parse", recovery_branch]);+ let output = repo+ .wt_command()+ .args(["step", "squash", "--stage=none", "--no-hooks"])+ .current_dir(&worktree)+ .output()+ .unwrap();+ let stderr = String::from_utf8_lossy(&output.stderr)+ .ansi_strip()+ .into_owned();+ assert!(output.status.success(), "{stderr}");+ let second_recovery = stderr+ .lines()+ .find_map(|line| line.strip_prefix("↳ To recover in a new worktree, run "))+ .expect("a copyable backup recovery command");+ let second_recovery_branch = second_recovery.split_whitespace().last().unwrap();+ let source_head = repo.git_output(&["rev-parse", branch]);+ fs::write(worktree.join("tracked.txt"), "latest live edit\n").unwrap();+ repo.run_git_in(&worktree, &["add", "tracked.txt"]);+ let live_index = repo+ .git_command()+ .args(["write-tree"])+ .current_dir(&worktree)+ .run()+ .unwrap()+ .stdout;++ let output = repo+ .wt_command()+ .args(+ second_recovery+ .strip_prefix("wt ")+ .unwrap()+ .split_whitespace(),+ )+ .output()+ .unwrap();+ assert!(+ output.status.success(),+ "{}",+ String::from_utf8_lossy(&output.stderr)+ );+ assert_ne!(recovery_branch, second_recovery_branch);+ let second_recovered = worktrunk::git::Repository::at(repo.root_path())+ .unwrap()+ .worktree_for_branch(second_recovery_branch)+ .unwrap()+ .unwrap();+ assert_eq!(+ fs::read_to_string(second_recovered.join("tracked.txt")).unwrap(),+ "new staged edit\n"+ );+ assert_eq!(+ fs::read_to_string(recovered.join("tracked.txt")).unwrap(),+ "staged snapshot\n"+ );+ assert_eq!(+ repo.git_output(&["rev-parse", recovery_branch]),+ first_recovery_head+ );+ assert_eq!(repo.git_output(&["rev-parse", "main"]), main_before);+ assert_eq!(repo.git_output(&["rev-parse", branch]), source_head);+ assert_eq!(+ repo.git_command()+ .args(["write-tree"])+ .current_dir(&worktree)+ .run()+ .unwrap()+ .stdout,+ live_index+ );+ assert_eq!(+ fs::read_to_string(worktree.join("tracked.txt")).unwrap(),+ "latest live edit\n"+ );+ assert_eq!(+ fs::read_to_string(worktree.join("unstaged.txt")).unwrap(),+ "unstaged draft\n"+ );+ assert_eq!(+ fs::read_to_string(worktree.join("draft.txt")).unwrap(),+ "untracked draft\n"+ );}/// A staged submodule bump that `submodule.<name>.ignore = all` hides fromdiff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rsindex c3c31398f..adb15ae74 100644--- a/tests/integration_tests/remove.rs+++ b/tests/integration_tests/remove.rs@@ -1396,6 +1396,90 @@ fn test_remove_refuses_dirty_target_when_git_dir_names_invoking_worktree(mut rep);}+/// Stash advice includes untracked files, including alongside tracked edits.+#[rstest]+#[case::untracked_only(false)]+#[case::mixed(true)]+fn test_remove_stash_advice_preserves_untracked(mut repo: TestRepo, #[case] mixed: bool) {+ let worktree = repo.add_worktree("stash-advice");+ fs::write(worktree.join("draft.txt"), "untracked draft\n").unwrap();+ if mixed {+ fs::write(worktree.join("tracked.txt"), "original\n").unwrap();+ repo.run_git_in(&worktree, &["add", "tracked.txt"]);+ repo.run_git_in(&worktree, &["commit", "-m", "tracked file"]);+ fs::write(worktree.join("tracked.txt"), "modified\n").unwrap();+ }++ let output = repo+ .wt_command()+ .args(["remove", "stash-advice"])+ .output()+ .unwrap();+ let stderr = String::from_utf8_lossy(&output.stderr)+ .ansi_strip()+ .into_owned();+ assert!(!output.status.success());+ assert!(stderr.contains("git stash -u"), "{stderr}");+ repo.run_git_in(&worktree, &["stash", "-u"]);+ assert!(!worktree.join("draft.txt").exists());+ assert_eq!(+ repo.git_output(&["show", "stash^3:draft.txt"]),+ "untracked draft"+ );+ repo.run_git_in(&worktree, &["stash", "pop"]);+ assert_eq!(+ fs::read_to_string(worktree.join("draft.txt")).unwrap(),+ "untracked draft\n"+ );+ if mixed {+ assert_eq!(+ fs::read_to_string(worktree.join("tracked.txt")).unwrap(),+ "modified\n"+ );+ }+}++/// Force-discard disclosure observes changes made by an approved pre-remove+/// hook, and runs only after that hook succeeds.+#[rstest]+#[case::remove("printf data > hook-only.txt", true)]+#[case::abort("printf data > hook-only.txt; exit 1", false)]+fn test_force_discard_warning_after_pre_remove(+ mut repo: TestRepo,+ #[case] hook: &str,+ #[case] succeeds: bool,+) {+ repo.write_project_config(&format!("pre-remove = '{hook}'"));+ repo.commit("hook");+ let worktree = repo.add_worktree("force-hook");+ let output = repo+ .wt_command()+ .args(["remove", "force-hook", "--force", "--foreground", "--yes"])+ .output()+ .unwrap();+ let stderr = String::from_utf8_lossy(&output.stderr)+ .ansi_strip()+ .into_owned();+ assert_eq!(output.status.success(), succeeds, "{stderr}");+ if succeeds {+ assert!(+ stderr.contains("Discarding uncommitted changes (--force)"),+ "{stderr}"+ );+ assert!(stderr.contains("?? hook-only.txt"), "{stderr}");+ assert!(!worktree.exists());+ } else {+ assert!(+ !stderr.contains("Discarding uncommitted changes"),+ "{stderr}"+ );+ assert_eq!(+ fs::read_to_string(worktree.join("hook-only.txt")).unwrap(),+ "data"+ );+ }+}+/// --force allows removal of dirty worktrees (issue #658)/// This test: untracked files, branch at same commit as main#[rstest]@@ -5658,3 +5742,227 @@ fn test_remove_stale_entry_spares_absent_sibling(mut repo: TestRepo) {"the stale entry should have been pruned\n{listed}");}++/// An unreadable index prevents normal removal, but disclosure must not veto+/// explicitly forced removal that Git itself permits. Neighboring data and+/// the retained branch remain intact.+#[rstest]+fn test_force_remove_with_corrupt_index_reports_unreadable_status(mut repo: TestRepo) {+ let mut target = None;+ let mut target_index = None;+ for branch in ["corrupt-index", "git-force-control"] {+ let worktree = repo.add_worktree(branch);+ fs::write(worktree.join("untracked.txt"), "keep until forced\n").unwrap();+ let output = repo+ .git_command()+ .args(["rev-parse", "--absolute-git-dir"])+ .current_dir(&worktree)+ .run()+ .unwrap();+ assert!(output.status.success());+ let index = PathBuf::from(String::from_utf8(output.stdout).unwrap().trim()).join("index");+ fs::write(&index, "bad").unwrap();+ let status = repo+ .git_command()+ .args(["status", "--porcelain"])+ .current_dir(&worktree)+ .run()+ .unwrap();+ assert_eq!(status.status.code(), Some(128));+ if branch == "git-force-control" {+ let removal = repo+ .git_command()+ .args(["worktree", "remove", "--force"])+ .arg(worktree.to_string_lossy())+ .run()+ .unwrap();+ assert!(+ removal.status.success(),+ "{}",+ String::from_utf8_lossy(&removal.stderr)+ );+ assert!(!worktree.exists());+ } else {+ target = Some(worktree);+ target_index = Some(index);+ }+ }+ let worktree = target.unwrap();+ let index = target_index.unwrap();+ let branch_head = repo.git_output(&["rev-parse", "refs/heads/corrupt-index"]);+ let sentinel = repo.root_path().join("main-only.txt");+ fs::write(&sentinel, "main worktree data\n").unwrap();+ let refusal = repo+ .wt_command()+ .args([+ "remove",+ "corrupt-index",+ "--foreground",+ "--no-delete-branch",+ ])+ .output()+ .unwrap();+ assert!(!refusal.status.success());+ assert_eq!(fs::read(&index).unwrap(), b"bad");+ assert_eq!(+ fs::read_to_string(worktree.join("untracked.txt")).unwrap(),+ "keep until forced\n"+ );+ let removal = repo+ .wt_command()+ .args([+ "remove",+ "corrupt-index",+ "--foreground",+ "--no-delete-branch",+ "--force",+ ])+ .output()+ .unwrap();+ assert!(+ removal.status.success(),+ "{}",+ String::from_utf8_lossy(&removal.stderr)+ );+ assert!(!worktree.exists());+ assert!(!index.exists());+ assert_eq!(+ repo.git_output(&["rev-parse", "refs/heads/corrupt-index"]),+ branch_head+ );+ assert_eq!(+ fs::read_to_string(&sentinel).unwrap(),+ "main worktree data\n"+ );+ setup_snapshot_settings(&repo).bind(|| {+ assert_snapshot!(+ "force_remove_corrupt_index",+ String::from_utf8_lossy(&removal.stderr)+ );+ });+}++/// An interrupted status probe must cancel force removal before data is staged+/// for deletion, and before the next worktree in a removal batch is touched.+#[cfg(unix)]+#[rstest]+#[case::foreground_sigint(true, false, 2)]+#[case::background_sigint(false, false, 2)]+#[case::foreground_sigterm(true, false, 15)]+#[case::background_sigterm(false, false, 15)]+#[case::detached_foreground_sigint(true, true, 2)]+#[case::detached_foreground_sigterm(true, true, 15)]+fn test_force_remove_interrupted_status_preserves_worktrees(+ mut repo: TestRepo,+ #[case] foreground: bool,+ #[case] detached: bool,+ #[case] signal: i32,+) {+ use std::os::unix::fs::PermissionsExt;+ use std::os::unix::process::ExitStatusExt;++ let worktree = repo.add_worktree("interrupted-status");+ let later_worktree = repo.add_worktree("later-worktree");+ fs::write(worktree.join("untracked.txt"), "preserve this data\n").unwrap();+ fs::write(+ later_worktree.join("untracked.txt"),+ "preserve later data\n",+ )+ .unwrap();+ let branch_head = repo.git_output(&["rev-parse", "refs/heads/interrupted-status"]);+ if detached {+ repo.detach_head_in_worktree("interrupted-status");+ repo.run_git(&["branch", "-d", "interrupted-status"]);+ let symbolic_head = repo+ .git_command()+ .args(["symbolic-ref", "--quiet", "HEAD"])+ .current_dir(&worktree)+ .run()+ .unwrap();+ assert_eq!(symbolic_head.status.code(), Some(1));+ assert_eq!(+ repo.git_command()+ .args([+ "show-ref",+ "--verify",+ "--quiet",+ "refs/heads/interrupted-status"+ ])+ .run()+ .unwrap()+ .status+ .code(),+ Some(1)+ );+ }+ let worktrees_before = repo.git_output(&["worktree", "list", "--porcelain"]);+ let staged_path = crate::common::resolve_git_common_dir(repo.root_path())+ .join("wt/trash")+ .join(format!("interrupted-status-{}", crate::common::TEST_EPOCH));+ assert!(!staged_path.exists());+ let monitor = repo.root_path().join(".git/interrupt-status");+ fs::write(+ &monitor,+ format!("#!/bin/sh\nkill -{signal} \"$PPID\"\nexit 0\n"),+ )+ .unwrap();+ fs::set_permissions(&monitor, fs::Permissions::from_mode(0o755)).unwrap();+ repo.run_git(&["config", "core.fsmonitor", monitor.to_str().unwrap()]);++ // Git invokes a real fsmonitor hook during status; the hook interrupts+ // only its own parent Git process, never the test or Worktrunk process.+ let status = repo+ .git_command()+ .args(["status", "--porcelain"])+ .current_dir(&worktree)+ .run()+ .unwrap();+ assert_eq!(status.status.signal(), Some(signal));++ let mut command = repo.wt_command();+ let target = if detached {+ worktree.to_str().unwrap()+ } else {+ "interrupted-status"+ };+ command.args([+ "remove",+ target,+ "later-worktree",+ "--no-delete-branch",+ "--force",+ ]);+ if foreground {+ command.arg("--foreground");+ }+ let removal = command.output().unwrap();+ assert_eq!(+ removal.status.signal(),+ Some(signal),+ "{}",+ String::from_utf8_lossy(&removal.stderr)+ );+ assert_eq!(+ fs::read_to_string(worktree.join("untracked.txt")).unwrap(),+ "preserve this data\n"+ );+ assert!(worktree.join(".git").is_file());+ assert!(later_worktree.join(".git").is_file());+ assert!(!staged_path.exists());+ assert_eq!(+ fs::read_to_string(later_worktree.join("untracked.txt")).unwrap(),+ "preserve later data\n"+ );+ assert_eq!(+ repo.git_output(&["-C", worktree.to_str().unwrap(), "rev-parse", "HEAD"]),+ branch_head+ );+ assert_eq!(+ repo.git_output(&["worktree", "list", "--porcelain"]),+ worktrees_before+ );+ let stderr = String::from_utf8_lossy(&removal.stderr);+ assert!(!stderr.contains("Discarding"));+ assert!(!stderr.contains("discarding"));+ assert!(!stderr.contains("Removing later-worktree"));+}diff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__git_state_errors.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__git_state_errors.snapindex e02f22218..ad3a66079 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__git_state_errors.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__git_state_errors.snap@@ -49,7 +49,7 @@ expression: render_cases(cases)[31m✗[39m [31mCannot remove worktree after merge: [1mfeature-auth[22m has uncommitted changes[39m[107m [0m M auth.rs[107m [0m ?? .DS_Store-[2m↳[22m [2mCommit or stash changes first[22m+[2m↳[22m [2mCommit or run [4mgit stash -u[24m in the dirty worktree first[22m## branch already existsdiff --git a/tests/snapshots/integration__integration_tests__help__help_md_merge.snap b/tests/snapshots/integration__integration_tests__help__help_md_merge.snapindex f3f667b21..028a300e2 100644--- a/tests/snapshots/integration__integration_tests__help__help_md_merge.snap+++ b/tests/snapshots/integration__integration_tests__help__help_md_merge.snap@@ -173,7 +173,7 @@ $ wt merge --no-commit --no-rebase`wt merge` runs these steps:1. **Commit** — Pre-commit hooks run, then uncommitted changes are committed. Post-commit hooks run in the background. This step is skipped when squashing (the default) — changes are staged during the squash step instead. With `--no-squash`, this is the only commit step.-2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`. With `--no-squash`, individual commits are preserved.+2. **Squash** — Combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. Working-tree changes swept into the squash are backed up first to `refs/wt-backup/<branch>`; see [`wt step squash`](/step/#wt-step-squash) for recovery. With `--no-squash`, individual commits are preserved.3. **Rebase** — Rebases onto target, skipping when nothing needs replaying ([`wt step rebase`](/step/#wt-step-rebase) gives the conditions). A conflict stops the merge with the rebase left open in the worktree, to resolve or abort. With `--no-rebase`, the graph produced by earlier commit/squash steps is preserved and the target must be able to fast-forward to its tip.4. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](/hook/).5. **Merge** — Fast-forward merge to the target branch ([`wt step push`](/step/#wt-step-push)). With `--no-ff`, a merge commit is created instead — semi-linear history after the default rebase, while explicit `--no-rebase` preserves the graph produced by earlier steps before adding the merge commit. Non-fast-forward merges are rejected.diff --git a/tests/snapshots/integration__integration_tests__help__help_merge_long.snap b/tests/snapshots/integration__integration_tests__help__help_merge_long.snapindex 0932b2b0c..14876477c 100644--- a/tests/snapshots/integration__integration_tests__help__help_merge_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_merge_long.snap@@ -157,7 +157,7 @@ Preserve the exact clean commit graph and tip:[2mwt merge[0m runs these steps:1. [1mCommit[0m — Pre-commit hooks run, then uncommitted changes are committed. Post-commit hooks run in the background. This step is skipped when squashing (the default) — changes are staged during the squash step instead. With [2m--no-squash[0m, this is the only commit step.-2. [1mSquash[0m — Combines all commits since target into one (like GitHub's "Squash and merge"). Use [2m--stage[0m to control what gets staged: [2mall[0m (default), [2mtracked[0m, or [2mnone[0m. Working-tree changes swept into the squash are backed up first to [2mrefs/wt-backup/<branch>[0m. With [2m--no-squash[0m, individual commits are preserved.+2. [1mSquash[0m — Combines all commits since target into one (like GitHub's "Squash and merge"). Use [2m--stage[0m to control what gets staged: [2mall[0m (default), [2mtracked[0m, or [2mnone[0m. Working-tree changes swept into the squash are backed up first to [2mrefs/wt-backup/<branch>[0m; see [2mwt step squash[0m for recovery. With [2m--no-squash[0m, individual commits are preserved.3. [1mRebase[0m — Rebases onto target, skipping when nothing needs replaying ([2mwt step rebase[0m gives the conditions). A conflict stops the merge with the rebase left open in the worktree, to resolve or abort. With [2m--no-rebase[0m, the graph produced by earlier commit/squash steps is preserved and the target must be able to fast-forward to its tip.4. [1mPre-merge hooks[0m — Hooks run after rebase, before merge. Failures abort. See [2mwt hook[0m.5. [1mMerge[0m — Fast-forward merge to the target branch ([2mwt step push[0m). With [2m--no-ff[0m, a merge commit is created instead — semi-linear history after the default rebase, while explicit [2m--no-rebase[0m preserves the graph produced by earlier steps before adding the merge commit. Non-fast-forward merges are rejected.diff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snapindex b1d63423d..46137a715 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap@@ -60,7 +60,8 @@ exit_code: 0----- stderr -----[36m◎[39m [36mSquashing 2 commits & working tree changes into a single commit [90m(2 files, [32m+2[39m[39m[90m)[39m...[39m-[2m↳[22m [2mBackup created @ 650fba7[22m+[2m↳[22m [2mBackup created @ [4mrefs/wt-backup/feature[24m (650fba7)[22m+[2m↳[22m [2mTo recover in a new worktree, run [4mwt switch --create --base 650fba7c9c04204ce4928e32c12e9c5b79d6d1a5 --no-hooks recovery/650fba7[24m[22m[36m◎[39m [36mGenerating squash commit message...[39m[107m [0m [1mfix: update file 1 content[22m[32m✓[39m [32mSquashed @ [HASH][39mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snapindex bbabe90b0..8174b21f7 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap@@ -60,7 +60,8 @@ exit_code: 0----- stderr -----[36m◎[39m [36mSquashing 1 commit & working tree changes into a single commit [90m(1 file, [32m+1[39m[39m[90m)[39m...[39m-[2m↳[22m [2mBackup created @ 6cb8292[22m+[2m↳[22m [2mBackup created @ [4mrefs/wt-backup/feature[24m (6cb8292)[22m+[2m↳[22m [2mTo recover in a new worktree, run [4mwt switch --create --base 6cb82927209b837bd2669fa0e042f237a70ca06e --no-hooks recovery/6cb8292[24m[22m[36m◎[39m [36mGenerating squash commit message...[39m[2m↳[22m [2mUsing fallback commit message. For LLM setup guide, run [4mwt config --help[24m[22m[107m [0m [1mSquash commits from feature[22mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snapindex 1115df280..61a9d3587 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap@@ -60,7 +60,8 @@ exit_code: 0----- stderr -----[36m◎[39m [36mSquashing 1 commit & working tree changes into a single commit [90m(1 file, [32m+1[39m[39m[90m)[39m...[39m-[2m↳[22m [2mBackup created @ 96b35d4[22m+[2m↳[22m [2mBackup created @ [4mrefs/wt-backup/feature[24m (96b35d4)[22m+[2m↳[22m [2mTo recover in a new worktree, run [4mwt switch --create --base 96b35d420c90946751bddf92e243883b903b52cb --no-hooks recovery/96b35d4[24m[22m[36m◎[39m [36mGenerating squash commit message...[39m[107m [0m [1mfix: improve auth validation logic[22m[32m✓[39m [32mSquashed @ [HASH][39mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_error_uncommitted_changes_with_no_commit.snap b/tests/snapshots/integration__integration_tests__merge__merge_error_uncommitted_changes_with_no_commit.snapindex f2a69a86a..191b60daf 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_error_uncommitted_changes_with_no_commit.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_error_uncommitted_changes_with_no_commit.snap@@ -63,4 +63,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot merge with --no-commit: [1mfeature[22m has uncommitted changes[39m[107m [0m ?? dirty.txt-[2m↳[22m [2mCommit or stash changes first[22m+[2m↳[22m [2mCommit or run [4mgit stash -u[24m in the dirty worktree first[22mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_commit_with_dirty_tree.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_commit_with_dirty_tree.snapindex 44d267d57..a0bd56171 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_no_commit_with_dirty_tree.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_commit_with_dirty_tree.snap@@ -62,4 +62,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot merge with --no-commit: [1mfeature[22m has uncommitted changes[39m[107m [0m ?? uncommitted.txt-[2m↳[22m [2mCommit or stash changes first[22m+[2m↳[22m [2mCommit or run [4mgit stash -u[24m in the dirty worktree first[22mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_working_tree_creates_backup.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_working_tree_creates_backup.snapindex c50ce144a..ab6843d6a 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_working_tree_creates_backup.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_working_tree_creates_backup.snap@@ -61,7 +61,8 @@ exit_code: 0----- stderr -----[36m◎[39m [36mSquashing 2 commits & working tree changes into a single commit [90m(2 files, [32m+2[39m[39m[90m)[39m...[39m-[2m↳[22m [2mBackup created @ 650fba7[22m+[2m↳[22m [2mBackup created @ [4mrefs/wt-backup/feature[24m (650fba7)[22m+[2m↳[22m [2mTo recover in a new worktree, run [4mwt switch --create --base 650fba7c9c04204ce4928e32c12e9c5b79d6d1a5 --no-hooks recovery/650fba7[24m[22m[36m◎[39m [36mGenerating squash commit message...[39m[107m [0m [1mfix: update files[22m[32m✓[39m [32mSquashed @ [HASH][39mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snap b/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snapindex c779d3c8e..453516ead 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snap@@ -64,7 +64,8 @@ exit_code: 0[107m [0m untracked1.txt[107m [0m untracked2.txt[36m◎[39m [36mSquashing 1 commit & working tree changes into a single commit [90m(3 files, [32m+3[39m[39m[90m)[39m...[39m-[2m↳[22m [2mBackup created @ ce9d1c1[22m+[2m↳[22m [2mBackup created @ [4mrefs/wt-backup/feature[24m (ce9d1c1)[22m+[2m↳[22m [2mTo recover in a new worktree, run [4mwt switch --create --base ce9d1c11261ee2906292f0f9ce50dda3309f0645 --no-hooks recovery/ce9d1c1[24m[22m[36m◎[39m [36mGenerating squash commit message...[39m[107m [0m [1mfix: commit changes[22m[32m✓[39m [32mSquashed @ [HASH][39mdiff --git a/tests/snapshots/integration__integration_tests__merge__step_squash_with_both_flags.snap b/tests/snapshots/integration__integration_tests__merge__step_squash_with_both_flags.snapindex 64ecf8d05..8db1f2843 100644--- a/tests/snapshots/integration__integration_tests__merge__step_squash_with_both_flags.snap+++ b/tests/snapshots/integration__integration_tests__merge__step_squash_with_both_flags.snap@@ -64,7 +64,8 @@ exit_code: 0----- stderr -----[2m○[22m Skipping pre-commit hooks (--no-hooks)[36m◎[39m [36mSquashing 2 commits & tracked changes into a single commit [90m(3 files, [32m+3[39m[39m[90m)[39m...[39m-[2m↳[22m [2mBackup created @ 6f7dfd4[22m+[2m↳[22m [2mBackup created @ [4mrefs/wt-backup/feature[24m (6f7dfd4)[22m+[2m↳[22m [2mTo recover in a new worktree, run [4mwt switch --create --base 6f7dfd42f267cc3012b438ad75c616e7b3b9f10d --no-hooks recovery/6f7dfd4[24m[22m[36m◎[39m [36mGenerating squash commit message...[39m[107m [0m [1msquash: combined commits[22m[32m✓[39m [32mSquashed @ [HASH][39mdiff --git a/tests/snapshots/integration__integration_tests__merge__step_squash_with_stage_tracked_flag.snap b/tests/snapshots/integration__integration_tests__merge__step_squash_with_stage_tracked_flag.snapindex 6cf910651..3b78137cf 100644--- a/tests/snapshots/integration__integration_tests__merge__step_squash_with_stage_tracked_flag.snap+++ b/tests/snapshots/integration__integration_tests__merge__step_squash_with_stage_tracked_flag.snap@@ -62,7 +62,8 @@ exit_code: 0----- stderr -----[36m◎[39m [36mSquashing 2 commits & tracked changes into a single commit [90m(2 files, [32m+2[39m[39m[90m)[39m...[39m-[2m↳[22m [2mBackup created @ 3f99f8e[22m+[2m↳[22m [2mBackup created @ [4mrefs/wt-backup/feature[24m (3f99f8e)[22m+[2m↳[22m [2mTo recover in a new worktree, run [4mwt switch --create --base 3f99f8e7a6c4d4516bf6ceff958037f873de5202 --no-hooks recovery/3f99f8e[24m[22m[36m◎[39m [36mGenerating squash commit message...[39m[107m [0m [1msquash: combined commits[22m[32m✓[39m [32mSquashed @ [HASH][39mdiff --git a/tests/snapshots/integration__integration_tests__remove__force_remove_corrupt_index.snap b/tests/snapshots/integration__integration_tests__remove__force_remove_corrupt_index.snapnew file mode 100644index 000000000..cda12b3c4--- /dev/null+++ b/tests/snapshots/integration__integration_tests__remove__force_remove_corrupt_index.snap@@ -0,0 +1,9 @@+---+source: tests/integration_tests/remove.rs+expression: "String::from_utf8_lossy(&removal.stderr)"+---+[36m◎[39m [36mRemoving [1mcorrupt-index[22m worktree...[39m+[33m▲[39m [33mCannot list uncommitted changes; discarding worktree contents (--force):[39m+[107m [0m fatal: _REPO_/.git/worktrees/repo.corrupt-index/index: index file smaller than expected+[32m✓[39m [32mRemoved [1mcorrupt-index[22m worktree (--force)[39m [90m(4 files · [BYTES] B[39m[90m)[39m+[2m↳[22m [2mBranch integrated (same commit as [4mmain[24m, [2m_[22m); retained with [4m--no-delete-branch[24m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap b/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snapindex 55aeb036d..4037256cd 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap@@ -61,4 +61,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot remove worktree: [1mfeature-dirty[22m has uncommitted changes[39m[107m [0m ?? dirty.txt-[2m↳[22m [2mCommit or stash changes first, or to lose uncommitted changes, run [4mwt remove --force feature-dirty[24m[22m+[2m↳[22m [2mCommit or run [4mgit stash -u[24m in the dirty worktree first, or to lose uncommitted changes, run [4mwt remove --force feature-dirty[24m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_continues_dirty_background.snap b/tests/snapshots/integration__integration_tests__remove__remove_continues_dirty_background.snapindex 5b0ae7f0b..3a1c3c61c 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_continues_dirty_background.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_continues_dirty_background.snap@@ -7,7 +7,7 @@ expression: stderr[0m[36m◎[39m [36mRemoving [1mfailed-a[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m[31m✗[39m [31mCannot remove worktree: [1mfailed-a[22m has uncommitted changes[39m[107m [0m ?? dirty.txt-[2m↳[22m [2mCommit or stash changes first, or to lose uncommitted changes, run [4mwt remove --force failed-a[24m[22m+[2m↳[22m [2mCommit or run [4mgit stash -u[24m in the dirty worktree first, or to lose uncommitted changes, run [4mwt remove --force failed-a[24m[22m[36m◎[39m [36mRunning pre-remove project hook @ [1m_REPO_.valid[22m[39m[107m [0m [2m[0m[2m[35mcase[0m[2m [0m[2m[32m'valid'[0m[2m [0m[2m[35min[0m[2m failed-*) [0m[2m[34mprintf[0m[2m uncommitted [0m[2m[36m>[0m[2m dirty.txt ;; [0m[2m[35mesac[0m[0m[36m◎[39m [36mRemoving [1mvalid[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m@@ -16,7 +16,7 @@ expression: stderr[0m[36m◎[39m [36mRemoving [1mfailed-b[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m[31m✗[39m [31mCannot remove worktree: [1mfailed-b[22m has uncommitted changes[39m[107m [0m ?? dirty.txt-[2m↳[22m [2mCommit or stash changes first, or to lose uncommitted changes, run [4mwt remove --force failed-b[24m[22m+[2m↳[22m [2mCommit or run [4mgit stash -u[24m in the dirty worktree first, or to lose uncommitted changes, run [4mwt remove --force failed-b[24m[22m[2m○[22m No worktree found for branch [1mbranch-only[22m[32m✓ Removed branch [1mbranch-only[22m (same commit as [1mmain[22m,[39m [2m_[22m[32m)[39m[36m◎[39m [36mRunning pre-remove project hook[39mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_force_with_force_delete.snap b/tests/snapshots/integration__integration_tests__remove__remove_force_with_force_delete.snapindex 24afa5999..c01d03827 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_force_with_force_delete.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_force_with_force_delete.snap@@ -62,3 +62,5 @@ exit_code: 0----- stderr -----[36m◎[39m [36mRemoving [1mfeature-dirty-unmerged[22m worktree (--force) & branch in background (--force-delete)[39m+[33m▲[39m [33mDiscarding uncommitted changes (--force):[39m+[107m [0m ?? untracked.txtdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap b/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snapindex 0976e0dd2..c0f03e16c 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap@@ -62,3 +62,5 @@ exit_code: 0----- stderr -----[36m◎[39m [36mRemoving [1mfeature-modified[22m worktree (--force) in background[39m[2m↳[22m [2mBranch unmerged; to delete, run [4mwt remove -D feature-modified[24m[22m+[33m▲[39m [33mDiscarding uncommitted changes (--force):[39m+[107m [0m M tracked.txtdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_force_with_staged_files.snap b/tests/snapshots/integration__integration_tests__remove__remove_force_with_staged_files.snapindex 2b5af403b..eda9f4ef1 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_force_with_staged_files.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_force_with_staged_files.snap@@ -61,3 +61,5 @@ exit_code: 0----- stderr -----[36m◎[39m [36mRemoving [1mfeature-staged[22m worktree (--force) & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m+[33m▲[39m [33mDiscarding uncommitted changes (--force):[39m+[107m [0m A staged.txtdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_force_with_untracked_files.snap b/tests/snapshots/integration__integration_tests__remove__remove_force_with_untracked_files.snapindex 0f3254805..9cb4da38c 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_force_with_untracked_files.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_force_with_untracked_files.snap@@ -61,3 +61,5 @@ exit_code: 0----- stderr -----[36m◎[39m [36mRemoving [1mfeature-untracked[22m worktree (--force) & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m+[33m▲[39m [33mDiscarding uncommitted changes (--force):[39m+[107m [0m ?? devbox.lockdiff --git a/tests/snapshots/integration__integration_tests__step_promote__promote_dirty_main.snap b/tests/snapshots/integration__integration_tests__step_promote__promote_dirty_main.snapindex 00bdbe94c..a68fb905b 100644--- a/tests/snapshots/integration__integration_tests__step_promote__promote_dirty_main.snap+++ b/tests/snapshots/integration__integration_tests__step_promote__promote_dirty_main.snap@@ -62,4 +62,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot promote: [1mmain[22m has uncommitted changes[39m[107m [0m ?? dirty.txt-[2m↳[22m [2mCommit or stash changes first[22m+[2m↳[22m [2mCommit or run [4mgit stash -u[24m in the dirty worktree first[22mdiff --git a/tests/snapshots/integration__integration_tests__step_promote__promote_dirty_target.snap b/tests/snapshots/integration__integration_tests__step_promote__promote_dirty_target.snapindex 60fb56995..76d35fdfb 100644--- a/tests/snapshots/integration__integration_tests__step_promote__promote_dirty_target.snap+++ b/tests/snapshots/integration__integration_tests__step_promote__promote_dirty_target.snap@@ -62,4 +62,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot promote: [1mfeature[22m has uncommitted changes[39m[107m [0m ?? dirty.txt-[2m↳[22m [2mCommit or stash changes first[22m+[2m↳[22m [2mCommit or run [4mgit stash -u[24m in the dirty worktree first[22mdiff --git a/tests/snapshots/integration__integration_tests__user_hooks__merge_post_commit_worktree_kept.snap b/tests/snapshots/integration__integration_tests__user_hooks__merge_post_commit_worktree_kept.snapindex f3d30f476..de67ce959 100644--- a/tests/snapshots/integration__integration_tests__user_hooks__merge_post_commit_worktree_kept.snap+++ b/tests/snapshots/integration__integration_tests__user_hooks__merge_post_commit_worktree_kept.snap@@ -64,7 +64,8 @@ exit_code: 0[33m▲[39m [33mAuto-staging 1 untracked path:[39m[107m [0m dirty.txt[36m◎[39m [36mSquashing 1 commit & working tree changes into a single commit [90m(2 files, [32m+2[39m[39m[90m)[39m...[39m-[2m↳[22m [2mBackup created @ 874aee4[22m+[2m↳[22m [2mBackup created @ [4mrefs/wt-backup/feature[24m (874aee4)[22m+[2m↳[22m [2mTo recover in a new worktree, run [4mwt switch --create --base 874aee4a329ef4a3a76b091e5d04f2b9ee5f33a5 --no-hooks recovery/874aee4[24m[22m[36m◎[39m [36mGenerating squash commit message...[39m[2m↳[22m [2mUsing fallback commit message. For LLM setup guide, run [4mwt config --help[24m[22m[107m [0m [1mSquash commits from feature[22mdiff --git a/tests/snapshots/integration__integration_tests__user_hooks__merge_post_commit_worktree_removed.snap b/tests/snapshots/integration__integration_tests__user_hooks__merge_post_commit_worktree_removed.snapindex 076319ade..16d4b405b 100644--- a/tests/snapshots/integration__integration_tests__user_hooks__merge_post_commit_worktree_removed.snap+++ b/tests/snapshots/integration__integration_tests__user_hooks__merge_post_commit_worktree_removed.snap@@ -63,7 +63,8 @@ exit_code: 0[33m▲[39m [33mAuto-staging 1 untracked path:[39m[107m [0m dirty.txt[36m◎[39m [36mSquashing 1 commit & working tree changes into a single commit [90m(2 files, [32m+2[39m[39m[90m)[39m...[39m-[2m↳[22m [2mBackup created @ 874aee4[22m+[2m↳[22m [2mBackup created @ [4mrefs/wt-backup/feature[24m (874aee4)[22m+[2m↳[22m [2mTo recover in a new worktree, run [4mwt switch --create --base 874aee4a329ef4a3a76b091e5d04f2b9ee5f33a5 --no-hooks recovery/874aee4[24m[22m[36m◎[39m [36mGenerating squash commit message...[39m[2m↳[22m [2mUsing fallback commit message. For LLM setup guide, run [4mwt config --help[24m[22m[107m [0m [1mSquash commits from feature[22m