Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(output): correct user-output consistency defects (#2867)

Maximilian Roos76754ca076a0
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index 1967de43f..17fec1c06 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -87,7 +87,7 @@ pub fn approve_command_batch(
);
eprintln!(
"{}",
- hint_message("Approval will be requested again next time.")
+ hint_message("Approval will be requested again next time")
);
}
}
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rs
index 0452bf111..714c1fd79 100644
--- a/src/commands/config/show.rs
+++ b/src/commands/config/show.rs
@@ -17,8 +17,8 @@ use worktrunk::path::format_path_for_display;
use worktrunk::shell::{FileDetectionResult, Shell, scan_for_detection_details};
use worktrunk::shell_exec::Cmd;
use worktrunk::styling::{
- error_message, format_bash_with_gutter, format_heading, format_toml, format_with_gutter,
- hint_message, info_message, success_message, warning_message,
+ FormattedMessage, error_message, format_bash_with_gutter, format_heading, format_toml,
+ format_with_gutter, hint_message, info_message, success_message, warning_message,
};
use crate::cli::{SwitchFormat, version_str};
@@ -1389,28 +1389,26 @@ pub(super) fn render_ci_tool_status(
Ok(())
}
+/// Format the version-check line given the latest release version.
+///
+/// Pure over `latest` so both arms are unit-testable without injecting a
+/// version through the environment; `render_version_check` supplies the value
+/// from `fetch_latest_version`.
+fn format_version_status(latest: &str) -> FormattedMessage {
+ let current = crate::cli::version_str();
+ if is_newer_version(latest, env!("CARGO_PKG_VERSION")) {
+ info_message(cformat!(
+ "Update available: <bold>{latest}</> (current: {current})"
+ ))
+ } else {
+ info_message(cformat!("Up to date (<bold>{current}</>)"))
+ }
+}
+
/// Render version update check (fetches from GitHub)
fn render_version_check(out: &mut String) -> anyhow::Result<()> {
match fetch_latest_version() {
- Ok(latest) => {
- let current = crate::cli::version_str();
- let current_semver = env!("CARGO_PKG_VERSION");
- if is_newer_version(&latest, current_semver) {
- writeln!(
- out,
- "{}",
- info_message(cformat!(
- "Update available: <bold>{latest}</> (current: {current})"
- ))
- )?;
- } else {
- writeln!(
- out,
- "{}",
- success_message(cformat!("Up to date (<bold>{current}</>)"))
- )?;
- }
- }
+ Ok(latest) => writeln!(out, "{}", format_version_status(&latest))?,
Err(e) => {
log::debug!("Version check failed: {e}");
writeln!(out, "{}", hint_message("Version check unavailable"))?;
@@ -1509,4 +1507,21 @@ mod tests {
assert!(!is_newer_version("invalid", "0.23.2"));
assert!(!is_newer_version("0.23.2", "invalid"));
}
+
+ #[test]
+ fn test_format_version_status() {
+ // A version far above the current crate version is "newer".
+ let update = format_version_status("999.0.0").to_string();
+ assert!(
+ update.contains("Update available"),
+ "expected update message, got: {update}"
+ );
+
+ // The current crate version is not newer than itself.
+ let up_to_date = format_version_status(env!("CARGO_PKG_VERSION")).to_string();
+ assert!(
+ up_to_date.contains("Up to date"),
+ "expected up-to-date message, got: {up_to_date}"
+ );
+ }
}
diff --git a/src/commands/relocate.rs b/src/commands/relocate.rs
index 82525cae5..9b7cb1c55 100644
--- a/src/commands/relocate.rs
+++ b/src/commands/relocate.rs
@@ -709,21 +709,26 @@ pub fn show_dry_run_preview(candidates: &[RelocationCandidate]) {
}
/// Show summary of relocations performed.
+///
+/// Only called after validation produced at least one candidate, so
+/// `relocated + skipped >= 1` always — each candidate either moves or is skipped.
pub fn show_summary(relocated: usize, skipped: usize) {
- if relocated > 0 || skipped > 0 {
- eprintln!();
- let plural = |n: usize| if n == 1 { "worktree" } else { "worktrees" };
- if skipped == 0 {
- let msg = format!("Relocated {relocated} {}", plural(relocated));
- eprintln!("{}", success_message(msg));
- } else {
- let msg = format!(
- "Relocated {relocated} {}, skipped {skipped} {}",
- plural(relocated),
- plural(skipped)
- );
- eprintln!("{}", info_message(msg));
- }
+ eprintln!();
+ let plural = |n: usize| if n == 1 { "worktree" } else { "worktrees" };
+ let msg = if skipped == 0 {
+ format!("Relocated {relocated} {}", plural(relocated))
+ } else {
+ format!(
+ "Relocated {relocated} {}, skipped {skipped} {}",
+ plural(relocated),
+ plural(skipped)
+ )
+ };
+ // Success when worktrees moved; info when only skips (no change made).
+ if relocated > 0 {
+ eprintln!("{}", success_message(msg));
+ } else {
+ eprintln!("{}", info_message(msg));
}
}
@@ -744,15 +749,16 @@ pub fn show_no_relocations_needed(template_errors: usize) {
}
/// Show message when all candidates were skipped during validation.
+///
+/// Only called when validation skipped every candidate, and at least one
+/// candidate exists by then, so `skipped >= 1` always.
pub fn show_all_skipped(skipped: usize) {
- if skipped > 0 {
- eprintln!();
- eprintln!(
- "{}",
- info_message(format!(
- "Skipped {skipped} worktree{}",
- if skipped == 1 { "" } else { "s" }
- ))
- );
- }
+ eprintln!();
+ eprintln!(
+ "{}",
+ info_message(format!(
+ "Skipped {skipped} worktree{}",
+ if skipped == 1 { "" } else { "s" }
+ ))
+ );
}
diff --git a/src/diagnostic.rs b/src/diagnostic.rs
index fc46c415c..6e8fcf39f 100644
--- a/src/diagnostic.rs
+++ b/src/diagnostic.rs
@@ -51,7 +51,7 @@ use minijinja::{Environment, context};
use worktrunk::git::Repository;
use worktrunk::path::format_path_for_display;
use worktrunk::shell_exec::Cmd;
-use worktrunk::styling::{eprintln, hint_message, info_message, warning_message};
+use worktrunk::styling::{eprintln, hint_message, success_message, warning_message};
use crate::cli::version_str;
use crate::output;
@@ -254,7 +254,7 @@ pub(crate) fn write_if_verbose(verbose: u8, command_line: &str, error_msg: Optio
let path_display = format_path_for_display(&path);
eprintln!(
"{}",
- info_message(format!("Diagnostic saved: {path_display}"))
+ success_message(format!("Diagnostic saved @ {path_display}"))
);
// Only show gh command if gh is installed
diff --git a/src/git/error.rs b/src/git/error.rs
index 9e2151f75..89d4b6596 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -1220,7 +1220,7 @@ impl GitError {
"Cannot create branch for <bold>{syntax}{number}</> — {name} already has branch <bold>{branch}</>"
)),
hint_message(cformat!(
- "To switch to it: <underline>wt switch {syntax}{number}</>"
+ "To switch to the existing branch, run <underline>wt switch {syntax}{number}</>"
))
)
}
diff --git a/src/output/shell_integration.rs b/src/output/shell_integration.rs
index 0a7bf3cdd..f0fabac47 100644
--- a/src/output/shell_integration.rs
+++ b/src/output/shell_integration.rs
@@ -347,7 +347,7 @@ pub fn print_shell_install_result(scan_result: &crate::commands::configure_shell
))
);
} else {
- eprintln!("{}", success_message("All shells already configured"));
+ eprintln!("{}", info_message("All shells already configured"));
}
// Zsh compinit advisory
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index 6d0cf1741..a4a236939 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -118,7 +118,7 @@ fn test_configure_shell_already_exists(repo: TestRepo, temp_home: TempDir) {
----- stderr -----
○ Already configured shell extension & completions for zsh @ ~/.zshrc
- ✓ All shells already configured
+ ○ All shells already configured
");
});
@@ -1356,7 +1356,7 @@ fn test_configure_shell_no_warning_when_already_configured(repo: TestRepo, temp_
----- stderr -----
○ Already configured shell extension & completions for zsh @ ~/.zshrc
- ✓ All shells already configured
+ ○ All shells already configured
");
});
}
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
index 38062520e..5d4372e85 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
@@ -8,7 +8,7 @@ expression: "&output"
❯ Allow and remember? [y/N] y
▲ Failed to save command approval: Failed to open lock file: Permission denied (os error 13)
-↳ Approval will be requested again next time.
+↳ Approval will be requested again next time
◎ Running pre-start project hook @ _REPO_.test-permission
  echo 'test command'
