Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor merge output to use `output::success`
Maximilian Roos3fc958cd7803
diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 60981db7c..aa03ef4ce 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -1,8 +1,8 @@use worktrunk::config::{ProjectConfig, WorktrunkConfig};use worktrunk::git::{GitError, Repository};use worktrunk::styling::{- AnstyleStyle, CYAN, CYAN_BOLD, ERROR, ERROR_EMOJI, GREEN, GREEN_BOLD, HINT, HINT_EMOJI,- SUCCESS_EMOJI, eprint, eprintln, format_with_gutter, println,+ AnstyleStyle, CYAN, CYAN_BOLD, ERROR, ERROR_EMOJI, GREEN, HINT, HINT_EMOJI, SUCCESS_EMOJI,+ eprint, eprintln, format_with_gutter, println,};use super::command_executor::{CommandContext, prepare_project_commands};@@ -33,9 +33,11 @@ pub fn handle_merge(// Check if already on target branchif current_branch == target_branch {- println!(- "{SUCCESS_EMOJI} {GREEN}Already on {GREEN_BOLD}{target_branch}{GREEN_BOLD:#}, nothing to merge{GREEN:#}"- );+ let bold = AnstyleStyle::new().bold();+ crate::output::success(format!(+ "Already on {bold}{target_branch}{bold:#}, nothing to merge"+ ))+ .map_err(|e| GitError::CommandFailed(e.to_string()))?;return Ok(());}@@ -245,7 +247,8 @@ fn handle_commit_changes(repo.run_command(&["commit", "-m", &commit_message]).map_err(|e| GitError::CommandFailed(format!("Failed to commit: {}", e)))?;- println!("{SUCCESS_EMOJI} {GREEN}Committed changes{GREEN:#}");+ crate::output::success("Committed changes")+ .map_err(|e| GitError::CommandFailed(e.to_string()))?;Ok(())}diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rsindex 819ef7c9d..f8fef2bad 100644--- a/tests/integration_tests/directives.rs+++ b/tests/integration_tests/directives.rs@@ -140,3 +140,59 @@ fn test_merge_internal_keep() {assert_cmd_snapshot!("merge_internal_keep", cmd);});}++/// Test merge command with internal flag (removes worktree, emits __WORKTRUNK_CD__)+/// This test verifies that the directive protocol is correctly formatted with NUL terminators+#[test]+fn test_merge_internal_remove() {+ 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 and path in output+ settings.add_filter(r"@ [a-f0-9]{7}", "@ [SHA]");+ settings.add_filter(r"__WORKTRUNK_CD__[^\x00]+", "__WORKTRUNK_CD__[PATH]");+ // Normalize temp directory paths in success message+ settings.add_filter(r"/private/var/folders/[^\s]+/test-repo", "[REPO]");++ settings.bind(|| {+ let mut cmd = Command::new(get_cargo_bin("wt"));+ repo.clean_cli_env(&mut cmd);+ cmd.arg("--internal")+ .arg("merge")+ .arg("main")+ .current_dir(&feature_wt);++ assert_cmd_snapshot!("merge_internal_remove", cmd);+ });+}diff --git a/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap b/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snapindex cea1d7708..37fb19401 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_already_on_target.snap@@ -13,11 +13,12 @@ info:GIT_EDITOR: ""LANG: CLC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"+ SOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpTxWA4J/test-config.toml---success: trueexit_code: 0----- stdout ------✅ [32mAlready on [1m[32mmain[0m, nothing to merge[0m+✅ [32mAlready on [1mmain[0m, nothing to merge[0m----- stderr -----