Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

docs: Remove shell integration section from README

Maximilian Roosbf02881d5d80
diff --git a/CLAUDE.md b/CLAUDE.md
index e26c7ec50..e535e8e19 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -147,12 +147,10 @@ Use consistent punctuation and structure for related messages:
**Parallel structure:** Related messages should follow the same pattern:
```rust
-// ✅ GOOD - parallel structure distinguishes context and integration reason
-// After wt merge: show integration reason with target in parentheses
-"Removing feature worktree & branch in background (ancestor of main)" // Traditional merge (ancestor)
-"Removing feature worktree & branch in background (contents match main)" // Squash/rebase (tree SHA matches)
-// Explicit wt remove: no parenthetical needed, user requested it
-"Removing feature worktree & branch in background" // Explicit remove
+// ✅ GOOD - parallel structure with integration reason explaining branch deletion
+// Both wt merge and wt remove show integration reason when branch is deleted
+"Removing feature worktree & branch in background (ancestor of main)" // Branch is integrated (ancestor)
+"Removing feature worktree & branch in background (contents match main)" // Branch is integrated (squash/rebase)
"Removing feature worktree in background; retaining unmerged branch" // Unmerged (system keeps)
"Removing feature worktree in background; retaining branch (--no-delete-branch)" // User flag (user keeps)
```
diff --git a/README.md b/README.md
index 5da9c95cb..5ac9cd7c5 100644
--- a/README.md
+++ b/README.md
@@ -105,7 +105,7 @@ Say we merged via CI, our changes are on main, and we're finished with the workt
```console
$ wt remove
-🔄 Removing feature-api worktree & branch in background
+🔄 Removing feature-api worktree & branch in background (ancestor of main)
```
<!-- END AUTO-GENERATED -->
diff --git a/src/commands/repository_ext.rs b/src/commands/repository_ext.rs
index 085d79f7c..15a3081fc 100644
--- a/src/commands/repository_ext.rs
+++ b/src/commands/repository_ext.rs
@@ -111,6 +111,11 @@ impl RepositoryCliExt for Repository {
let current_worktree = self.worktree_root()?;
let removing_current = current_worktree == worktree_path;
+ // Cannot remove the main working tree (only linked worktrees can be removed)
+ if removing_current && !self.is_in_worktree()? {
+ return Err(GitError::CannotRemoveMainWorktree.into());
+ }
+
let (main_path, changed_directory) = if removing_current {
let worktrees = self.list_worktrees()?;
(worktrees.main().path.clone(), true)
@@ -118,6 +123,14 @@ impl RepositoryCliExt for Repository {
(current_worktree, false)
};
+ // Resolve default branch for integration reason display
+ // Skip if removing the default branch itself (avoids tautological "main (ancestor of main)")
+ let default_branch = self.default_branch().ok();
+ let target_branch = match &default_branch {
+ Some(db) if db == branch_name => None,
+ _ => default_branch,
+ };
+
Ok(RemoveResult::RemovedWorktree {
main_path,
worktree_path,
@@ -125,7 +138,7 @@ impl RepositoryCliExt for Repository {
branch_name: Some(branch_name.to_string()),
no_delete_branch,
force_delete,
- target_branch: None,
+ target_branch,
})
}
@@ -134,6 +147,11 @@ impl RepositoryCliExt for Repository {
no_delete_branch: bool,
force_delete: bool,
) -> anyhow::Result<RemoveResult> {
+ // Cannot remove the main working tree (only linked worktrees can be removed)
+ if !self.is_in_worktree()? {
+ return Err(GitError::CannotRemoveMainWorktree.into());
+ }
+
// Get current worktree path
let current_path = self.worktree_root()?;
@@ -153,6 +171,14 @@ impl RepositoryCliExt for Repository {
// Get main worktree path (we're removing current, so we'll cd to main)
let main_path = worktrees.main().path.clone();
+ // Resolve default branch for integration reason display
+ // Skip if removing the default branch itself (avoids tautological "main (ancestor of main)")
+ let default_branch = self.default_branch().ok();
+ let target_branch = match (&default_branch, &branch_name) {
+ (Some(db), Some(bn)) if db == bn => None,
+ _ => default_branch,
+ };
+
Ok(RemoveResult::RemovedWorktree {
main_path,
worktree_path: current_path,
@@ -160,7 +186,7 @@ impl RepositoryCliExt for Repository {
branch_name,
no_delete_branch,
force_delete,
- target_branch: None,
+ target_branch,
})
}
diff --git a/src/git/error.rs b/src/git/error.rs
index 9824810ea..4d1377aaa 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -80,6 +80,7 @@ pub enum GitError {
path: PathBuf,
error: String,
},
+ CannotRemoveMainWorktree,
// Merge/push errors
ConflictingChanges {
@@ -238,6 +239,13 @@ impl std::fmt::Display for GitError {
write!(f, "{}", format_error_block(header, error))
}
+ GitError::CannotRemoveMainWorktree => {
+ cwrite!(
+ f,
+ "{ERROR_EMOJI} <red>The main worktree cannot be removed</>"
+ )
+ }
+
GitError::ConflictingChanges {
files,
worktree_path,
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 5e7545c85..507b54fb4 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -159,14 +159,14 @@ fn get_flag_note(
} else if force_delete && deletion_result.is_some() {
" (--force-delete)".to_string()
} else if let Some(target) = target_branch {
- // After wt merge: show specific integration reason with target
+ // Show integration reason when branch is deleted (both wt merge and wt remove)
match deletion_result {
Some(Some(IntegrationReason::Merged)) => format!(" (ancestor of {target})"),
Some(Some(IntegrationReason::ContentsMatch)) => format!(" (contents match {target})"),
Some(None) | None => String::new(),
}
} else {
- // Explicit wt remove: no reason needed, user requested it
+ // No target branch available (e.g., couldn't resolve default branch)
String::new()
}
}
@@ -186,13 +186,6 @@ fn format_remove_worktree_message(
deletion_result: Option<Option<IntegrationReason>>,
target_branch: Option<&str>,
) -> String {
- // Build the action description based on actual outcome
- let action = if no_delete_branch || deletion_result.is_none() {
- "Removed worktree"
- } else {
- "Removed worktree & branch"
- };
-
// Show flag acknowledgment when applicable
let flag_note = get_flag_note(
no_delete_branch,
@@ -202,21 +195,29 @@ fn format_remove_worktree_message(
);
let branch_display = branch.or(Some(branch_name));
-
let path_display = format_path_for_display(main_path);
+ // Build message parallel to background format: "Removed {branch} worktree & branch{flag_note}"
+ let action_suffix = if no_delete_branch || deletion_result.is_none() {
+ "worktree"
+ } else {
+ "worktree & branch"
+ };
+
if changed_directory {
if let Some(b) = branch_display {
cformat!(
- "<green>{action} for <bold>{b}</>, changed directory to <bold>{path_display}</>{flag_note}</>"
+ "<green>Removed <bold>{b}</> {action_suffix}; changed directory to <bold>{path_display}</>{flag_note}</>"
)
} else {
- cformat!("<green>{action}, changed directory to <bold>{path_display}</>{flag_note}</>")
+ cformat!(
+ "<green>Removed {action_suffix}; changed directory to <bold>{path_display}</>{flag_note}</>"
+ )
}
} else if let Some(b) = branch_display {
- cformat!("<green>{action} for <bold>{b}</>{flag_note}</>")
+ cformat!("<green>Removed <bold>{b}</> {action_suffix}{flag_note}</>")
} else {
- cformat!("<green>{action}{flag_note}</>")
+ cformat!("<green>Removed {action_suffix}{flag_note}</>")
}
}
diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rs
index 7f6a09680..37050255b 100644
--- a/tests/integration_tests/directives.rs
+++ b/tests/integration_tests/directives.rs
@@ -85,13 +85,12 @@ fn test_remove_internal_directive() {
.current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r"
- success: true
- exit_code: 0
+ success: false
+ exit_code: 1
----- stdout -----
- cd '[PATH]'
----- stderr -----
- 🔄 Removing main worktree & branch in background
+ ❌ The main worktree cannot be removed
");
});
}
@@ -111,12 +110,12 @@ fn test_remove_without_internal() {
cmd.arg("remove").current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r"
- success: true
- exit_code: 0
+ success: false
+ exit_code: 1
----- stdout -----
----- stderr -----
- 🔄 Removing main worktree & branch in background
+ ❌ The main worktree cannot be removed
");
});
}
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index ff9d42bc7..cc20f741e 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -1,6 +1,11 @@
-use crate::common::{TestRepo, make_snapshot_cmd_with_global_flags, setup_snapshot_settings};
+use crate::common::{
+ TestRepo, make_snapshot_cmd_with_global_flags, setup_snapshot_settings,
+ setup_temp_snapshot_settings, wt_command,
+};
use insta_cmd::assert_cmd_snapshot;
+use std::path::PathBuf;
use std::process::Command;
+use tempfile::TempDir;
/// Helper to create snapshot with normalized paths
fn snapshot_remove(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&std::path::Path>) {
@@ -447,3 +452,173 @@ fn test_remove_branch_matching_tree_content() {
None,
);
}
+/// Test the explicit difference between removing main worktree (error) vs linked worktree (success).
+///
+/// This test documents the expected behavior:
+/// 1. Linked worktrees can be removed (whether from within them or from elsewhere)
+/// 2. The main worktree cannot be removed under any circumstances
+/// 3. This is true regardless of which branch is checked out in the main worktree
+#[test]
+fn test_remove_main_worktree_vs_linked_worktree() {
+ let mut repo = setup_remove_repo();
+
+ // Create a linked worktree
+ let linked_wt_path = repo.add_worktree("feature");
+
+ // Part 1: Verify linked worktree CAN be removed (from within it)
+ snapshot_remove(
+ "remove_main_vs_linked__from_linked_succeeds",
+ &repo,
+ &[],
+ Some(&linked_wt_path),
+ );
+
+ // Part 2: Recreate the linked worktree for the next test
+ let _linked_wt_path = repo.add_worktree("feature2");
+
+ // Part 3: Verify linked worktree CAN be removed (from main, by name)
+ snapshot_remove(
+ "remove_main_vs_linked__from_main_by_name_succeeds",
+ &repo,
+ &["feature2"],
+ None,
+ );
+
+ // Part 4: Verify main worktree CANNOT be removed (from main, on default branch)
+ snapshot_remove(
+ "remove_main_vs_linked__main_on_default_fails",
+ &repo,
+ &[],
+ None,
+ );
+
+ // Part 5: Create a feature branch IN the main worktree, verify STILL cannot remove
+ let mut cmd = std::process::Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["switch", "-c", "feature-in-main"])
+ .current_dir(repo.root_path())
+ .output()
+ .unwrap();
+
+ snapshot_remove(
+ "remove_main_vs_linked__main_on_feature_fails",
+ &repo,
+ &[],
+ None,
+ );
+}
+
+/// Test that removing a worktree for the default branch doesn't show tautological reason.
+///
+/// When removing a worktree for "main" branch, we should NOT show "(ancestor of main)"
+/// because that would be tautological. The message should just be "Removed main worktree & branch".
+///
+/// This requires a bare repo setup since you can't have a linked worktree for the default
+/// branch in a normal repo (the main worktree already has it checked out).
+#[test]
+fn test_remove_default_branch_no_tautology() {
+ // Create bare repository
+ let temp_dir = TempDir::new().unwrap();
+ let bare_repo_path = temp_dir.path().join("repo.git");
+ let test_config_path = temp_dir.path().join("test-config.toml");
+
+ let output = Command::new("git")
+ .args(["init", "--bare", "--initial-branch", "main"])
+ .current_dir(temp_dir.path())
+ .arg(&bare_repo_path)
+ .env("GIT_CONFIG_GLOBAL", "/dev/null")
+ .env("GIT_CONFIG_SYSTEM", "/dev/null")
+ .output()
+ .unwrap();
+ assert!(output.status.success(), "Failed to init bare repo");
+
+ let bare_repo_path: PathBuf = bare_repo_path.canonicalize().unwrap();
+
+ // Create worktree for main branch
+ let main_worktree = temp_dir.path().join("repo.main");
+ let output = Command::new("git")
+ .args([
+ "-C",
+ bare_repo_path.to_str().unwrap(),
+ "worktree",
+ "add",
+ "-b",
+ "main",
+ main_worktree.to_str().unwrap(),
+ ])
+ .env("GIT_CONFIG_GLOBAL", "/dev/null")
+ .env("GIT_CONFIG_SYSTEM", "/dev/null")
+ .env("GIT_AUTHOR_DATE", "2025-01-01T00:00:00Z")
+ .env("GIT_COMMITTER_DATE", "2025-01-01T00:00:00Z")
+ .output()
+ .unwrap();
+ assert!(output.status.success(), "Failed to create main worktree");
+
+ let main_worktree = main_worktree.canonicalize().unwrap();
+
+ // Create initial commit in main worktree
+ std::fs::write(main_worktree.join("file.txt"), "initial").unwrap();
+ let output = Command::new("git")
+ .args(["add", "file.txt"])
+ .current_dir(&main_worktree)
+ .env("GIT_CONFIG_GLOBAL", "/dev/null")
+ .env("GIT_CONFIG_SYSTEM", "/dev/null")
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ let output = Command::new("git")
+ .args(["commit", "-m", "Initial commit"])
+ .current_dir(&main_worktree)
+ .env("GIT_CONFIG_GLOBAL", "/dev/null")
+ .env("GIT_CONFIG_SYSTEM", "/dev/null")
+ .env("GIT_AUTHOR_NAME", "Test User")
+ .env("GIT_AUTHOR_EMAIL", "[email protected]")
+ .env("GIT_AUTHOR_DATE", "2025-01-01T00:00:00Z")
+ .env("GIT_COMMITTER_NAME", "Test User")
+ .env("GIT_COMMITTER_EMAIL", "[email protected]")
+ .env("GIT_COMMITTER_DATE", "2025-01-01T00:00:00Z")
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+
+ // Create a second worktree (feature) so we have somewhere to run remove from
+ let feature_worktree = temp_dir.path().join("repo.feature");
+ let output = Command::new("git")
+ .args([
+ "-C",
+ bare_repo_path.to_str().unwrap(),
+ "worktree",
+ "add",
+ "-b",
+ "feature",
+ feature_worktree.to_str().unwrap(),
+ ])
+ .env("GIT_CONFIG_GLOBAL", "/dev/null")
+ .env("GIT_CONFIG_SYSTEM", "/dev/null")
+ .env("GIT_AUTHOR_DATE", "2025-01-01T00:00:00Z")
+ .env("GIT_COMMITTER_DATE", "2025-01-01T00:00:00Z")
+ .output()
+ .unwrap();
+ assert!(output.status.success(), "Failed to create feature worktree");
+
+ let feature_worktree = feature_worktree.canonicalize().unwrap();
+
+ // Remove main worktree by name from feature worktree (foreground for snapshot)
+ // Should NOT show "(ancestor of main)" - that would be tautological
+ let settings = setup_temp_snapshot_settings(temp_dir.path());
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ cmd.args(["remove", "--no-background", "main"])
+ .current_dir(&feature_worktree)
+ .env("WORKTRUNK_CONFIG_PATH", test_config_path.to_str().unwrap())
+ .env("GIT_CONFIG_GLOBAL", "/dev/null")
+ .env("GIT_CONFIG_SYSTEM", "/dev/null")
+ .env("GIT_AUTHOR_DATE", "2025-01-01T00:00:00Z")
+ .env("GIT_COMMITTER_DATE", "2025-01-01T00:00:00Z")
+ .env("GIT_EDITOR", "")
+ .env("LANG", "C")
+ .env("LC_ALL", "C");
+
+ assert_cmd_snapshot!("remove_default_branch_no_tautology", cmd);
+ });
+}
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_remove.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_remove.snap
index 12beee43f..a2b3ef609 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_remove.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_remove.snap
@@ -1,6 +1,5 @@
---
source: tests/integration_tests/shell_wrapper.rs
-assertion_line: 1362
expression: output.normalized()
---
-🔄 Removing feature-api worktree & branch in background
+🔄 Removing feature-api worktree & branch in background (ancestor of main)
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove.snap
index 83f3dfa9e..3d2a05d59 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-🔄 Removing to-remove worktree & branch in background
+🔄 Removing to-remove worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_already_on_default.snap b/tests/snapshots/integration__integration_tests__remove__remove_already_on_default.snap
index cb34bd4f4..22375f771 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_already_on_default.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_already_on_default.snap
@@ -18,9 +18,9 @@ info:
WORKTRUNK_BIN: ""
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
-success: true
-exit_code: 0
+success: false
+exit_code: 1
----- stdout -----
----- stderr -----
-🔄 Removing main worktree & branch in background
+❌ The main worktree cannot be removed
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap
index 2ec2b7b12..53fb4b346 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap
@@ -24,4 +24,4 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Removing feature-a worktree & branch in background
+🔄 Removing feature-a worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap
index 091bb4497..e16f99f05 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap
@@ -24,4 +24,4 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Removing feature-b worktree & branch in background
+🔄 Removing feature-b worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_current_by_name.snap b/tests/snapshots/integration__integration_tests__remove__remove_current_by_name.snap
index 641b1cf53..fe234b7f6 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_current_by_name.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_current_by_name.snap
@@ -24,4 +24,4 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Removing feature-current worktree & branch in background
+🔄 Removing feature-current worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_default_branch_no_tautology.snap b/tests/snapshots/integration__integration_tests__remove__remove_default_branch_no_tautology.snap
new file mode 100644
index 000000000..145e950ea
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__remove__remove_default_branch_no_tautology.snap
@@ -0,0 +1,29 @@
+---
+source: tests/integration_tests/remove.rs
+info:
+ program: wt
+ args:
+ - remove
+ - "--no-background"
+ - main
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_BIN: ""
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Removing worktree for main...
+✅ Removed main worktree & branch
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_dirty_working_tree.snap b/tests/snapshots/integration__integration_tests__remove__remove_dirty_working_tree.snap
index fb3e9bca6..22375f771 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_dirty_working_tree.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_dirty_working_tree.snap
@@ -23,6 +23,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-❌ Cannot remove worktree: working tree has uncommitted changes
-
-💡 Commit or stash them first
+❌ The main worktree cannot be removed
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_foreground.snap b/tests/snapshots/integration__integration_tests__remove__remove_foreground.snap
index 0e8011760..de378ddd7 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_foreground.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_foreground.snap
@@ -26,4 +26,4 @@ exit_code: 0
----- stderr -----
🔄 Removing worktree for feature-fg...
-✅ Removed worktree & branch for feature-fg
+✅ Removed feature-fg worktree & branch (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap
index 7c2ff31e6..281649e60 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap
@@ -23,4 +23,4 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Removing feature-wt worktree & branch in background
+🔄 Removing feature-wt worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap b/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap
index baa0521bc..a4c926a28 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap
@@ -25,4 +25,4 @@ exit_code: 0
cd '[REPO]'
----- stderr -----
-🔄 Removing feature-internal worktree & branch in background
+🔄 Removing feature-internal worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_linked_succeeds.snap b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_linked_succeeds.snap
new file mode 100644
index 000000000..548aedb41
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_linked_succeeds.snap
@@ -0,0 +1,26 @@
+---
+source: tests/integration_tests/remove.rs
+info:
+ program: wt
+ args:
+ - remove
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_BIN: ""
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Removing feature worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_main_by_name_succeeds.snap b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_main_by_name_succeeds.snap
new file mode 100644
index 000000000..dbd04ddc2
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_main_by_name_succeeds.snap
@@ -0,0 +1,27 @@
+---
+source: tests/integration_tests/remove.rs
+info:
+ program: wt
+ args:
+ - remove
+ - feature2
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_BIN: ""
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Removing feature2 worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__main_on_default_fails.snap b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__main_on_default_fails.snap
new file mode 100644
index 000000000..22375f771
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__main_on_default_fails.snap
@@ -0,0 +1,26 @@
+---
+source: tests/integration_tests/remove.rs
+info:
+ program: wt
+ args:
+ - remove
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_BIN: ""
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+❌ The main worktree cannot be removed
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__main_on_feature_fails.snap b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__main_on_feature_fails.snap
new file mode 100644
index 000000000..22375f771
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__main_on_feature_fails.snap
@@ -0,0 +1,26 @@
+---
+source: tests/integration_tests/remove.rs
+info:
+ program: wt
+ args:
+ - remove
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_BIN: ""
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+❌ The main worktree cannot be removed
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap b/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap
index 39d7fbb96..60fe098fb 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap
@@ -26,6 +26,6 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Removing feature-b worktree & branch in background
-🔄 Removing feature-c worktree & branch in background
-🔄 Removing feature-a worktree & branch in background
+🔄 Removing feature-b worktree & branch in background (ancestor of main)
+🔄 Removing feature-c worktree & branch in background (ancestor of main)
+🔄 Removing feature-a worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap b/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap
index 04ad2c312..e59137c72 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap
@@ -26,6 +26,6 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Removing feature-a worktree & branch in background
-🔄 Removing feature-b worktree & branch in background
-🔄 Removing feature-c worktree & branch in background
+🔄 Removing feature-a worktree & branch in background (ancestor of main)
+🔄 Removing feature-b worktree & branch in background (ancestor of main)
+🔄 Removing feature-c worktree & branch in background (ancestor of main)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_switch_to_default.snap b/tests/snapshots/integration__integration_tests__remove__remove_switch_to_default.snap
index efca7970d..22375f771 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_switch_to_default.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_switch_to_default.snap
@@ -18,9 +18,9 @@ info:
WORKTRUNK_BIN: ""
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
-success: true
-exit_code: 0
+success: false
+exit_code: 1
----- stdout -----
----- stderr -----
-🔄 Removing feature worktree & branch in background
+❌ The main worktree cannot be removed