test command
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap
index c34ee647f..9caf77371 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap
@@ -74,7 +74,7 @@ exit_code: 0
DIAGNOSTICS
↳ CI status requires GitHub, GitLab, Gitea, or Azure DevOps remote
-✓ Up to date ([VERSION])
+○ Up to date ([VERSION])
✗ Commit generation failed (nonexistent-llm-command-12345 -m test-model)
  ✗ Commit generation command failed
    sh: nonexistent-llm-command-12345: command not found
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_gitea_remote.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_gitea_remote.snap
index 2cc443375..4b3413eef 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_full_gitea_remote.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_gitea_remote.snap
@@ -71,7 +71,7 @@ exit_code: 0
DIAGNOSTICS
▲ tea installed but not authenticated; run tea login add
-✓ Up to date ([VERSION])
+○ Up to date ([VERSION])
↳ Commit generation not configured
OTHER
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap
index 8c334d1ab..931cd6262 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap
@@ -71,7 +71,7 @@ exit_code: 0
DIAGNOSTICS
↳ CI status requires GitHub, GitLab, Gitea, or Azure DevOps remote
-✓ Up to date ([VERSION])
+○ Up to date ([VERSION])
↳ Commit generation not configured
OTHER
diff --git a/tests/snapshots/integration__integration_tests__step_relocate__relocate_mixed_success_and_skip.snap b/tests/snapshots/integration__integration_tests__step_relocate__relocate_mixed_success_and_skip.snap
index 7fedd91cf..7cb97edf0 100644
--- a/tests/snapshots/integration__integration_tests__step_relocate__relocate_mixed_success_and_skip.snap
+++ b/tests/snapshots/integration__integration_tests__step_relocate__relocate_mixed_success_and_skip.snap
@@ -47,4 +47,4 @@ exit_code: 0
▲ Skipping feature2 (locked)
✓ Relocated feature1: _PARENT_/wrong-location-1 → _REPO_.feature1
-○ Relocated 1 worktree, skipped 1 worktree
+✓ Relocated 1 worktree, skipped 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__step_relocate__relocate_same_target_no_panic.snap b/tests/snapshots/integration__integration_tests__step_relocate__relocate_same_target_no_panic.snap
index 6ac219223..ead2788db 100644
--- a/tests/snapshots/integration__integration_tests__step_relocate__relocate_same_target_no_panic.snap
+++ b/tests/snapshots/integration__integration_tests__step_relocate__relocate_same_target_no_panic.snap
@@ -49,4 +49,4 @@ exit_code: 0
✓ Relocated alpha: _PARENT_/wrong-location-1 → _REPO_/repo.shared
▲ Skipping beta (target occupied: _REPO_/repo.shared)
-○ Relocated 1 worktree, skipped 1 worktree
+✓ Relocated 1 worktree, skipped 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_mr_create_conflict.snap b/tests/snapshots/integration__integration_tests__switch__switch_mr_create_conflict.snap
index f2e235627..7490957c8 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_mr_create_conflict.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_mr_create_conflict.snap
@@ -49,4 +49,4 @@ exit_code: 1
  Fix authentication bug in login flow (!101)
  by @alice · opened · feature-auth · https://gitlab.com/owner/test-repo/-/merge_requests/101
