Skip to content

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

feat: Consistent remove messages

Maximilian Roos97e8f221b72a
diff --git a/CLAUDE.md b/CLAUDE.md
index 405d4a0d4..3b96e9d31 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -74,6 +74,53 @@ Output messages should acknowledge user-supplied arguments (flags, options, valu
"Committing with default message... (3 files, +45, -12)"
```
+### Message Consistency Patterns
+
+Use consistent punctuation and structure for related messages:
+
+**Semicolon for qualifiers:** Separate the action from a qualifier/reason:
+```rust
+// Action; qualifier (flag)
+"Removing feature in background; retaining branch (--no-delete-branch)"
+"Commands approved; not saved (--force)"
+```
+
+**Ampersand for conjunctions:** Use `&` for combined actions:
+```rust
+// Action & additional action
+"Removing feature & branch in background"
+"Commands approved & saved to config"
+```
+
+**Explicit flag acknowledgment:** Show flags in parentheses when they change behavior:
+```rust
+// ✅ GOOD - shows the flag explicitly
+"Removing feature in background; retaining branch (--no-delete-branch)"
+// ❌ BAD - doesn't acknowledge user's explicit choice
+"Removing feature in background; retaining branch"
+```
+
+**Parallel structure:** Related messages should follow the same pattern:
+```rust
+// ✅ GOOD - parallel structure distinguishes user choice from system decision
+"Removing feature & branch in background" // Merged (will delete)
+"Removing feature in background; retaining unmerged branch" // Unmerged (system keeps)
+"Removing feature in background; retaining branch (--no-delete-branch)" // User flag (user keeps)
+```
+
+**Compute decisions once:** For background operations, check conditions upfront, show the message, then pass the decision explicitly rather than re-checking in background scripts:
+```rust
+// ✅ GOOD - check once, pass decision
+let should_delete = check_if_merged();
+show_message_based_on(should_delete);
+spawn_background(build_command(should_delete));
+
+// ❌ BAD - check twice (once for message, again in background script)
+let is_merged = check_if_merged();
+show_message_based_on(is_merged);
+spawn_background(build_command_that_checks_merge_again()); // Duplicate check!
+```
+
### The anstyle Ecosystem
All styling uses the **anstyle ecosystem** for composable, auto-detecting terminal output:
diff --git a/src/commands/standalone.rs b/src/commands/standalone.rs
index 650c75f45..2681949b8 100644
--- a/src/commands/standalone.rs
+++ b/src/commands/standalone.rs
@@ -360,12 +360,12 @@ pub fn handle_standalone_ask_approvals(force: bool, show_all: bool) -> Result<()
if force {
// When using --force, commands aren't saved to config
crate::output::success(format!(
- "{GREEN}Commands approved (not saved with --force){GREEN:#}"
+ "{GREEN}Commands approved; not saved (--force){GREEN:#}"
))?;
} else {
// Interactive approval - commands were saved to config (unless save failed)
crate::output::success(format!(
- "{GREEN}Commands approved and saved to config{GREEN:#}"
+ "{GREEN}Commands approved & saved to config{GREEN:#}"
))?;
}
} else {
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index e24548511..90da7adae 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -135,35 +135,28 @@ pub fn execute_user_command(command: &str) -> Result<(), GitError> {
/// Build shell command for background worktree removal
///
-/// Constructs a command that:
-/// 1. Removes the worktree using `git worktree remove`
-/// 2. Conditionally deletes the branch if it's fully merged
-///
-/// The command replicates the same safety checks done in handle_remove_output:
-/// - Uses `git merge-base --is-ancestor` to check if branch is merged
-/// - Only deletes with `-D` if the branch is an ancestor of the target
+/// `should_delete_branch` indicates whether to delete the branch after removing the worktree.
+/// This decision is computed upfront (checking if branch is merged) before spawning the background process.
fn build_remove_command(
worktree_path: &std::path::Path,
branch_name: &str,
- no_delete_branch: bool,
- target_branch: &str,
+ should_delete_branch: bool,
) -> String {
use shell_escape::escape;
let worktree_path_str = worktree_path.to_string_lossy();
let worktree_escaped = escape(worktree_path_str.as_ref().into());
let branch_escaped = escape(branch_name.into());
- let target_escaped = escape(target_branch.into());
- if no_delete_branch {
- // Just remove the worktree
- format!("git worktree remove {}", worktree_escaped)
- } else {
- // Remove worktree and conditionally delete branch if merged
+ if should_delete_branch {
+ // Remove worktree and delete branch
format!(
- "git worktree remove {} && if git merge-base --is-ancestor {} {}; then git branch -D {}; fi",
- worktree_escaped, branch_escaped, target_escaped, branch_escaped
+ "git worktree remove {} && git branch -D {}",
+ worktree_escaped, branch_escaped
)
+ } else {
+ // Just remove the worktree
+ format!("git worktree remove {}", worktree_escaped)
}
}
@@ -193,14 +186,37 @@ pub fn handle_remove_output(
if background {
// Background mode: spawn detached process
- let check_target = target_branch.as_deref().unwrap_or("HEAD");
- let remove_command =
- build_remove_command(worktree_path, branch_name, *no_delete_branch, check_target);
-
- // Show simple progress message (log location documented in --help)
- super::progress(format!(
- "{CYAN}Removing {CYAN_BOLD}{branch_name}{CYAN_BOLD:#}{CYAN} in background{CYAN:#}"
- ))?;
+
+ // Determine if we should delete the branch (check once upfront)
+ let should_delete_branch = if *no_delete_branch {
+ false
+ } else {
+ // Check if branch is fully merged to target
+ let check_target = target_branch.as_deref().unwrap_or("HEAD");
+ let deletion_repo = worktrunk::git::Repository::at(primary_path);
+ deletion_repo
+ .run_command(&["merge-base", "--is-ancestor", branch_name, check_target])
+ .is_ok()
+ };
+
+ // Show progress message based on what we'll do
+ let action = if *no_delete_branch {
+ format!(
+ "{CYAN}Removing {CYAN_BOLD}{branch_name}{CYAN_BOLD:#}{CYAN} in background; retaining branch (--no-delete-branch){CYAN:#}"
+ )
+ } else if should_delete_branch {
+ format!(
+ "{CYAN}Removing {CYAN_BOLD}{branch_name}{CYAN_BOLD:#}{CYAN} & branch in background{CYAN:#}"
+ )
+ } else {
+ format!(
+ "{CYAN}Removing {CYAN_BOLD}{branch_name}{CYAN_BOLD:#}{CYAN} in background; retaining unmerged branch{CYAN:#}"
+ )
+ };
+ super::progress(action)?;
+
+ // Build command with the decision we already made
+ let remove_command = build_remove_command(worktree_path, branch_name, should_delete_branch);
// Spawn the removal in background - runs from primary_path (where we cd'd to)
spawn_detached(&repo, primary_path, &remove_command, branch_name, "remove")?;
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index 11275c38c..178902f86 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -259,3 +259,21 @@ fn test_remove_foreground() {
None,
);
}
+
+#[test]
+fn test_remove_no_delete_branch() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create a worktree
+ let _worktree_path = repo.add_worktree("feature-keep", "feature-keep");
+
+ // Remove worktree but keep the branch using --no-delete-branch flag
+ snapshot_remove(
+ "remove_no_delete_branch",
+ &repo,
+ &["--no-delete-branch", "feature-keep"],
+ None,
+ );
+}
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 b659c4230..0ab13a9ff 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 in background
+🔄 Removing to-remove & branch in background
diff --git a/tests/snapshots/integration__integration_tests__approvals__ask_approvals_force.snap b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_force.snap
index 6e17d8250..b845948e9 100644
--- a/tests/snapshots/integration__integration_tests__approvals__ask_approvals_force.snap
+++ b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_force.snap
@@ -1,6 +1,5 @@
---
source: tests/integration_tests/approvals.rs
-assertion_line: 12
info:
program: wt
args:
@@ -18,11 +17,11 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpQPV1jE/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpQUcoV5/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-✅ Commands approved (not saved with --force)
+✅ Commands approved; not saved (--force)
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap b/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap
index fabca61ce..aae1c3d1d 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap
@@ -16,11 +16,11 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpBVXg8X/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpaG3hNH/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-🔄 Removing feature-unmerged in background
+🔄 Removing feature-unmerged in background; retaining unmerged branch
----- stderr -----
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 b06950ba0..9a20479a4 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
@@ -16,11 +16,11 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpikdoOB/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpNwTy5B/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-🔄 Removing feature-a in background
+🔄 Removing feature-a & branch in background
----- stderr -----
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 51515b3ba..8ba41e45a 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
@@ -16,11 +16,11 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpSaCcYh/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp9E4JlY/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-🔄 Removing feature-b in background
+🔄 Removing feature-b & branch in background
----- stderr -----
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 3358520e7..5a51151c4 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
@@ -16,11 +16,11 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpIA71vF/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp5q6eV3/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-🔄 Removing feature-current in background
+🔄 Removing feature-current & branch in background
----- stderr -----
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 65d237e6f..a5736daa8 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap
@@ -15,11 +15,11 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpscKTqw/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpRjatEC/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-🔄 Removing feature-wt in background
+🔄 Removing feature-wt & branch in background
----- stderr -----
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 9b9c8f883..bd9e871ef 100644
Binary files a/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap and b/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap differ
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 f0673802b..f3de901bb 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
@@ -18,13 +18,13 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpO7W9xY/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpl3mMRJ/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-🔄 Removing feature-b in background
-🔄 Removing feature-c in background
-🔄 Removing feature-a in background
+🔄 Removing feature-b & branch in background
+🔄 Removing feature-c & branch in background
+🔄 Removing feature-a & branch in background
----- stderr -----
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 a8f8b7f72..8f52e697f 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap
@@ -18,13 +18,13 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpCjU6VT/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpisVj0I/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-🔄 Removing feature-a in background
-🔄 Removing feature-b in background
-🔄 Removing feature-c in background
+🔄 Removing feature-a & branch in background
+🔄 Removing feature-b & branch in background
+🔄 Removing feature-c & branch in background
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_no_delete_branch.snap b/tests/snapshots/integration__integration_tests__remove__remove_no_delete_branch.snap
new file mode 100644
index 000000000..1ebe17dfc
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__remove__remove_no_delete_branch.snap
@@ -0,0 +1,27 @@
+---
+source: tests/integration_tests/remove.rs
+info:
+ program: wt
+ args:
+ - remove
+ - "--no-delete-branch"
+ - feature-keep
+ 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: /dev/null
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpCltw2x/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+🔄 Removing feature-keep in background; retaining branch (--no-delete-branch)
+
+----- stderr -----