mirror of
https://github.com/max-sixty/worktrunk.git
synced 2026-12-03 18:06:15 +08:00
Feat: Add --internal flag to merge command
This change introduces an `--internal` flag to the `merge` command. When this flag is present, the command will output internal directives for shell wrappers, allowing for automatic directory changes after a merge operation, similar to `switch` and `remove`. The shell integration templates (bash, elvish, fish, nushell, powershell, xonsh) have been updated to pass the `--internal` flag to `merge` when invoked via the shell alias. This ensures that the shell can automatically `cd` to the primary worktree after a successful merge and cleanup. Additionally, the user-facing output for `switch` and `remove` has been updated to suggest running `wt configure-shell` for automatic `cd` functionality, replacing the previous "Note: Use 'wt switch' (with shell integration) for automatic cd" message. Co-authored-by: Claude <no-reply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
665855c89a
commit
2ed8a2d8a4
+12
-3
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
+6
-1
@@ -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);
|
||||
|
||||
+2
-2
@@ -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 support
|
||||
shift
|
||||
_wt_exec "$subcommand" --internal "$@"
|
||||
|
||||
@@ -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 merge
|
||||
fn {{ 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 support
|
||||
var rest-args = $args[1..]
|
||||
_wt_exec $subcommand --internal $@rest-args
|
||||
|
||||
+2
-2
@@ -19,12 +19,12 @@ function _wt_exec
|
||||
return $exit_code
|
||||
end
|
||||
|
||||
# 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
|
||||
function {{ 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 '*'
|
||||
|
||||
@@ -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 them
|
||||
export 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 support
|
||||
let rest_args = ($rest | skip 1)
|
||||
let internal_args = ([$subcommand, "--internal"] | append $rest_args)
|
||||
|
||||
@@ -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 merge
|
||||
function {{ 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 @restArgs
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ def _wt_exec(args):
|
||||
return result.returncode
|
||||
|
||||
def _{{ 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 wt
|
||||
wt
|
||||
@@ -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 support
|
||||
rest_args = args[1:]
|
||||
return _wt_exec([subcommand, "--internal"] + rest_args)
|
||||
|
||||
@@ -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 merge
|
||||
wt() {
|
||||
local subcommand="$1"
|
||||
|
||||
case "$subcommand" in
|
||||
switch|remove)
|
||||
switch|remove|merge)
|
||||
# Commands that need --internal for directory change support
|
||||
shift
|
||||
_wt_exec "$subcommand" --internal "$@"
|
||||
|
||||
@@ -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 merge
|
||||
wt() {
|
||||
local subcommand="$1"
|
||||
|
||||
case "$subcommand" in
|
||||
switch|remove)
|
||||
switch|remove|merge)
|
||||
# Commands that need --internal for directory change support
|
||||
shift
|
||||
_wt_exec "$subcommand" --internal "$@"
|
||||
|
||||
@@ -40,12 +40,12 @@ function _wt_exec
|
||||
return $exit_code
|
||||
end
|
||||
|
||||
# Override wt command to add --internal flag for switch and remove
|
||||
# Override wt command to add --internal flag for switch, remove, and merge
|
||||
function wt
|
||||
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 '*'
|
||||
|
||||
@@ -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 merge
|
||||
wt() {
|
||||
local subcommand="$1"
|
||||
|
||||
case "$subcommand" in
|
||||
switch|remove)
|
||||
switch|remove|merge)
|
||||
# Commands that need --internal for directory change support
|
||||
shift
|
||||
_wt_exec "$subcommand" --internal "$@"
|
||||
|
||||
@@ -6,6 +6,7 @@ info:
|
||||
- merge
|
||||
- main
|
||||
env:
|
||||
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 worktree
|
||||
Path: [REPO]
|
||||
Note: Use 'wt remove' (with shell integration) for automatic cd
|
||||
|
||||
To enable automatic cd, run: wt configure-shell
|
||||
|
||||
----- stderr -----
|
||||
|
||||
@@ -6,6 +6,7 @@ info:
|
||||
- merge
|
||||
- main
|
||||
env:
|
||||
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 worktree
|
||||
Path: [REPO]
|
||||
Note: Use 'wt remove' (with shell integration) for automatic cd
|
||||
|
||||
To enable automatic cd, run: wt configure-shell
|
||||
|
||||
----- stderr -----
|
||||
|
||||
+2
-1
@@ -29,7 +29,8 @@ Successfully pushed to 'main'
|
||||
Cleaning up worktree...
|
||||
Moved to primary worktree and removed worktree
|
||||
Path: [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 message
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@ Successfully pushed to 'main'
|
||||
Cleaning up worktree...
|
||||
Moved to primary worktree and removed worktree
|
||||
Path: [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 message
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ Successfully pushed to 'main'
|
||||
Cleaning up worktree...
|
||||
Moved to primary worktree and removed worktree
|
||||
Path: [REPO]
|
||||
Note: Use 'wt remove' (with shell integration) for automatic cd
|
||||
|
||||
To enable automatic cd, run: wt configure-shell
|
||||
|
||||
----- stderr -----
|
||||
|
||||
@@ -31,7 +31,8 @@ Successfully pushed to 'main'
|
||||
Cleaning up worktree...
|
||||
Moved to primary worktree and removed worktree
|
||||
Path: [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 message
|
||||
|
||||
@@ -5,6 +5,7 @@ info:
|
||||
args:
|
||||
- merge
|
||||
env:
|
||||
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 worktree
|
||||
Path: [REPO]
|
||||
Note: Use 'wt remove' (with shell integration) for automatic cd
|
||||
|
||||
To enable automatic cd, run: wt configure-shell
|
||||
|
||||
----- stderr -----
|
||||
|
||||
@@ -5,6 +5,7 @@ info:
|
||||
args:
|
||||
- remove
|
||||
env:
|
||||
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 worktree
|
||||
Path: [REPO]
|
||||
Note: Use 'wt remove' (with shell integration) for automatic cd
|
||||
|
||||
To enable automatic cd, run: wt configure-shell
|
||||
|
||||
----- stderr -----
|
||||
|
||||
@@ -21,6 +21,7 @@ success: true
|
||||
exit_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 -----
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ success: true
|
||||
exit_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 -----
|
||||
|
||||
@@ -24,6 +24,7 @@ exit_code: 0
|
||||
----- stdout -----
|
||||
test output
|
||||
Created 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 -----
|
||||
|
||||
@@ -23,6 +23,7 @@ success: true
|
||||
exit_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 -----
|
||||
|
||||
Reference in New Issue
Block a user