Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor: Handle merge summary output with directives
Maximilian Roosd5d6a30ceef3
diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 96f752915..602fffc15 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -118,46 +118,92 @@ pub fn handle_merge(// Print comprehensive summaryprintln!();- print_merge_summary(¤t_branch, &target_branch, squashed_count, true);+ handle_merge_summary_output(+ ¤t_branch,+ &target_branch,+ squashed_count,+ true,+ internal,+ )?;} else {// Print comprehensive summary (worktree preserved)println!();- print_merge_summary(¤t_branch, &target_branch, squashed_count, false);+ handle_merge_summary_output(+ ¤t_branch,+ &target_branch,+ squashed_count,+ false,+ internal,+ )?;}Ok(())}-/// Print a comprehensive summary of the merge operation-fn print_merge_summary(+/// Format the merge summary message+fn format_merge_summary(from_branch: &str,to_branch: &str,squashed_count: Option<usize>,cleaned_up: bool,-) {+) -> String {let green = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Green)));let green_bold = green.bold();let dim = AnstyleStyle::new().dimmed();- println!("✅ {green}Merge complete{green:#}");- println!();+ let mut output = format!("✅ {green}Merge complete{green:#}\n\n");// Show what was merged- println!(- " {dim}Merged: {green_bold}{from_branch}{green_bold:#} → {green_bold}{to_branch}{green_bold:#}{dim:#}"- );+ output.push_str(&format!(+ " {dim}Merged: {green_bold}{from_branch}{green_bold:#} → {green_bold}{to_branch}{green_bold:#}{dim:#}\n"+ ));// Show squash info if applicableif let Some(count) = squashed_count {- println!(" {dim}Squashed: {count} commits into 1{dim:#}");+ output.push_str(&format!(" {dim}Squashed: {count} commits into 1{dim:#}\n"));}// Show worktree statusif cleaned_up {- println!(" {dim}Worktree: Removed{dim:#}");+ output.push_str(&format!(" {dim}Worktree: Removed{dim:#}"));} else {- println!(" {dim}Worktree: Kept (use 'wt remove' to clean up){dim:#}");+ output.push_str(&format!(+ " {dim}Worktree: Kept (use 'wt remove' to clean up){dim:#}"+ ));}++ output+}++/// Handle output for merge summary+///+/// In internal mode: outputs directives for shell wrapper+/// In non-internal mode: prints message directly+fn handle_merge_summary_output(+ from_branch: &str,+ to_branch: &str,+ squashed_count: Option<usize>,+ cleaned_up: bool,+ internal: bool,+) -> Result<(), GitError> {+ use crate::output::{Directive, DirectiveOutput};++ let message = format_merge_summary(from_branch, to_branch, squashed_count, cleaned_up);++ if internal {+ // Internal mode: output directives for shell wrapper+ let mut output = DirectiveOutput::new();+ output.add(Directive::Message(message));++ output+ .write_to_stdout()+ .map_err(|e| GitError::CommandFailed(e.to_string()))?;+ } else {+ // Non-internal mode: print directly+ println!("{}", message);+ }++ Ok(())}/// Commit uncommitted changes with LLM-generated messagediff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rsindex c0bfa4003..fe7636b87 100644--- a/tests/integration_tests/directives.rs+++ b/tests/integration_tests/directives.rs@@ -87,3 +87,56 @@ fn test_remove_without_internal() {assert_cmd_snapshot!("remove_without_internal", cmd);});}++/// Test merge command with internal flag and --keep+#[test]+fn test_merge_internal_keep() {+ let mut repo = TestRepo::new();+ repo.commit("Initial commit");+ repo.setup_remote("main");++ // Create a worktree for main+ let main_wt = repo.root_path().parent().unwrap().join("test-repo.main-wt");+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to add worktree");++ // Create a feature worktree and make a commit+ let feature_wt = repo.add_worktree("feature", "feature");+ std::fs::write(feature_wt.join("feature.txt"), "feature content")+ .expect("Failed to write file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["add", "feature.txt"])+ .current_dir(&feature_wt)+ .output()+ .expect("Failed to add file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", "Add feature file"])+ .current_dir(&feature_wt)+ .output()+ .expect("Failed to commit");++ let mut settings = Settings::clone_current();+ settings.set_snapshot_path("../snapshots");+ // Normalize SHA in output+ settings.add_filter(r"@ [a-f0-9]{7}", "@ [SHA]");++ settings.bind(|| {+ let mut cmd = Command::new(get_cargo_bin("wt"));+ repo.clean_cli_env(&mut cmd);+ cmd.arg("merge")+ .arg("main")+ .arg("--keep")+ .arg("--internal")+ .current_dir(&feature_wt);++ assert_cmd_snapshot!("merge_internal_keep", cmd);+ });+}diff --git a/tests/snapshots/integration__integration_tests__directives__merge_internal_keep.snap b/tests/snapshots/integration__integration_tests__directives__merge_internal_keep.snapnew file mode 100644index 000000000..8d5d2ba2dBinary files /dev/null and b/tests/snapshots/integration__integration_tests__directives__merge_internal_keep.snap differ