Skip to content

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

Prefer local target when same commit as upstream

Maximilian Roosba8fd9972ff7
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 5caf98d20..f70b11aa8 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -55,9 +55,11 @@ fn format_switch_success_message(
/// Determine the effective target for integration checks.
///
/// If the upstream of the local target (e.g., `origin/main`) is strictly ahead of
-/// the local target (i.e., local is an ancestor of upstream), uses the upstream.
-/// This handles the common case where a branch was merged remotely but the user
-/// hasn't pulled yet.
+/// the local target (i.e., local is an ancestor of upstream but not the same commit),
+/// uses the upstream. This handles the common case where a branch was merged remotely
+/// but the user hasn't pulled yet.
+///
+/// When local and upstream are the same commit, prefers local for clearer messaging.
///
/// Returns the effective target ref to check against.
///
@@ -71,6 +73,11 @@ fn effective_integration_target(repo: &Repository, local_target: &str) -> String
_ => return local_target.to_string(),
};
+ // If local and upstream are the same commit, prefer local for clearer messaging
+ if repo.same_commit(local_target, &upstream).unwrap_or(false) {
+ return local_target.to_string();
+ }
+
// Check if local is strictly behind upstream (local is ancestor of upstream)
// This means upstream has commits that local doesn't have
// On error, fall back to local target (defensive: don't fail remove due to git errors)
diff --git a/tests/snapshots/integration__integration_tests__directives__remove_internal_powershell_directive.snap b/tests/snapshots/integration__integration_tests__directives__remove_internal_powershell_directive.snap
index f6a1cbee0..62ce7f327 100644
--- a/tests/snapshots/integration__integration_tests__directives__remove_internal_powershell_directive.snap
+++ b/tests/snapshots/integration__integration_tests__directives__remove_internal_powershell_directive.snap
@@ -6,6 +6,7 @@ info:
- "--internal=powershell"
- remove
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -13,10 +14,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
@@ -24,4 +29,4 @@ exit_code: 0
Set-Location '[PATH]'
----- stderr -----
-πŸ”„ Removing feature worktree & branch in background (already in origin/main)
+πŸ”„ Removing feature worktree & branch in background (already in main)