Skip to content

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

Refactor: Unify bold styling constants

Maximilian Roos43c9ab1f7188
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index 7ae902043..8171d4c87 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -5,8 +5,8 @@
use worktrunk::config::{Command, WorktrunkConfig};
use worktrunk::git::{GitError, GitResultExt};
use worktrunk::styling::{
- AnstyleStyle, HINT, HINT_EMOJI, INFO_EMOJI, PROGRESS_EMOJI, WARNING, WARNING_EMOJI, eprint,
- eprintln, format_bash_with_gutter, println, stderr,
+ AnstyleStyle, HINT, HINT_EMOJI, INFO_EMOJI, PROGRESS_EMOJI, WARNING, WARNING_BOLD,
+ WARNING_EMOJI, eprint, eprintln, format_bash_with_gutter, println, stderr,
};
/// Batch approval helper used when multiple commands are queued for execution.
@@ -97,13 +97,12 @@ fn prompt_for_batch_approval(commands: &[&Command], project_id: &str) -> std::io
let project_name = project_id.split('/').next_back().unwrap_or(project_id);
let bold = AnstyleStyle::new().bold();
- let warning_bold = WARNING.bold();
let count = commands.len();
let plural = if count == 1 { "" } else { "s" };
eprintln!();
eprintln!(
- "{WARNING_EMOJI} {WARNING}{warning_bold}{project_name}{warning_bold:#} wants to execute {warning_bold}{count}{warning_bold:#} command{plural}:{WARNING:#}"
+ "{WARNING_EMOJI} {WARNING}{WARNING_BOLD}{project_name}{WARNING_BOLD:#} wants to execute {WARNING_BOLD}{count}{WARNING_BOLD:#} command{plural}:{WARNING:#}"
);
eprintln!();
diff --git a/src/commands/command_executor.rs b/src/commands/command_executor.rs
index 375433aa6..4397f2a6b 100644
--- a/src/commands/command_executor.rs
+++ b/src/commands/command_executor.rs
@@ -66,7 +66,7 @@ fn expand_commands(
);
base_extras.insert(
"repo_root".to_string(),
- repo_root.to_str().unwrap_or("").to_string(),
+ repo_root.to_string_lossy().to_string(),
);
for &(key, value) in extra_vars {
base_extras.insert(key.to_string(), value.to_string());
diff --git a/src/commands/config.rs b/src/commands/config.rs
index c86dad20b..e1b9c7a67 100644
--- a/src/commands/config.rs
+++ b/src/commands/config.rs
@@ -2,7 +2,8 @@ use etcetera::base_strategy::{BaseStrategy, choose_base_strategy};
use std::path::PathBuf;
use worktrunk::git::{GitError, GitResultExt, Repository};
use worktrunk::styling::{
- AnstyleStyle, GREEN, HINT, HINT_EMOJI, INFO_EMOJI, SUCCESS_EMOJI, format_toml, print, println,
+ AnstyleStyle, GREEN, GREEN_BOLD, HINT, HINT_EMOJI, INFO_EMOJI, SUCCESS_EMOJI, format_toml,
+ print, println,
};
/// Example configuration file content
@@ -175,8 +176,7 @@ pub fn handle_config_refresh_cache() -> Result<(), GitError> {
let branch = repo.refresh_default_branch()?;
// Display success message
- let green_bold = GREEN.bold();
- println!("{SUCCESS_EMOJI} {GREEN}Cache refreshed: {green_bold}{branch}{green_bold:#}{GREEN:#}");
+ println!("{SUCCESS_EMOJI} {GREEN}Cache refreshed: {GREEN_BOLD}{branch}{GREEN_BOLD:#}{GREEN:#}");
Ok(())
}
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rs
index 6a6c80b34..9c9de26cd 100644
--- a/src/commands/configure_shell.rs
+++ b/src/commands/configure_shell.rs
@@ -2,7 +2,9 @@ use std::fs::{self, OpenOptions};
use std::io::{self, BufRead, BufReader, Write};
use std::path::{Path, PathBuf};
use worktrunk::shell::Shell;
-use worktrunk::styling::{INFO_EMOJI, PROGRESS_EMOJI, SUCCESS_EMOJI, format_bash_with_gutter};
+use worktrunk::styling::{
+ CYAN_BOLD, INFO_EMOJI, PROGRESS_EMOJI, SUCCESS_EMOJI, format_bash_with_gutter,
+};
pub struct ConfigureResult {
pub shell: Shell,
@@ -328,15 +330,12 @@ fn configure_fish_file(
}
fn prompt_for_confirmation(results: &[ConfigureResult]) -> Result<bool, String> {
- use anstyle::{AnsiColor, Color, Style};
+ use anstyle::Style;
use worktrunk::styling::{HINT_EMOJI, eprint, eprintln};
- let cyan = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
- let cyan_bold = cyan.bold();
-
// Interactive prompts go to stderr so they appear even when stdout is redirected
eprintln!();
- eprintln!("{HINT_EMOJI} {cyan_bold}Configuration changes:{cyan_bold:#}");
+ eprintln!("{HINT_EMOJI} {CYAN_BOLD}Configuration changes:{CYAN_BOLD:#}");
eprintln!();
for result in results {
diff --git a/src/commands/dev.rs b/src/commands/dev.rs
index bcc4089e8..c6c816216 100644
--- a/src/commands/dev.rs
+++ b/src/commands/dev.rs
@@ -2,7 +2,8 @@ use worktrunk::HookType;
use worktrunk::config::{ProjectConfig, WorktrunkConfig};
use worktrunk::git::{GitError, GitResultExt, Repository};
use worktrunk::styling::{
- AnstyleStyle, CYAN, CYAN_BOLD, HINT, HINT_EMOJI, eprintln, format_with_gutter,
+ AnstyleStyle, CYAN, CYAN_BOLD, GREEN_BOLD, HINT, HINT_BOLD, HINT_EMOJI, eprintln,
+ format_with_gutter,
};
use super::merge::{
@@ -92,10 +93,9 @@ fn load_project_config(repo: &Repository) -> Result<ProjectConfig, GitError> {
// No project config found - show helpful error
use worktrunk::styling::ERROR;
use worktrunk::styling::ERROR_EMOJI;
- let hint_bold = HINT.bold();
eprintln!("{ERROR_EMOJI} {ERROR}No project configuration found{ERROR:#}",);
eprintln!(
- "{HINT_EMOJI} {HINT}Create a config file at: {hint_bold}{}{hint_bold:#}{HINT:#}",
+ "{HINT_EMOJI} {HINT}Create a config file at: {HINT_BOLD}{}{HINT_BOLD:#}{HINT:#}",
config_path.display()
);
Err(GitError::CommandFailed(
@@ -379,9 +379,8 @@ pub fn handle_dev_rebase(target: Option<&str>) -> Result<bool, GitError> {
// Success
use worktrunk::styling::GREEN;
- let green_bold = GREEN.bold();
crate::output::success(format!(
- "{GREEN}Rebased onto {green_bold}{target_branch}{green_bold:#}{GREEN:#}"
+ "{GREEN}Rebased onto {GREEN_BOLD}{target_branch}{GREEN_BOLD:#}{GREEN:#}"
))?;
Ok(true)
diff --git a/src/commands/list/model.rs b/src/commands/list/model.rs
index a143551c4..81b8135cc 100644
--- a/src/commands/list/model.rs
+++ b/src/commands/list/model.rs
@@ -1,7 +1,7 @@
use rayon::prelude::*;
use std::path::PathBuf;
use worktrunk::git::{GitError, Repository};
-use worktrunk::styling::{HINT, HINT_EMOJI, WARNING, WARNING_EMOJI, println};
+use worktrunk::styling::{HINT, HINT_EMOJI, WARNING, WARNING_BOLD, WARNING_EMOJI, println};
use super::ci_status::PrStatus;
@@ -601,9 +601,8 @@ pub fn gather_list_data(
match result {
Ok(branch_info) => items.push(ListItem::Branch(branch_info)),
Err(e) => {
- let warning_bold = WARNING.bold();
println!(
- "{WARNING_EMOJI} {WARNING}Failed to enrich branch {warning_bold}{branch}{warning_bold:#}: {e}{WARNING:#}"
+ "{WARNING_EMOJI} {WARNING}Failed to enrich branch {WARNING_BOLD}{branch}{WARNING_BOLD:#}: {e}{WARNING:#}"
);
println!(
"{HINT_EMOJI} {HINT}This branch will be shown with limited information{HINT:#}"
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index c5abc92e7..f9a448691 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -2,8 +2,8 @@ use worktrunk::HookType;
use worktrunk::config::{Command, CommandPhase, ProjectConfig, WorktrunkConfig};
use worktrunk::git::{GitError, GitResultExt, Repository};
use worktrunk::styling::{
- AnstyleStyle, CYAN, CYAN_BOLD, ERROR, ERROR_EMOJI, HINT, HINT_EMOJI, WARNING,
- format_bash_with_gutter, format_with_gutter,
+ AnstyleStyle, CYAN, CYAN_BOLD, ERROR, ERROR_EMOJI, GREEN_BOLD, HINT, HINT_EMOJI, WARNING,
+ WARNING_BOLD, format_bash_with_gutter, format_with_gutter,
};
use super::command_approval::approve_command_batch;
@@ -137,9 +137,8 @@ pub fn handle_merge(
// Check if already on target branch
if current_branch == target_branch {
use worktrunk::styling::GREEN;
- let green_bold = GREEN.bold();
crate::output::success(format!(
- "{GREEN}Already on {green_bold}{target_branch}{green_bold:#}{GREEN}, nothing to merge{GREEN:#}"
+ "{GREEN}Already on {GREEN_BOLD}{target_branch}{GREEN_BOLD:#}{GREEN}, nothing to merge{GREEN:#}"
))?;
return Ok(());
}
@@ -247,9 +246,8 @@ pub fn handle_merge(
// Show success message now that user has been cd'd to primary
use worktrunk::styling::GREEN;
- let green_bold = GREEN.bold();
crate::output::success(format!(
- "{GREEN}Returned to primary at {green_bold}{}{green_bold:#}{GREEN:#}",
+ "{GREEN}Returned to primary at {GREEN_BOLD}{}{GREEN_BOLD:#}{GREEN:#}",
primary_worktree_dir.display()
))?;
@@ -301,12 +299,11 @@ pub fn handle_merge(
/// Format the merge summary message (no emoji - output system adds it)
fn format_merge_summary(primary_path: Option<&std::path::Path>) -> String {
use worktrunk::styling::GREEN;
- let green_bold = GREEN.bold();
// Show where we ended up
if let Some(path) = primary_path {
format!(
- "{GREEN}Returned to primary at {green_bold}{}{green_bold:#}{GREEN:#}",
+ "{GREEN}Returned to primary at {GREEN_BOLD}{}{GREEN_BOLD:#}{GREEN:#}",
path.display()
)
} else {
@@ -577,10 +574,9 @@ pub fn execute_post_merge_commands(
crate::output::gutter(format_bash_with_gutter(&prepared.expanded, ""))?;
if let Err(e) = execute_command_in_worktree(main_worktree_path, &prepared.expanded) {
- let warning_bold = WARNING.bold();
let message = match &prepared.name {
Some(name) => format!(
- "{WARNING}Command {warning_bold}{name}{warning_bold:#} failed: {e}{WARNING:#}"
+ "{WARNING}Command {WARNING_BOLD}{name}{WARNING_BOLD:#} failed: {e}{WARNING:#}"
),
None => format!("{WARNING}Command failed: {e}{WARNING:#}"),
};
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index a0e042499..40d7a90b5 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -103,7 +103,9 @@
use std::path::PathBuf;
use worktrunk::config::{CommandPhase, ProjectConfig, WorktrunkConfig};
use worktrunk::git::{GitError, GitResultExt, Repository};
-use worktrunk::styling::{CYAN, CYAN_BOLD, GREEN, GREEN_BOLD, WARNING, format_bash_with_gutter};
+use worktrunk::styling::{
+ CYAN, CYAN_BOLD, GREEN, GREEN_BOLD, WARNING, WARNING_BOLD, format_bash_with_gutter,
+};
use super::command_executor::{CommandContext, prepare_project_commands};
use crate::commands::process::spawn_detached;
@@ -283,9 +285,8 @@ pub fn handle_remove(
};
// Show progress with resolved name
- let cyan_bold = CYAN.bold();
let progress_msg = if let Some(ref b) = resolved_name {
- format!("{CYAN}Removing worktree for {cyan_bold}{b}{cyan_bold:#}...{CYAN:#}")
+ format!("{CYAN}Removing worktree for {CYAN_BOLD}{b}{CYAN_BOLD:#}...{CYAN:#}")
} else {
format!("{CYAN}Removing worktree...{CYAN:#}")
};
@@ -488,10 +489,9 @@ pub fn execute_post_create_commands(
crate::output::gutter(format_bash_with_gutter(&prepared.expanded, ""))?;
if let Err(e) = execute_command_in_worktree(worktree_path, &prepared.expanded) {
- let warning_bold = WARNING.bold();
let message = match &prepared.name {
Some(name) => format!(
- "{WARNING}Command {warning_bold}{name}{warning_bold:#} failed: {e}{WARNING:#}"
+ "{WARNING}Command {WARNING_BOLD}{name}{WARNING_BOLD:#} failed: {e}{WARNING:#}"
),
None => format!("{WARNING}Command failed: {e}{WARNING:#}"),
};
diff --git a/src/config/expansion.rs b/src/config/expansion.rs
index d62357608..c9a1186d3 100644
--- a/src/config/expansion.rs
+++ b/src/config/expansion.rs
@@ -82,8 +82,10 @@ pub fn expand_command_template(
target_branch: Option<&str>,
) -> String {
let mut extra = std::collections::HashMap::new();
- extra.insert("worktree", worktree_path.to_str().unwrap_or(""));
- extra.insert("repo_root", repo_root.to_str().unwrap_or(""));
+ let worktree_str = worktree_path.to_string_lossy();
+ let repo_root_str = repo_root.to_string_lossy();
+ extra.insert("worktree", worktree_str.as_ref());
+ extra.insert("repo_root", repo_root_str.as_ref());
if let Some(target) = target_branch {
extra.insert("target", target);
}
diff --git a/src/git/error.rs b/src/git/error.rs
index 38fb7e704..354ae44b1 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -58,7 +58,7 @@ pub enum GitError {
impl std::fmt::Display for GitError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- use crate::styling::{ERROR, ERROR_EMOJI, HINT, HINT_EMOJI};
+ use crate::styling::{ERROR, ERROR_BOLD, ERROR_EMOJI, HINT, HINT_EMOJI};
match self {
// Plain message that will be displayed by main.rs
@@ -91,19 +91,16 @@ impl std::fmt::Display for GitError {
command_name,
error,
exit_code: _,
- } => {
- let error_bold = ERROR.bold();
- match command_name {
- Some(name) => write!(
- f,
- "{ERROR_EMOJI} {ERROR}{hook_type} command failed: {error_bold}{name}{error_bold:#}{ERROR:#}\n\n{error}\n\n{HINT_EMOJI} {HINT}Use --no-hooks to skip {hook_type} commands{HINT:#}"
- ),
- None => write!(
- f,
- "{ERROR_EMOJI} {ERROR}{hook_type} command failed{ERROR:#}\n\n{error}\n\n{HINT_EMOJI} {HINT}Use --no-hooks to skip {hook_type} commands{HINT:#}"
- ),
- }
- }
+ } => match command_name {
+ Some(name) => write!(
+ f,
+ "{ERROR_EMOJI} {ERROR}{hook_type} command failed: {ERROR_BOLD}{name}{ERROR_BOLD:#}{ERROR:#}\n\n{error}\n\n{HINT_EMOJI} {HINT}Use --no-hooks to skip {hook_type} commands{HINT:#}"
+ ),
+ None => write!(
+ f,
+ "{ERROR_EMOJI} {ERROR}{hook_type} command failed{ERROR:#}\n\n{error}\n\n{HINT_EMOJI} {HINT}Use --no-hooks to skip {hook_type} commands{HINT:#}"
+ ),
+ },
// Uncommitted changes
GitError::UncommittedChanges => {
@@ -115,28 +112,25 @@ impl std::fmt::Display for GitError {
// Branch already exists
GitError::BranchAlreadyExists { branch } => {
- let error_bold = ERROR.bold();
write!(
f,
- "{ERROR_EMOJI} {ERROR}Branch {error_bold}{branch}{error_bold:#}{ERROR} already exists{ERROR:#}\n\n{HINT_EMOJI} {HINT}Remove --create flag to switch to it{HINT:#}"
+ "{ERROR_EMOJI} {ERROR}Branch {ERROR_BOLD}{branch}{ERROR_BOLD:#}{ERROR} already exists{ERROR:#}\n\n{HINT_EMOJI} {HINT}Remove --create flag to switch to it{HINT:#}"
)
}
// Worktree missing
GitError::WorktreeMissing { branch } => {
- let error_bold = ERROR.bold();
write!(
f,
- "{ERROR_EMOJI} {ERROR}Worktree directory missing for {error_bold}{branch}{error_bold:#}{ERROR:#}\n\n{HINT_EMOJI} {HINT}Run 'git worktree prune' to clean up{HINT:#}"
+ "{ERROR_EMOJI} {ERROR}Worktree directory missing for {ERROR_BOLD}{branch}{ERROR_BOLD:#}{ERROR:#}\n\n{HINT_EMOJI} {HINT}Run 'git worktree prune' to clean up{HINT:#}"
)
}
// No worktree found
GitError::NoWorktreeFound { branch } => {
- let error_bold = ERROR.bold();
write!(
f,
- "{ERROR_EMOJI} {ERROR}No worktree found for branch {error_bold}{branch}{error_bold:#}{ERROR:#}"
+ "{ERROR_EMOJI} {ERROR}No worktree found for branch {ERROR_BOLD}{branch}{ERROR_BOLD:#}{ERROR:#}"
)
}
@@ -168,11 +162,9 @@ impl std::fmt::Display for GitError {
commits_formatted,
files_formatted,
} => {
- let error_bold = ERROR.bold();
-
writeln!(
f,
- "{ERROR_EMOJI} {ERROR}Can't push to local {error_bold}{target_branch}{error_bold:#} branch: it has newer commits{ERROR:#}"
+ "{ERROR_EMOJI} {ERROR}Can't push to local {ERROR_BOLD}{target_branch}{ERROR_BOLD:#} branch: it has newer commits{ERROR:#}"
)?;
// Show the formatted commit log
@@ -224,11 +216,10 @@ impl std::fmt::Display for GitError {
git_output,
} => {
use crate::styling::format_with_gutter;
- let error_bold = ERROR.bold();
write!(
f,
- "{ERROR_EMOJI} {ERROR}Rebase onto {error_bold}{target_branch}{error_bold:#}{ERROR} incomplete{ERROR:#}"
+ "{ERROR_EMOJI} {ERROR}Rebase onto {ERROR_BOLD}{target_branch}{ERROR_BOLD:#}{ERROR} incomplete{ERROR:#}"
)?;
if !git_output.is_empty() {
diff --git a/src/git/parse.rs b/src/git/parse.rs
index a43c3a6fa..96ea6c93d 100644
--- a/src/git/parse.rs
+++ b/src/git/parse.rs
@@ -36,15 +36,13 @@ pub(crate) fn parse_worktree_list(output: &str) -> Result<Vec<Worktree>, GitErro
prunable: None,
});
}
- "HEAD" => {
- if let Some(ref mut wt) = current {
+ key => match (key, current.as_mut()) {
+ ("HEAD", Some(wt)) => {
wt.head = value
.ok_or_else(|| GitError::ParseError("HEAD line missing SHA".to_string()))?
.to_string();
}
- }
- "branch" => {
- if let Some(ref mut wt) = current {
+ ("branch", Some(wt)) => {
// Strip refs/heads/ prefix if present
let branch_ref = value.ok_or_else(|| {
GitError::ParseError("branch line missing ref".to_string())
@@ -55,30 +53,22 @@ pub(crate) fn parse_worktree_list(output: &str) -> Result<Vec<Worktree>, GitErro
.to_string();
wt.branch = Some(branch);
}
- }
- "bare" => {
- if let Some(ref mut wt) = current {
+ ("bare", Some(wt)) => {
wt.bare = true;
}
- }
- "detached" => {
- if let Some(ref mut wt) = current {
+ ("detached", Some(wt)) => {
wt.detached = true;
}
- }
- "locked" => {
- if let Some(ref mut wt) = current {
+ ("locked", Some(wt)) => {
wt.locked = Some(value.unwrap_or_default().to_string());
}
- }
- "prunable" => {
- if let Some(ref mut wt) = current {
+ ("prunable", Some(wt)) => {
wt.prunable = Some(value.unwrap_or_default().to_string());
}
- }
- _ => {
- // Ignore unknown attributes for forward compatibility
- }
+ _ => {
+ // Ignore unknown attributes or attributes before first worktree
+ }
+ },
}
}
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 96a550b36..f649dc38d 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -24,12 +24,11 @@ fn format_switch_message(result: &SwitchResult, branch: &str) -> String {
/// Format message for remove operation (includes emoji and color for consistency)
fn format_remove_message(result: &RemoveResult, branch: Option<&str>) -> String {
- use worktrunk::styling::GREEN;
- let green_bold = GREEN.bold();
+ use worktrunk::styling::{GREEN, GREEN_BOLD};
match result {
RemoveResult::AlreadyOnDefault(branch) => {
- format!("{GREEN}Already on default branch {green_bold}{branch}{green_bold:#}{GREEN:#}")
+ format!("{GREEN}Already on default branch {GREEN_BOLD}{branch}{GREEN_BOLD:#}{GREEN:#}")
}
RemoveResult::RemovedWorktree {
primary_path,
@@ -51,23 +50,23 @@ fn format_remove_message(result: &RemoveResult, branch: Option<&str>) -> String
if let Some(b) = branch_display {
// Re-establish GREEN after each green_bold reset to prevent color leak
format!(
- "{GREEN}{action} for {green_bold}{b}{green_bold:#}{GREEN}, returned to primary at {green_bold}{}{green_bold:#}{GREEN:#}",
+ "{GREEN}{action} for {GREEN_BOLD}{b}{GREEN_BOLD:#}{GREEN}, returned to primary at {GREEN_BOLD}{}{GREEN_BOLD:#}{GREEN:#}",
primary_path.display()
)
} else {
format!(
- "{GREEN}{action}, returned to primary at {green_bold}{}{green_bold:#}{GREEN:#}",
+ "{GREEN}{action}, returned to primary at {GREEN_BOLD}{}{GREEN_BOLD:#}{GREEN:#}",
primary_path.display()
)
}
} else if let Some(b) = branch_display {
- format!("{GREEN}{action} for {green_bold}{b}{green_bold:#}{GREEN:#}")
+ format!("{GREEN}{action} for {GREEN_BOLD}{b}{GREEN_BOLD:#}{GREEN:#}")
} else {
format!("{GREEN}{action}{GREEN:#}")
}
}
RemoveResult::SwitchedToDefault(branch) => {
- format!("{GREEN}Switched to default branch {green_bold}{branch}{green_bold:#}{GREEN:#}")
+ format!("{GREEN}Switched to default branch {GREEN_BOLD}{branch}{GREEN_BOLD:#}{GREEN:#}")
}
}
}
@@ -150,12 +149,11 @@ pub fn handle_remove_output(result: &RemoveResult, branch: Option<&str>) -> Resu
if let Err(e) = result {
// If branch deletion fails, show a warning but don't error
// This matches the user's request: "print a nice message, don't raise some big error"
- use worktrunk::styling::{WARNING, WARNING_EMOJI};
- let warning_bold = WARNING.bold();
+ use worktrunk::styling::{WARNING, WARNING_BOLD, WARNING_EMOJI};
// Normalize error message to single line to prevent formatting issues
let error_msg = e.to_string().replace('\n', " ").trim().to_string();
super::progress(format!(
- "{WARNING_EMOJI} {WARNING}Could not delete branch {warning_bold}{branch_name}{warning_bold:#}: {error_msg}{WARNING:#}"
+ "{WARNING_EMOJI} {WARNING}Could not delete branch {WARNING_BOLD}{branch_name}{WARNING_BOLD:#}: {error_msg}{WARNING:#}"
))?;
}
}
diff --git a/src/output/mod.rs b/src/output/mod.rs
index c6229728e..4c3df3cfa 100644
--- a/src/output/mod.rs
+++ b/src/output/mod.rs
@@ -86,8 +86,7 @@ pub(crate) fn format_switch_success_message(
base_branch: Option<&str>,
use_past_tense: bool,
) -> String {
- use worktrunk::styling::GREEN;
- let green_bold = GREEN.bold();
+ use worktrunk::styling::{GREEN, GREEN_BOLD};
let action = if created_branch {
"Created new worktree for"
@@ -99,11 +98,11 @@ pub(crate) fn format_switch_success_message(
// Re-establish GREEN after each green_bold reset to prevent color leak
match base_branch {
Some(base) => format!(
- "{GREEN}{action} {green_bold}{branch}{green_bold:#}{GREEN} from {green_bold}{base}{green_bold:#}{GREEN}{location} {green_bold}{}{green_bold:#}{GREEN:#}",
+ "{GREEN}{action} {GREEN_BOLD}{branch}{GREEN_BOLD:#}{GREEN} from {GREEN_BOLD}{base}{GREEN_BOLD:#}{GREEN}{location} {GREEN_BOLD}{}{GREEN_BOLD:#}{GREEN:#}",
path.display()
),
None => format!(
- "{GREEN}{action} {green_bold}{branch}{green_bold:#}{GREEN}{location} {green_bold}{}{green_bold:#}{GREEN:#}",
+ "{GREEN}{action} {GREEN_BOLD}{branch}{GREEN_BOLD:#}{GREEN}{location} {GREEN_BOLD}{}{GREEN_BOLD:#}{GREEN:#}",
path.display()
),
}
diff --git a/src/styling/constants.rs b/src/styling/constants.rs
index f146a07e0..0bb77322f 100644
--- a/src/styling/constants.rs
+++ b/src/styling/constants.rs
@@ -11,12 +11,25 @@ use anstyle::{AnsiColor, Color, Style};
/// Error style (red) - use as `{ERROR}text{ERROR:#}`
pub const ERROR: Style = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Red)));
+/// Error bold style (red + bold) - use as `{ERROR_BOLD}text{ERROR_BOLD:#}`
+pub const ERROR_BOLD: Style = Style::new()
+ .fg_color(Some(Color::Ansi(AnsiColor::Red)))
+ .bold();
+
/// Warning style (yellow) - use as `{WARNING}text{WARNING:#}`
pub const WARNING: Style = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Yellow)));
+/// Warning bold style (yellow + bold) - use as `{WARNING_BOLD}text{WARNING_BOLD:#}`
+pub const WARNING_BOLD: Style = Style::new()
+ .fg_color(Some(Color::Ansi(AnsiColor::Yellow)))
+ .bold();
+
/// Hint style (dimmed) - use as `{HINT}text{HINT:#}`
pub const HINT: Style = Style::new().dimmed();
+/// Hint bold style (dimmed + bold) - use as `{HINT_BOLD}text{HINT_BOLD:#}`
+pub const HINT_BOLD: Style = Style::new().dimmed().bold();
+
/// Current worktree style (magenta + bold)
pub const CURRENT: Style = Style::new()
.bold()
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index e6a52280b..1602fe1ed 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -100,6 +100,29 @@ impl TestRepo {
cmd.env("SOURCE_DATE_EPOCH", "1761609600");
}
+ /// Create a configured git command with args and current_dir set
+ ///
+ /// This is a convenience wrapper around configure_git_cmd that reduces boilerplate.
+ /// Returns a Command ready to execute with .output(), .status(), etc.
+ ///
+ /// # Example
+ /// ```ignore
+ /// // Before:
+ /// let mut cmd = Command::new("git");
+ /// self.configure_git_cmd(&mut cmd);
+ /// cmd.args(["add", "."]).current_dir(&self.root).output()?;
+ ///
+ /// // After:
+ /// self.git_command(&["add", "."]).output()?;
+ /// ```
+ pub fn git_command(&self, args: &[&str]) -> Command {
+ let mut cmd = Command::new("git");
+ self.configure_git_cmd(&mut cmd);
+ cmd.args(args);
+ cmd.current_dir(&self.root);
+ cmd
+ }
+
/// Clean environment for worktrunk CLI commands
///
/// Removes potentially interfering environment variables and sets
@@ -199,17 +222,11 @@ impl TestRepo {
let file_path = self.root.join("file.txt");
std::fs::write(&file_path, message).expect("Failed to write file");
- let mut cmd = Command::new("git");
- self.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&self.root)
+ self.git_command(&["add", "."])
.output()
.expect("Failed to git add");
- let mut cmd = Command::new("git");
- self.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", message])
- .current_dir(&self.root)
+ self.git_command(&["commit", "-m", message])
.output()
.expect("Failed to git commit");
}
@@ -225,17 +242,11 @@ impl TestRepo {
let file_path = self.root.join(format!("file-{}.txt", timestamp));
std::fs::write(&file_path, "content").expect("Failed to write file");
- let mut cmd = Command::new("git");
- self.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&self.root)
+ self.git_command(&["add", "."])
.output()
.expect("Failed to git add");
- let mut cmd = Command::new("git");
- self.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", message])
- .current_dir(&self.root)
+ self.git_command(&["commit", "-m", message])
.output()
.expect("Failed to git commit");
}