Skip to content

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.rs
index 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 request
let (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 failing
repo.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.snap
index 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.rs
expression: output.normalized()
---
-βœ… Already on main, nothing to merge
+βœ… Merged to main
+βœ… Worktree preserved (--no-remove)
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap b/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap
index 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: C
LC_ALL: C
SOURCE_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: true
exit_code: 0
----- stdout -----
-βœ… Already on main, nothing to merge
+πŸ’‘ No commits to squash - already at merge base
+βœ… Merged to main
+βœ… Worktree preserved (--no-remove)
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap
index 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: C
LC_ALL: C
SOURCE_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: true
exit_code: 0
----- stdout -----
-βœ… Already on feature, nothing to merge
+πŸ’‘ No commits to squash - already at merge base
+βœ… Merged to feature
+βœ… Worktree preserved (--no-remove)
----- stderr -----