Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor(merge): Use shared `handle_squash` and `handle_rebase`
Maximilian Roos3c80c8feb2db
diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 03e695bde..bedefdc2e 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -144,14 +144,21 @@ pub fn handle_merge(// Squash commits if enabled - track whether squashing occurredlet squashed = if squash_enabled {- handle_squash(&target_branch, force, no_verify, tracked_only)?+ super::standalone::handle_squash(+ Some(&target_branch),+ force,+ no_verify,+ true,+ tracked_only,+ !tracked_only,+ )?} else {false};// Rebase onto target (skip if --no-commit) - track whether rebasing occurredlet rebased = if !no_commit {- super::standalone::handle_standalone_rebase(Some(&target_branch))?+ super::standalone::handle_rebase(Some(&target_branch))?} else {false};@@ -275,24 +282,6 @@ fn handle_merge_summary_output(primary_path: Option<&std::path::Path>) -> ResultOk(())}--fn handle_squash(- target_branch: &str,- force: bool,- skip_pre_commit: bool,- tracked_only: bool,-) -> Result<bool, GitError> {- // Delegate to the shared standalone implementation (auto_trust=true: commands approved in batch)- super::standalone::handle_standalone_squash(- Some(target_branch),- force,- skip_pre_commit,- true,- tracked_only,- !tracked_only,- )-}-/// Run pre-merge commands sequentially (blocking, fail-fast)pub fn run_pre_merge_commands(project_config: &ProjectConfig,diff --git a/src/commands/mod.rs b/src/commands/mod.rsindex ad3b300ad..2040daf4f 100644--- a/src/commands/mod.rs+++ b/src/commands/mod.rs@@ -27,8 +27,8 @@ pub use merge::handle_merge;#[cfg(unix)]pub use select::handle_select;pub use standalone::{- handle_standalone_ask_approvals, handle_standalone_commit, handle_standalone_push,- handle_standalone_rebase, handle_standalone_run_hook, handle_standalone_squash,+ handle_rebase, handle_squash, handle_standalone_ask_approvals, handle_standalone_commit,+ handle_standalone_run_hook,};pub use worktree::{handle_remove, handle_switch};diff --git a/src/commands/standalone.rs b/src/commands/standalone.rsindex e889d9c37..90b66f55b 100644--- a/src/commands/standalone.rs+++ b/src/commands/standalone.rs@@ -117,7 +117,7 @@ pub fn handle_standalone_commit(force: bool, no_verify: bool) -> Result<(), GitEcommit_changes(options)}-/// Handle `wt beta squash` command+/// Handle shared squash workflow (used by `wt beta squash` and `wt merge`)////// # Arguments/// * `auto_trust` - If true, skip approval prompts for pre-commit commands (already approved in batch)@@ -125,7 +125,7 @@ pub fn handle_standalone_commit(force: bool, no_verify: bool) -> Result<(), GitE/// * `warn_about_untracked` - Emit a warning before auto-staging untracked files////// Returns true if a commit or squash operation occurred, false if nothing needed to be done-pub fn handle_standalone_squash(+pub fn handle_squash(target: Option<&str>,force: bool,skip_pre_commit: bool,@@ -283,17 +283,9 @@ pub fn handle_standalone_squash(Ok(true)}-/// Handle `wt beta push` command-pub fn handle_standalone_push(- target: Option<&str>,- allow_merge_commits: bool,-) -> Result<(), GitError> {- super::worktree::handle_push(target, allow_merge_commits, "Pushed to", None, None, None)-}--/// Handle `wt beta rebase` command+/// Handle shared rebase workflow (used by `wt beta rebase` and `wt merge`)/// Returns true if rebasing occurred, false if already up-to-date-pub fn handle_standalone_rebase(target: Option<&str>) -> Result<bool, GitError> {+pub fn handle_rebase(target: Option<&str>) -> Result<bool, GitError> {let repo = Repository::current();// Get target branch (default to default branch if not provided)diff --git a/src/main.rs b/src/main.rsindex fe9f3192c..13c6c23d6 100644--- a/src/main.rs+++ b/src/main.rs@@ -16,13 +16,12 @@ pub use crate::cli::OutputFormat;use commands::command_executor::CommandContext;#[cfg(unix)]use commands::handle_select;-use commands::worktree::SwitchResult;+use commands::worktree::{SwitchResult, handle_push};use commands::{ConfigAction, handle_complete, handle_config_help, handle_config_init, handle_config_list,handle_config_refresh_cache, handle_configure_shell, handle_init, handle_list, handle_merge,- handle_remove, handle_standalone_ask_approvals, handle_standalone_commit,- handle_standalone_push, handle_standalone_rebase, handle_standalone_run_hook,- handle_standalone_squash, handle_switch,+ handle_rebase, handle_remove, handle_squash, handle_standalone_ask_approvals,+ handle_standalone_commit, handle_standalone_run_hook, handle_switch,};use output::{execute_user_command, handle_remove_output, handle_switch_output};@@ -168,15 +167,19 @@ fn main() {target,force,no_verify,- } => handle_standalone_squash(target.as_deref(), force, no_verify, false, false, true)- .map(|_| ()),+ } => handle_squash(target.as_deref(), force, no_verify, false, false, true).map(|_| ()),StandaloneCommand::Push {target,allow_merge_commits,- } => handle_standalone_push(target.as_deref(), allow_merge_commits),- StandaloneCommand::Rebase { target } => {- handle_standalone_rebase(target.as_deref()).map(|_| ())- }+ } => handle_push(+ target.as_deref(),+ allow_merge_commits,+ "Pushed to",+ None,+ None,+ None,+ ),+ StandaloneCommand::Rebase { target } => handle_rebase(target.as_deref()).map(|_| ()),StandaloneCommand::AskApprovals { force, all } => {handle_standalone_ask_approvals(force, all)}