Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor(error): give the unmerged-index phrase one home (#3599)
Maximilian Roosbcf6a287c184
diff --git a/src/commands/relocate.rs b/src/commands/relocate.rsindex d6d5f2598..c84574462 100644--- a/src/commands/relocate.rs+++ b/src/commands/relocate.rs@@ -26,7 +26,7 @@ use std::path::{Path, PathBuf};use anyhow::Context;use color_print::cformat;use worktrunk::config::UserConfig;-use worktrunk::git::{ErrorExt, Repository, WorktreeInfo};+use worktrunk::git::{ErrorExt, Repository, WorktreeInfo, format_unresolved_conflicts};use worktrunk::path::{format_path_for_display, paths_match};use worktrunk::styling::{eprintln, format_with_gutter, hint_message, info_message, println, progress_message,@@ -283,12 +283,11 @@ pub fn validate_candidates(// is the policy choice of skip over abort, not the guard.let unmerged = worktree.unmerged_paths()?;if !unmerged.is_empty() {- let count = unmerged.len();- let paths = if count == 1 { "path" } else { "paths" };eprintln!("{}",warning_message(cformat!(- "Skipping <bold>{branch}</> ({count} {paths} with unresolved conflicts)"+ "Skipping <bold>{branch}</> ({})",+ format_unresolved_conflicts(unmerged.len()))));eprintln!("{}", format_with_gutter(&unmerged.join("\n"), None));diff --git a/src/git/error.rs b/src/git/error.rsindex 96c8d75b8..670047b27 100644--- a/src/git/error.rs+++ b/src/git/error.rs@@ -640,6 +640,15 @@ pub enum GitError {impl std::error::Error for GitError {}+/// `"1 path with unresolved conflicts"` — the shared tail of every message+/// about an unmerged index. [`GitError::UnmergedPaths`] refuses outright;+/// `wt step relocate` warns and skips instead, because a conflict blocks only+/// one of the many worktrees it walks. The phrase is shared, not the error type.+pub fn format_unresolved_conflicts(count: usize) -> String {+ let paths = if count == 1 { "path" } else { "paths" };+ format!("{count} {paths} with unresolved conflicts")+}+impl GitError {/// Styled title for this variant (first line, with inline `<bold>`/// highlights on entity names like branch and path).@@ -662,9 +671,10 @@ impl GitError {}GitError::UnmergedPaths { action, files } => {- let count = files.len();- let paths = if count == 1 { "path" } else { "paths" };- cformat!("Cannot {action}: {count} {paths} with unresolved conflicts")+ format!(+ "Cannot {action}: {}",+ format_unresolved_conflicts(files.len())+ )}GitError::UncommittedChanges { action, branch, .. } => match (action, branch) {diff --git a/src/git/mod.rs b/src/git/mod.rsindex 4213eface..b3c5328a8 100644--- a/src/git/mod.rs+++ b/src/git/mod.rs@@ -66,6 +66,8 @@ pub use error::{WorktrunkError,// Wrap a HookCommandFailed-bearing error with a --no-hooks hintadd_hook_skip_hint,+ // Shared phrasing for an unmerged index ("1 path with unresolved conflicts")+ format_unresolved_conflicts,// Render a single error via Diagnostic if it implements onetry_render_diagnostic,};