Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Feat: Add `--internal` flag to `merge` command
Maximilian Roos2ed8a2d8a4e3
diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex cf445b6e7..7e70d8418 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -5,7 +5,12 @@ use worktrunk::styling::format_error;use super::worktree::handle_push;use super::worktree::handle_remove;-pub fn handle_merge(target: Option<&str>, squash: bool, keep: bool) -> Result<(), GitError> {+pub fn handle_merge(+ target: Option<&str>,+ squash: bool,+ keep: bool,+ internal: bool,+) -> Result<(), GitError> {let repo = Repository::current();// Get current branch@@ -50,8 +55,12 @@ pub fn handle_merge(target: Option<&str>, squash: bool, keep: bool) -> Result<()let result = handle_remove()?;- // Display user-facing output- if let Some(output) = result.format_user_output() {+ // Display output based on mode+ if internal {+ if let Some(output) = result.format_internal_output() {+ println!("{}", output);+ }+ } else if let Some(output) = result.format_user_output() {println!("{}", output);}diff --git a/src/commands/worktree.rs b/src/commands/worktree.rsindex c032c0443..32cc5ebb9 100644--- a/src/commands/worktree.rs+++ b/src/commands/worktree.rs@@ -34,7 +34,7 @@ impl SwitchResult {)};Some(format!(- "{}\nNote: Use 'wt switch' (with shell integration) for automatic cd",+ "{}\n\nTo enable automatic cd, run: wt configure-shell",msg))}@@ -85,7 +85,7 @@ impl RemoveResult {Some(format!("Already on default branch '{}'", branch))}RemoveResult::RemovedWorktree { primary_path } => Some(format!(- "Moved to primary worktree and removed worktree\nPath: {}\nNote: Use 'wt remove' (with shell integration) for automatic cd",+ "Moved to primary worktree and removed worktree\nPath: {}\n\nTo enable automatic cd, run: wt configure-shell",primary_path.display())),RemoveResult::SwitchedToDefault(branch) => {diff --git a/src/main.rs b/src/main.rsindex 2bac7d853..1489ee46d 100644--- a/src/main.rs+++ b/src/main.rs@@ -119,6 +119,10 @@ enum Commands {/// Keep worktree after merging (don't remove)#[arg(short, long)]keep: bool,++ /// Use internal mode (outputs directives for shell wrapper)+ #[arg(long, hide = true)]+ internal: bool,},/// Generate shell completion script (deprecated - use init instead)@@ -215,7 +219,8 @@ fn main() {target,squash,keep,- } => handle_merge(target.as_deref(), squash, keep),+ internal,+ } => handle_merge(target.as_deref(), squash, keep, internal),Commands::Completion { shell } => {let mut cli_cmd = Cli::command();handle_completion(shell, &mut cli_cmd);diff --git a/templates/bash.sh b/templates/bash.shindex 96502906b..9ad299f12 100644--- a/templates/bash.sh+++ b/templates/bash.sh@@ -20,12 +20,12 @@ _wt_exec() {return $exit_code}-# Override {{ cmd_prefix }} command to add --internal flag for switch and remove+# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and merge{{ cmd_prefix }}() {local subcommand="$1"case "$subcommand" in- switch|remove)+ switch|remove|merge)# Commands that need --internal for directory change supportshift_wt_exec "$subcommand" --internal "$@"diff --git a/templates/elvish.elv b/templates/elvish.elvindex a67cdc5fc..4b60dd286 100644--- a/templates/elvish.elv+++ b/templates/elvish.elv@@ -32,7 +32,7 @@ fn _wt_exec {|@args|}}-# Override {{ cmd_prefix }} command to add --internal flag for switch and finish+# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and mergefn {{ cmd_prefix }} {|@args|if (== (count $args) 0) {e:wt@@ -41,7 +41,7 @@ fn {{ cmd_prefix }} {|@args|var subcommand = $args[0]- if (or (eq $subcommand "switch") (eq $subcommand "finish")) {+ if (or (eq $subcommand "switch") (eq $subcommand "remove") (eq $subcommand "merge")) {# Commands that need --internal for directory change supportvar rest-args = $args[1..]_wt_exec $subcommand --internal $@rest-argsdiff --git a/templates/fish.fish b/templates/fish.fishindex b23d6360e..a3b27e2c4 100644--- a/templates/fish.fish+++ b/templates/fish.fish@@ -19,12 +19,12 @@ function _wt_execreturn $exit_codeend-# Override {{ cmd_prefix }} command to add --internal flag for switch and remove+# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and mergefunction {{ cmd_prefix }}set -l subcommand $argv[1]switch $subcommand- case switch remove+ case switch remove merge# Commands that need --internal for directory change support_wt_exec $subcommand --internal $argv[2..-1]case '*'diff --git a/templates/nushell.nu b/templates/nushell.nuindex c4e798d80..b0f0d2f54 100644--- a/templates/nushell.nu+++ b/templates/nushell.nu@@ -21,13 +21,13 @@ export def --env _wt_exec [...args] {return $result.exit_code}-# Override {{ cmd_prefix }} command to add --internal flag for switch and finish+# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and merge# Use --wrapped to pass through all flags without parsing themexport def --env --wrapped {{ cmd_prefix }} [...rest] {let subcommand = ($rest | get 0? | default "")match $subcommand {- "switch" | "finish" => {+ "switch" | "remove" | "merge" => {# Commands that need --internal for directory change supportlet rest_args = ($rest | skip 1)let internal_args = ([$subcommand, "--internal"] | append $rest_args)diff --git a/templates/powershell.ps1 b/templates/powershell.ps1index 35e9cc0bc..ed76ff3e5 100644--- a/templates/powershell.ps1+++ b/templates/powershell.ps1@@ -26,7 +26,7 @@ function _wt_exec {return $exitCode}-# Override {{ cmd_prefix }} command to add --internal flag for switch and finish+# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and mergefunction {{ cmd_prefix }} {param([Parameter(ValueFromRemainingArguments=$true)]@@ -41,7 +41,7 @@ function {{ cmd_prefix }} {$subcommand = $Arguments[0]switch ($subcommand) {- { $_ -in @("switch", "finish") } {+ { $_ -in @("switch", "remove", "merge") } {# Commands that need --internal for directory change support$restArgs = $Arguments[1..($Arguments.Count-1)]$exitCode = _wt_exec $subcommand --internal @restArgsdiff --git a/templates/xonsh.xsh b/templates/xonsh.xshindex 4819d487e..8301387d9 100644--- a/templates/xonsh.xsh+++ b/templates/xonsh.xsh@@ -20,7 +20,7 @@ def _wt_exec(args):return result.returncodedef _{{ cmd_prefix }}_wrapper(args):- """Override {{ cmd_prefix }} command to add --internal flag for switch and finish"""+ """Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and merge"""if not args:# No arguments, just run wtwt@@ -28,7 +28,7 @@ def _{{ cmd_prefix }}_wrapper(args):subcommand = args[0]- if subcommand in ["switch", "finish"]:+ if subcommand in ["switch", "remove", "merge"]:# Commands that need --internal for directory change supportrest_args = args[1:]return _wt_exec([subcommand, "--internal"] + rest_args)diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex 8302b8877..3ca027463 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -41,12 +41,12 @@ _wt_exec() {return $exit_code}-# Override wt command to add --internal flag for switch and remove+# Override wt command to add --internal flag for switch, remove, and mergewt() {local subcommand="$1"case "$subcommand" in- switch|remove)+ switch|remove|merge)# Commands that need --internal for directory change supportshift_wt_exec "$subcommand" --internal "$@"diff --git a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snapindex 09ed225b7..30f47f167 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap@@ -43,12 +43,12 @@ _wt_exec() {return $exit_code}-# Override wt command to add --internal flag for switch and remove+# Override wt command to add --internal flag for switch, remove, and mergewt() {local subcommand="$1"case "$subcommand" in- switch|remove)+ switch|remove|merge)# Commands that need --internal for directory change supportshift_wt_exec "$subcommand" --internal "$@"diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex a0cea1644..88c1bce25 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -40,12 +40,12 @@ function _wt_execreturn $exit_codeend-# Override wt command to add --internal flag for switch and remove+# Override wt command to add --internal flag for switch, remove, and mergefunction wtset -l subcommand $argv[1]switch $subcommand- case switch remove+ case switch remove merge# Commands that need --internal for directory change support_wt_exec $subcommand --internal $argv[2..-1]case '*'diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex 3bb2bd70a..21ae261bd 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -41,12 +41,12 @@ _wt_exec() {return $exit_code}-# Override wt command to add --internal flag for switch and remove+# Override wt command to add --internal flag for switch, remove, and mergewt() {local subcommand="$1"case "$subcommand" in- switch|remove)+ switch|remove|merge)# Commands that need --internal for directory change supportshift_wt_exec "$subcommand" --internal "$@"diff --git a/tests/snapshots/integration__integration_tests__merge__merge_fast_forward.snap b/tests/snapshots/integration__integration_tests__merge__merge_fast_forward.snapindex d2d3cc650..bd9bd77af 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_fast_forward.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_fast_forward.snap@@ -6,6 +6,7 @@ info:- merge- mainenv:+ CLICOLOR_FORCE: "1"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/null@@ -25,6 +26,7 @@ Successfully pushed to 'main'Cleaning up worktree...Moved to primary worktree and removed worktreePath: [REPO]-Note: Use 'wt remove' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__merge__merge_not_fast_forward.snap b/tests/snapshots/integration__integration_tests__merge__merge_not_fast_forward.snapindex d2d3cc650..bd9bd77af 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_not_fast_forward.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_not_fast_forward.snap@@ -6,6 +6,7 @@ info:- merge- mainenv:+ CLICOLOR_FORCE: "1"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/null@@ -25,6 +26,7 @@ Successfully pushed to 'main'Cleaning up worktree...Moved to primary worktree and removed worktreePath: [REPO]-Note: Use 'wt remove' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snapindex b5a090239..a816cfe99 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap@@ -29,7 +29,8 @@ Successfully pushed to 'main'Cleaning up worktree...Moved to primary worktree and removed worktreePath: [REPO]-Note: Use 'wt remove' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----Warning: LLM generation failed, using deterministic messagediff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snapindex 2f75c24fa..a60d0d3cf 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap@@ -30,7 +30,8 @@ Successfully pushed to 'main'Cleaning up worktree...Moved to primary worktree and removed worktreePath: [REPO]-Note: Use 'wt remove' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----Warning: LLM generation failed, using deterministic messagediff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_single_commit.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_single_commit.snapindex 318bdc9cf..e0ced77fe 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_single_commit.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_single_commit.snap@@ -28,6 +28,7 @@ Successfully pushed to 'main'Cleaning up worktree...Moved to primary worktree and removed worktreePath: [REPO]-Note: Use 'wt remove' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snapindex e27f3f8fc..b705acd31 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap@@ -31,7 +31,8 @@ Successfully pushed to 'main'Cleaning up worktree...Moved to primary worktree and removed worktreePath: [REPO]-Note: Use 'wt remove' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----Warning: LLM generation failed, using deterministic messagediff --git a/tests/snapshots/integration__integration_tests__merge__merge_to_default.snap b/tests/snapshots/integration__integration_tests__merge__merge_to_default.snapindex 36f2578e6..47a59568d 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_to_default.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_to_default.snap@@ -5,6 +5,7 @@ info:args:- mergeenv:+ CLICOLOR_FORCE: "1"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/null@@ -24,6 +25,7 @@ Successfully pushed to 'main'Cleaning up worktree...Moved to primary worktree and removed worktreePath: [REPO]-Note: Use 'wt remove' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snapindex 7f029d8ab..559564c6d 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_from_worktree.snap@@ -5,6 +5,7 @@ info:args:- removeenv:+ CLICOLOR_FORCE: "1"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/null@@ -19,6 +20,7 @@ exit_code: 0----- stdout -----Moved to primary worktree and removed worktreePath: [REPO]-Note: Use 'wt remove' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__switch__switch_create_new.snap b/tests/snapshots/integration__integration_tests__switch__switch_create_new.snapindex 729593c43..7e3737a9c 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_create_new.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_create_new.snap@@ -21,6 +21,7 @@ success: trueexit_code: 0----- stdout -----Created new branch and worktree for 'feature-x' at [REPO].feature-x-Note: Use 'wt switch' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_creates_file.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_creates_file.snapindex b523e0a53..3fc7be4a1 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_creates_file.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_creates_file.snap@@ -23,6 +23,7 @@ success: trueexit_code: 0----- stdout -----Created new branch and worktree for 'file-test' at [REPO].file-test-Note: Use 'wt switch' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_success.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_success.snapindex 9e5767d8b..69e61d25c 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_success.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_success.snap@@ -24,6 +24,7 @@ exit_code: 0----- stdout -----test outputCreated new branch and worktree for 'exec-test' at [REPO].exec-test-Note: Use 'wt switch' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__switch__switch_with_base.snap b/tests/snapshots/integration__integration_tests__switch__switch_with_base.snapindex 5e5279728..415a9ae7f 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_with_base.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_with_base.snap@@ -23,6 +23,7 @@ success: trueexit_code: 0----- stdout -----Created new branch and worktree for 'feature-with-base' at [REPO].feature-with-base-Note: Use 'wt switch' (with shell integration) for automatic cd++To enable automatic cd, run: wt configure-shell----- stderr -----