✗ Cannot create branch for mr:101 — MR already has branch feature-auth
-↳ To switch to it: wt switch mr:101
+↳ To switch to the existing branch, run wt switch mr:101
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_create_conflict.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_create_conflict.snap
index 82e925c7c..af4c5abe3 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_create_conflict.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_create_conflict.snap
@@ -58,4 +58,4 @@ exit_code: 1
  Fix authentication bug in login flow (#101)
  by @[email protected] · active · feature-auth · https://dev.azure.com/myorg/myproject/_git/test-repo/pullrequest/101
✗ Cannot create branch for pr:101 — PR already has branch feature-auth
-↳ To switch to it: wt switch pr:101
+↳ To switch to the existing branch, run wt switch pr:101
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_forge_platform.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_forge_platform.snap
index 7f3722bf2..88d0335d6 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_forge_platform.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_forge_platform.snap
@@ -58,4 +58,4 @@ exit_code: 1
  Override test (#101)
  by @[email protected] · active · feature-auth · https://dev.azure.com/myorg/myproject/_git/test-repo/pullrequest/101
✗ Cannot create branch for pr:101 — PR already has branch feature-auth
-↳ To switch to it: wt switch pr:101
+↳ To switch to the existing branch, run wt switch pr:101
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_create_conflict.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_create_conflict.snap
index 8e765d02f..a86c9f687 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_create_conflict.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_create_conflict.snap
@@ -49,4 +49,4 @@ exit_code: 1
  Fix authentication bug in login flow (#101)
  by @alice · open · feature-auth · https://github.com/owner/test-repo/pull/101
✗ Cannot create branch for pr:101 — PR already has branch feature-auth
-↳ To switch to it: wt switch pr:101
+↳ To switch to the existing branch, run wt switch pr:101
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_create_conflict.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_create_conflict.snap
index 729929605..53d06af4a 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_create_conflict.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_create_conflict.snap
@@ -49,4 +49,4 @@ exit_code: 1
  Fix authentication bug in login flow (#101)
  by @alice · open · feature-auth · https://gitea.example.com/owner/test-repo/pulls/101
✗ Cannot create branch for pr:101 — PR already has branch feature-auth
-↳ To switch to it: wt switch pr:101
+↳ To switch to the existing branch, run wt switch pr:101
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forge_platform.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forge_platform.snap
index e6617bfd2..779a2431a 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forge_platform.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forge_platform.snap
@@ -49,4 +49,4 @@ exit_code: 1
  Override test (#101)
  by @alice · open · feature-auth · https://git.internal.example.com/owner/test-repo/pulls/101
✗ Cannot create branch for pr:101 — PR already has branch feature-auth
-↳ To switch to it: wt switch pr:101
+↳ To switch to the existing branch, run wt switch pr:101