Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Allow merging to current branch for consistency
Maximilian Roos6107e8d87b3d
diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 43c7954c6..6eb57f34e 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -137,14 +137,8 @@ pub fn handle_merge(// Get target branch (default to default branch if not provided)let target_branch = repo.resolve_target_branch(target)?;- // Check if already on target branch- if current_branch == target_branch {- use worktrunk::styling::GREEN;- crate::output::success(format!(- "{GREEN}Already on {GREEN_BOLD}{target_branch}{GREEN_BOLD:#}{GREEN}, nothing to merge{GREEN:#}"- ))?;- return Ok(());- }+ // When current == target, force --no-remove (can't remove the worktree we're on)+ let no_remove_effective = no_remove || current_branch == target_branch;// Collect and approve all commands upfront for batch permission requestlet (all_commands, project_id) = MergeCommandCollector {@@ -235,7 +229,7 @@ pub fn handle_merge(let primary_worktree_dir = worktrees.worktrees[0].path.clone();// Finish worktree unless --no-remove was specified- if !no_remove {+ if !no_remove_effective {// STEP 1: Check for uncommitted changes before attempting cleanup// This prevents showing "Cleaning up worktree..." before failingrepo.ensure_clean_working_tree()?;diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge.snapindex 27789aa57..2cb4877cf 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge.snap@@ -2,4 +2,5 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized()----β [32mAlready on [1m[32mmain[0m[32m, nothing to merge[0m+β [32mMerged to [1m[32mmain[0m[0m+β [32mWorktree preserved (--no-remove)[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap b/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snapindex ec88c6d26..6b1594551 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap@@ -15,11 +15,13 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmps9ICzC/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpKgm0sH/test-config.toml---success: trueexit_code: 0----- stdout ------β [32mAlready on [1m[32mmain[0m[32m, nothing to merge[0m+π‘ [2mNo commits to squash - already at merge base[0m+β [32mMerged to [1m[32mmain[0m[0m+β [32mWorktree preserved (--no-remove)[0m----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snapindex fadfa4941..537c98b5d 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap@@ -15,11 +15,13 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpUWoJyn/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpP0JvO5/test-config.toml---success: trueexit_code: 0----- stdout ------β [32mAlready on [1m[32mfeature[0m[32m, nothing to merge[0m+π‘ [2mNo commits to squash - already at merge base[0m+β [32mMerged to [1m[32mfeature[0m[0m+β [32mWorktree preserved (--no-remove)[0m----- stderr -----