Skip to content

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

fix(remove): show the delete-branch config override (#4615)

Worktrunk Bot2ab571273ead
diff --git a/docs/src/content/docs/remove.md b/docs/src/content/docs/remove.md
index b7deafcaa..372bd0c2a 100644
--- a/docs/src/content/docs/remove.md
+++ b/docs/src/content/docs/remove.md
@@ -34,6 +34,12 @@ Keep the branch:
$ wt remove --no-delete-branch feature-branch
```
+If `[remove] delete-branch = false` is configured, use `--delete-branch` to delete a branch for one removal:
+
+```console
+$ wt remove --delete-branch feature-branch
+```
+
Force-delete an unmerged branch:
```console
@@ -148,6 +154,9 @@ Options:
--no-delete-branch
Keep branch after removal
+ --delete-branch
+ Delete branch after removal (overrides config [remove] delete-branch = false)
+
-D, --force-delete
Delete unmerged branches
diff --git a/plugins/worktrunk/skills/worktrunk/reference/remove.md b/plugins/worktrunk/skills/worktrunk/reference/remove.md
index 062a1a51f..c8fbdbe34 100644
--- a/plugins/worktrunk/skills/worktrunk/reference/remove.md
+++ b/plugins/worktrunk/skills/worktrunk/reference/remove.md
@@ -28,6 +28,12 @@ Keep the branch:
$ wt remove --no-delete-branch feature-branch
```
+If `[remove] delete-branch = false` is configured, use `--delete-branch` to delete a branch for one removal:
+
+```console
+$ wt remove --delete-branch feature-branch
+```
+
Force-delete an unmerged branch:
```console
@@ -135,6 +141,9 @@ Options:
--no-delete-branch
Keep branch after removal
+ --delete-branch
+ Delete branch after removal (overrides config [remove] delete-branch = false)
+
-D, --force-delete
Delete unmerged branches
diff --git a/skills/worktrunk/reference/remove.md b/skills/worktrunk/reference/remove.md
index 062a1a51f..c8fbdbe34 100644
--- a/skills/worktrunk/reference/remove.md
+++ b/skills/worktrunk/reference/remove.md
@@ -28,6 +28,12 @@ Keep the branch:
$ wt remove --no-delete-branch feature-branch
```
+If `[remove] delete-branch = false` is configured, use `--delete-branch` to delete a branch for one removal:
+
+```console
+$ wt remove --delete-branch feature-branch
+```
+
Force-delete an unmerged branch:
```console
@@ -135,6 +141,9 @@ Options:
--no-delete-branch
Keep branch after removal
+ --delete-branch
+ Delete branch after removal (overrides config [remove] delete-branch = false)
+
-D, --force-delete
Delete unmerged branches
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index b6c3e3a00..b212acea5 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -501,11 +501,7 @@ pub(crate) struct RemoveArgs {
pub(crate) no_delete_branch: bool,
/// Delete branch after removal (overrides config `[remove] delete-branch = false`)
- #[arg(
- long = "delete-branch",
- overrides_with = "no_delete_branch",
- hide = true
- )]
+ #[arg(long = "delete-branch", overrides_with = "no_delete_branch")]
pub(crate) delete_branch: bool,
/// Delete unmerged branches
@@ -1331,6 +1327,12 @@ Keep the branch:
$ wt remove --no-delete-branch feature-branch
```
+If `[remove] delete-branch = false` is configured, use `--delete-branch` to delete a branch for one removal:
+
+```console
+$ wt remove --delete-branch feature-branch
+```
+
Force-delete an unmerged branch:
```console
diff --git a/src/commands/remove.rs b/src/commands/remove.rs
index 8f5eff683..477d9a0ab 100644
--- a/src/commands/remove.rs
+++ b/src/commands/remove.rs
@@ -392,10 +392,15 @@ pub fn handle_remove_command(args: RemoveArgs, yes: bool) -> anyhow::Result<()>
// Validate conflicting flags
if !delete_branch && args.force_delete {
+ let message = if args.no_delete_branch {
+ "Cannot use --force-delete with --no-delete-branch"
+ } else {
+ "Cannot use --force-delete with [remove] delete-branch = false; use --delete-branch to override it"
+ };
return Err(worktrunk::git::GitError::Other {
- message: "Cannot use --force-delete with delete-branch=false (set via --no-delete-branch or [remove] delete-branch = false)".into(),
- }
- .into());
+ message: message.into(),
+ }
+ .into());
}
// `--reap` relies on per-process cwd discovery (`lsof`/`ps`), which
diff --git a/tests/integration_tests/help.rs b/tests/integration_tests/help.rs
index a27be2dd8..8a7a7d6a2 100644
--- a/tests/integration_tests/help.rs
+++ b/tests/integration_tests/help.rs
@@ -79,6 +79,21 @@ fn test_merge_help_describes_exact_shape_no_rebase() {
);
}
+#[test]
+fn test_remove_help_shows_delete_branch_override() {
+ let output = wt_command()
+ .args(["remove", "--help"])
+ .output()
+ .expect("failed to run wt remove --help");
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ let stdout = stdout.ansi_strip();
+ assert!(
+ stdout.contains("--delete-branch"),
+ "missing config override in remove help:\n{stdout}"
+ );
+}
+
// Root command (wt)
#[rstest]
#[case("help_root_short", "-h")]
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index 997da1b52..c09e5782e 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -2159,6 +2159,71 @@ delete-branch = false
);
}
+#[rstest]
+fn test_remove_cli_delete_branch_force_overrides_config(mut repo: TestRepo) {
+ repo.write_test_config(
+ r#"[remove]
+delete-branch = false
+"#,
+ );
+ let worktree_path = repo.add_worktree("feature-cli-force-override");
+ std::fs::write(worktree_path.join("feature.txt"), "unmerged change").unwrap();
+ repo.git_command()
+ .args(["add", "feature.txt"])
+ .current_dir(&worktree_path)
+ .run()
+ .unwrap();
+ repo.git_command()
+ .args(["commit", "-m", "Add unmerged change"])
+ .current_dir(&worktree_path)
+ .run()
+ .unwrap();
+
+ let output = repo
+ .wt_command()
+ .args([
+ "remove",
+ "--foreground",
+ "--delete-branch",
+ "-D",
+ "feature-cli-force-override",
+ ])
+ .output()
+ .expect("wt remove should run");
+ assert!(
+ output.status.success(),
+ "wt remove failed: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ let branches = repo
+ .git_command()
+ .args(["branch", "--list", "feature-cli-force-override"])
+ .run()
+ .unwrap()
+ .stdout;
+ assert!(branches.is_empty(), "force-deleted branch should be gone");
+}
+
+#[rstest]
+fn test_remove_force_delete_with_config_false_suggests_override(repo: TestRepo) {
+ repo.write_test_config(
+ r#"[remove]
+delete-branch = false
+"#,
+ );
+ let output = repo
+ .wt_command()
+ .args(["remove", "-D", "nonexistent"])
+ .output()
+ .expect("wt remove should run");
+ assert!(!output.status.success());
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains("use --delete-branch to override it"),
+ "{stderr}"
+ );
+}
+
#[rstest]
fn test_remove_no_delete_branch_unmerged(mut repo: TestRepo) {
// Create a worktree with an unmerged commit
diff --git a/tests/snapshots/integration__integration_tests__help__help_remove_long.snap b/tests/snapshots/integration__integration_tests__help__help_remove_long.snap
index ef598d639..b2e8a4b39 100644
--- a/tests/snapshots/integration__integration_tests__help__help_remove_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_remove_long.snap
@@ -56,6 +56,9 @@ Usage: wt remove [OPTIONS] [BRANCHES]...
--no-delete-branch
Keep branch after removal
+ --delete-branch
+ Delete branch after removal (overrides config [remove] delete-branch = false)
+
-D, --force-delete
Delete unmerged branches
@@ -123,6 +126,10 @@ Keep the branch:
  wt remove --no-delete-branch feature-branch
+If [remove] delete-branch = false is configured, use --delete-branch to delete a branch for one removal:
+
+  wt remove --delete-branch feature-branch
+
Force-delete an unmerged branch:
  wt remove -D experimental
diff --git a/tests/snapshots/integration__integration_tests__help__help_remove_short.snap b/tests/snapshots/integration__integration_tests__help__help_remove_short.snap
index 41fddd0ad..13e29aed2 100644
--- a/tests/snapshots/integration__integration_tests__help__help_remove_short.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_remove_short.snap
@@ -51,6 +51,7 @@ Usage: wt remove [OPTIONS] [BRANCHES]...
Options:
--no-delete-branch Keep branch after removal
+ --delete-branch Delete branch after removal (overrides config [remove] delete-branch = false)
-D, --force-delete Delete unmerged branches
--foreground Run removal in foreground (block until complete)
--reap Kill processes started in the worktree [experimental]
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_conflicting_branch_flags.snap b/tests/snapshots/integration__integration_tests__remove__remove_conflicting_branch_flags.snap
index b068b4e3f..7d30f105b 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_conflicting_branch_flags.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_conflicting_branch_flags.snap
@@ -61,4 +61,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-✗ Cannot use --force-delete with delete-branch=false (set via --no-delete-branch or [remove] delete-branch = false)
+✗ Cannot use --force-delete with --no-delete-branch