Skip to content

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

Introduce error formatting for consistent user feedback

Maximilian Roos868c2d4660a6
diff --git a/benches/completion.rs b/benches/completion.rs
index f74d5992d..7a8fc30d1 100644
--- a/benches/completion.rs
+++ b/benches/completion.rs
@@ -9,27 +9,27 @@ fn setup_test_repo(num_branches: usize, num_worktrees: usize) -> TempDir {
// Initialize git repo
Command::new("git")
- .args(&["init"])
+ .args(["init"])
.current_dir(repo_path)
.output()
.unwrap();
// Configure git
Command::new("git")
- .args(&["config", "user.name", "Test"])
+ .args(["config", "user.name", "Test"])
.current_dir(repo_path)
.output()
.unwrap();
Command::new("git")
- .args(&["config", "user.email", "[email protected]"])
+ .args(["config", "user.email", "[email protected]"])
.current_dir(repo_path)
.output()
.unwrap();
// Create initial commit
Command::new("git")
- .args(&["commit", "--allow-empty", "-m", "initial"])
+ .args(["commit", "--allow-empty", "-m", "initial"])
.current_dir(repo_path)
.output()
.unwrap();
@@ -37,7 +37,7 @@ fn setup_test_repo(num_branches: usize, num_worktrees: usize) -> TempDir {
// Create branches
for i in 0..num_branches {
Command::new("git")
- .args(&["branch", &format!("branch-{}", i)])
+ .args(["branch", &format!("branch-{}", i)])
.current_dir(repo_path)
.output()
.unwrap();
@@ -47,7 +47,7 @@ fn setup_test_repo(num_branches: usize, num_worktrees: usize) -> TempDir {
for i in 0..num_worktrees {
let worktree_path = repo_path.join(format!("wt-{}", i));
Command::new("git")
- .args(&[
+ .args([
"worktree",
"add",
"-b",
@@ -70,7 +70,7 @@ fn bench_completion_switch(c: &mut Criterion) {
let temp = setup_test_repo(10, 0);
b.iter(|| {
Command::new("cargo")
- .args(&["run", "--", "complete", "wt", "switch", ""])
+ .args(["run", "--", "complete", "wt", "switch", ""])
.current_dir(temp.path())
.output()
.unwrap();
@@ -82,7 +82,7 @@ fn bench_completion_switch(c: &mut Criterion) {
let temp = setup_test_repo(50, 0);
b.iter(|| {
Command::new("cargo")
- .args(&["run", "--", "complete", "wt", "switch", ""])
+ .args(["run", "--", "complete", "wt", "switch", ""])
.current_dir(temp.path())
.output()
.unwrap();
@@ -94,7 +94,7 @@ fn bench_completion_switch(c: &mut Criterion) {
let temp = setup_test_repo(100, 0);
b.iter(|| {
Command::new("cargo")
- .args(&["run", "--", "complete", "wt", "switch", ""])
+ .args(["run", "--", "complete", "wt", "switch", ""])
.current_dir(temp.path())
.output()
.unwrap();
@@ -112,7 +112,7 @@ fn bench_completion_switch_with_worktrees(c: &mut Criterion) {
let temp = setup_test_repo(50, 10);
b.iter(|| {
Command::new("cargo")
- .args(&["run", "--", "complete", "wt", "switch", ""])
+ .args(["run", "--", "complete", "wt", "switch", ""])
.current_dir(temp.path())
.output()
.unwrap();
@@ -130,7 +130,7 @@ fn bench_completion_push(c: &mut Criterion) {
let temp = setup_test_repo(100, 0);
b.iter(|| {
Command::new("cargo")
- .args(&["run", "--", "complete", "wt", "push", ""])
+ .args(["run", "--", "complete", "wt", "push", ""])
.current_dir(temp.path())
.output()
.unwrap();
diff --git a/src/error_format.rs b/src/error_format.rs
new file mode 100644
index 000000000..48d57a83e
--- /dev/null
+++ b/src/error_format.rs
@@ -0,0 +1,178 @@
+use anstyle::{AnsiColor, Color, Style};
+use std::io::IsTerminal;
+
+/// Determines if colored output should be used
+fn should_use_color() -> bool {
+ // Check for force color environment variables (for testing)
+ if std::env::var("CLICOLOR_FORCE").is_ok() || std::env::var("FORCE_COLOR").is_ok() {
+ return true;
+ }
+
+ // Check if NO_COLOR is set (universal way to disable colors)
+ if std::env::var("NO_COLOR").is_ok() {
+ return false;
+ }
+
+ // Otherwise use TTY detection
+ std::io::stderr().is_terminal()
+}
+
+/// Format an error message with red color and ❌ emoji
+pub fn format_error(msg: &str) -> String {
+ if should_use_color() {
+ let error_style = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Red)));
+ format!(
+ "{}❌ {}{}",
+ error_style.render(),
+ msg,
+ error_style.render_reset()
+ )
+ } else {
+ format!("❌ {}", msg)
+ }
+}
+
+/// Format a warning message with yellow color and 🟡 emoji
+pub fn format_warning(msg: &str) -> String {
+ if should_use_color() {
+ let warning_style = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Yellow)));
+ format!(
+ "{}🟡 {}{}",
+ warning_style.render(),
+ msg,
+ warning_style.render_reset()
+ )
+ } else {
+ format!("🟡 {}", msg)
+ }
+}
+
+/// Format a hint message with dim color and 💡 emoji
+pub fn format_hint(msg: &str) -> String {
+ if should_use_color() {
+ let hint_style = Style::new().dimmed();
+ format!(
+ "{}💡 {}{}",
+ hint_style.render(),
+ msg,
+ hint_style.render_reset()
+ )
+ } else {
+ format!("💡 {}", msg)
+ }
+}
+
+/// Format text with bold styling
+pub fn bold(text: &str) -> String {
+ if should_use_color() {
+ let bold_style = Style::new().bold();
+ format!(
+ "{}{}{}",
+ bold_style.render(),
+ text,
+ bold_style.render_reset()
+ )
+ } else {
+ text.to_string()
+ }
+}
+
+/// Format text with a specific color
+pub fn colored(text: &str, color: AnsiColor) -> String {
+ if should_use_color() {
+ let style = Style::new().fg_color(Some(Color::Ansi(color)));
+ format!("{}{}{}", style.render(), text, style.render_reset())
+ } else {
+ text.to_string()
+ }
+}
+
+/// Format an error message with bold emphasis on specific parts
+///
+/// Example: `format_error_with_bold("Branch '", "feature-x", "' already exists")`
+pub fn format_error_with_bold(prefix: &str, emphasized: &str, suffix: &str) -> String {
+ if should_use_color() {
+ let error_style = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Red)));
+ let bold_style = Style::new()
+ .fg_color(Some(Color::Ansi(AnsiColor::Red)))
+ .bold();
+ format!(
+ "{}❌ {}{}{}{}{}{}",
+ error_style.render(),
+ prefix,
+ bold_style.render(),
+ emphasized,
+ error_style.render(), // Back to regular red
+ suffix,
+ error_style.render_reset()
+ )
+ } else {
+ format!("❌ {}{}{}", prefix, emphasized, suffix)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_format_error_no_color() {
+ // Ensure NO_COLOR disables formatting
+ unsafe {
+ std::env::set_var("NO_COLOR", "1");
+ }
+ let result = format_error("Test error");
+ assert_eq!(result, "❌ Test error");
+ unsafe {
+ std::env::remove_var("NO_COLOR");
+ }
+ }
+
+ #[test]
+ fn test_format_error_with_bold_no_color() {
+ unsafe {
+ std::env::set_var("NO_COLOR", "1");
+ }
+ let result = format_error_with_bold("Branch '", "main", "' already exists");
+ assert_eq!(result, "❌ Branch 'main' already exists");
+ unsafe {
+ std::env::remove_var("NO_COLOR");
+ }
+ }
+
+ #[test]
+ fn test_format_warning() {
+ unsafe {
+ std::env::set_var("NO_COLOR", "1");
+ }
+ let result = format_warning("Test warning");
+ assert_eq!(result, "🟡 Test warning");
+ unsafe {
+ std::env::remove_var("NO_COLOR");
+ }
+ }
+
+ #[test]
+ fn test_format_hint() {
+ unsafe {
+ std::env::set_var("NO_COLOR", "1");
+ }
+ let result = format_hint("Test hint");
+ assert_eq!(result, "💡 Test hint");
+ unsafe {
+ std::env::remove_var("NO_COLOR");
+ }
+ }
+
+ #[test]
+ fn test_bold() {
+ unsafe {
+ std::env::set_var("NO_COLOR", "1");
+ }
+ let result = bold("important");
+ assert_eq!(result, "important");
+ unsafe {
+ std::env::remove_var("NO_COLOR");
+ }
+ }
+}
diff --git a/src/git.rs b/src/git.rs
index 818919388..372b8bb4e 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -21,8 +21,13 @@ pub enum GitError {
impl std::fmt::Display for GitError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
- GitError::CommandFailed(msg) => write!(f, "Git command failed: {}", msg),
- GitError::ParseError(msg) => write!(f, "Parse error: {}", msg),
+ // CommandFailed messages are already formatted with emoji and colors
+ GitError::CommandFailed(msg) => write!(f, "{}", msg),
+ // ParseError messages need formatting
+ GitError::ParseError(msg) => {
+ use crate::error_format::format_error;
+ write!(f, "{}", format_error(msg))
+ }
}
}
}
diff --git a/src/lib.rs b/src/lib.rs
index b67abd2d3..f71b539e8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,4 @@
pub mod config;
+pub mod error_format;
pub mod git;
pub mod shell;
diff --git a/src/main.rs b/src/main.rs
index 58d9178c2..26d441048 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,7 @@ use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
use clap_complete::{Shell as CompletionShell, generate};
use std::io;
use std::process;
+use worktrunk::error_format::{format_error_with_bold, format_hint, format_warning};
use worktrunk::git::{
GitError, branch_exists, count_commits, get_ahead_behind_in, get_all_branches,
get_available_branches, get_branch_diff_stats_in, get_changed_files, get_commit_timestamp_in,
@@ -146,7 +147,8 @@ fn main() {
};
if let Err(e) = result {
- eprintln!("Error: {}", e);
+ // Error messages are already formatted with emoji and colors
+ eprintln!("{}", e);
process::exit(1);
}
}
@@ -247,20 +249,24 @@ fn handle_list() -> Result<(), GitError> {
let timestamp = get_commit_timestamp_in(&wt.path, &wt.head).unwrap_or(0);
// Calculate ahead/behind relative to primary branch (only if primary has a branch)
- let (ahead, behind) = if is_primary || primary_branch.is_none() {
+ let (ahead, behind) = if is_primary {
(0, 0)
+ } else if let Some(pb) = primary_branch {
+ get_ahead_behind_in(&wt.path, pb, &wt.head).unwrap_or((0, 0))
} else {
- get_ahead_behind_in(&wt.path, primary_branch.unwrap(), &wt.head).unwrap_or((0, 0))
+ (0, 0)
};
// Get working tree diff stats
let working_tree_diff = get_working_tree_diff_stats_in(&wt.path).unwrap_or((0, 0));
// Get branch diff stats (downstream of primary, only if primary has a branch)
- let branch_diff = if is_primary || primary_branch.is_none() {
+ let branch_diff = if is_primary {
(0, 0)
+ } else if let Some(pb) = primary_branch {
+ get_branch_diff_stats_in(&wt.path, pb, &wt.head).unwrap_or((0, 0))
} else {
- get_branch_diff_stats_in(&wt.path, primary_branch.unwrap(), &wt.head).unwrap_or((0, 0))
+ (0, 0)
};
infos.push(WorktreeInfo {
@@ -474,15 +480,19 @@ fn handle_switch(
) -> Result<(), GitError> {
// Check for conflicting conditions
if create && branch_exists(branch)? {
- return Err(GitError::CommandFailed(format!(
- "Branch '{}' already exists. Remove --create flag to switch to it.",
- branch
+ return Err(GitError::CommandFailed(format_error_with_bold(
+ "Branch '",
+ branch,
+ "' already exists. Remove --create flag to switch to it.",
)));
}
// Check if base flag was provided without create flag
if base.is_some() && !create {
- eprintln!("Warning: --base flag is only used with --create, ignoring");
+ eprintln!(
+ "{}",
+ format_warning("--base flag is only used with --create, ignoring")
+ );
}
// Check if worktree already exists for this branch
@@ -493,9 +503,10 @@ fn handle_switch(
}
return Ok(());
} else {
- return Err(GitError::CommandFailed(format!(
- "Worktree directory missing for '{}'. Run 'git worktree prune' to clean up.",
- branch
+ return Err(GitError::CommandFailed(format_error_with_bold(
+ "Worktree directory missing for '",
+ branch,
+ "'. Run 'git worktree prune' to clean up.",
)));
}
}
@@ -566,9 +577,10 @@ fn handle_switch(
fn handle_remove(internal: bool) -> Result<(), GitError> {
// Check for uncommitted changes
if is_dirty()? {
- return Err(GitError::CommandFailed(
- "Working tree has uncommitted changes. Commit or stash them first.".to_string(),
- ));
+ use worktrunk::error_format::format_error;
+ return Err(GitError::CommandFailed(format_error(
+ "Working tree has uncommitted changes. Commit or stash them first.",
+ )));
}
// Get current state
@@ -648,17 +660,23 @@ fn handle_push(target: Option<&str>, allow_merge_commits: bool) -> Result<(), Gi
// Check if it's a fast-forward
if !is_ancestor(&target_branch, "HEAD")? {
+ let error_msg =
+ format_error_with_bold("Not a fast-forward from '", &target_branch, "' to HEAD");
+ let hint_msg = format_hint(
+ "The target branch has commits not in your current branch. Consider 'git pull' or 'git rebase'",
+ );
return Err(GitError::CommandFailed(format!(
- "Not a fast-forward from '{}' to HEAD. The target branch has commits not in your current branch.",
- target_branch
+ "{}\n{}",
+ error_msg, hint_msg
)));
}
// Check for merge commits unless allowed
if !allow_merge_commits && has_merge_commits(&target_branch, "HEAD")? {
- return Err(GitError::CommandFailed(
- "Found merge commits in push range. Use --allow-merge-commits to push non-linear history.".to_string(),
- ));
+ use worktrunk::error_format::format_error;
+ return Err(GitError::CommandFailed(format_error(
+ "Found merge commits in push range. Use --allow-merge-commits to push non-linear history.",
+ )));
}
// Configure receive.denyCurrentBranch if needed
@@ -708,7 +726,11 @@ fn handle_push(target: Option<&str>, allow_merge_commits: bool) -> Result<(), Gi
.collect();
if !overlapping.is_empty() {
- eprintln!("Cannot push: conflicting uncommitted changes in:");
+ use worktrunk::error_format::format_error;
+ eprintln!(
+ "{}",
+ format_error("Cannot push: conflicting uncommitted changes in:")
+ );
for file in &overlapping {
eprintln!(" - {}", file);
}
@@ -758,8 +780,9 @@ fn handle_push(target: Option<&str>, allow_merge_commits: bool) -> Result<(), Gi
fn handle_merge(target: Option<&str>, keep: bool) -> Result<(), GitError> {
// Get current branch
+ use worktrunk::error_format::format_error;
let current_branch = get_current_branch()?
- .ok_or_else(|| GitError::CommandFailed("Not on a branch (detached HEAD)".to_string()))?;
+ .ok_or_else(|| GitError::CommandFailed(format_error("Not on a branch (detached HEAD)")))?;
// Get target branch (default to default branch if not provided)
let target_branch = match target {
@@ -775,9 +798,10 @@ fn handle_merge(target: Option<&str>, keep: bool) -> Result<(), GitError> {
// Check for uncommitted changes
if is_dirty()? {
- return Err(GitError::CommandFailed(
- "Working tree has uncommitted changes. Commit or stash them first.".to_string(),
- ));
+ use worktrunk::error_format::format_error;
+ return Err(GitError::CommandFailed(format_error(
+ "Working tree has uncommitted changes. Commit or stash them first.",
+ )));
}
// Rebase onto target
@@ -887,8 +911,8 @@ fn parse_completion_context(args: &[String]) -> CompletionContext {
"switch" => {
// Check if we're completing --base flag value
if args.len() >= 3 {
- for i in 2..args.len() - 1 {
- if args[i] == "--base" || args[i] == "-b" {
+ for arg in args.iter().skip(2).take(args.len() - 3) {
+ if arg == "--base" || arg == "-b" {
// We're completing the value after --base
return CompletionContext::BaseFlag;
}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 349d42d37..8feb16292 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -106,6 +106,8 @@ impl TestRepo {
}
// Set deterministic environment for git
self.configure_git_cmd(cmd);
+ // Force color output for snapshot testing (captures ANSI codes)
+ cmd.env("CLICOLOR_FORCE", "1");
}
/// Get the root path of the repository
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index 2d9248d5b..9f6e26c47 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -41,13 +41,13 @@ fn test_complete_switch_shows_branches() {
// Create some branches using git
StdCommand::new("git")
- .args(&["branch", "feature/new"])
+ .args(["branch", "feature/new"])
.current_dir(temp.root_path())
.output()
.unwrap();
StdCommand::new("git")
- .args(&["branch", "hotfix/bug"])
+ .args(["branch", "hotfix/bug"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -56,7 +56,7 @@ fn test_complete_switch_shows_branches() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "switch", ""])
+ .args(["complete", "wt", "switch", ""])
.output()
.unwrap();
@@ -79,7 +79,7 @@ fn test_complete_switch_excludes_branches_with_worktrees() {
// Create another branch without worktree
StdCommand::new("git")
- .args(&["branch", "hotfix/bug"])
+ .args(["branch", "hotfix/bug"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -88,7 +88,7 @@ fn test_complete_switch_excludes_branches_with_worktrees() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "switch", ""])
+ .args(["complete", "wt", "switch", ""])
.output()
.unwrap();
@@ -112,7 +112,7 @@ fn test_complete_push_shows_all_branches() {
// Create another branch without worktree
StdCommand::new("git")
- .args(&["branch", "hotfix/bug"])
+ .args(["branch", "hotfix/bug"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -121,7 +121,7 @@ fn test_complete_push_shows_all_branches() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "push", ""])
+ .args(["complete", "wt", "push", ""])
.output()
.unwrap();
@@ -141,13 +141,13 @@ fn test_complete_base_flag_shows_all_branches() {
// Create branches
StdCommand::new("git")
- .args(&["branch", "develop"])
+ .args(["branch", "develop"])
.current_dir(temp.root_path())
.output()
.unwrap();
StdCommand::new("git")
- .args(&["branch", "feature/existing"])
+ .args(["branch", "feature/existing"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -156,7 +156,7 @@ fn test_complete_base_flag_shows_all_branches() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&[
+ .args([
"complete",
"wt",
"switch",
@@ -185,7 +185,7 @@ fn test_complete_outside_git_repo_returns_empty() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.path())
- .args(&["complete", "wt", "switch", ""])
+ .args(["complete", "wt", "switch", ""])
.output()
.unwrap();
@@ -228,7 +228,7 @@ fn test_complete_base_flag_short_form() {
// Create branches
StdCommand::new("git")
- .args(&["branch", "develop"])
+ .args(["branch", "develop"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -237,7 +237,7 @@ fn test_complete_base_flag_short_form() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&[
+ .args([
"complete",
"wt",
"switch",
@@ -266,7 +266,7 @@ fn test_complete_empty_repo_returns_empty() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "switch", ""])
+ .args(["complete", "wt", "switch", ""])
.output()
.unwrap();
@@ -283,19 +283,19 @@ fn test_complete_with_partial_prefix() {
// Create branches with common prefix
StdCommand::new("git")
- .args(&["branch", "feature/one"])
+ .args(["branch", "feature/one"])
.current_dir(temp.root_path())
.output()
.unwrap();
StdCommand::new("git")
- .args(&["branch", "feature/two"])
+ .args(["branch", "feature/two"])
.current_dir(temp.root_path())
.output()
.unwrap();
StdCommand::new("git")
- .args(&["branch", "hotfix/bug"])
+ .args(["branch", "hotfix/bug"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -305,7 +305,7 @@ fn test_complete_with_partial_prefix() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "switch", "feat"])
+ .args(["complete", "wt", "switch", "feat"])
.output()
.unwrap();
@@ -333,7 +333,7 @@ fn test_complete_switch_no_available_branches() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "switch", ""])
+ .args(["complete", "wt", "switch", ""])
.output()
.unwrap();
@@ -353,14 +353,14 @@ fn test_complete_excludes_remote_branches() {
// Create local branches
StdCommand::new("git")
- .args(&["branch", "feature/local"])
+ .args(["branch", "feature/local"])
.current_dir(temp.root_path())
.output()
.unwrap();
// Set up a fake remote
StdCommand::new("git")
- .args(&["remote", "add", "origin", "https://example.com/repo.git"])
+ .args(["remote", "add", "origin", "https://example.com/repo.git"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -369,33 +369,33 @@ fn test_complete_excludes_remote_branches() {
// First, create a bare repo to act as remote
let remote_dir = temp.root_path().parent().unwrap().join("remote.git");
StdCommand::new("git")
- .args(&["init", "--bare", remote_dir.to_str().unwrap()])
+ .args(["init", "--bare", remote_dir.to_str().unwrap()])
.output()
.unwrap();
// Update remote URL to point to our bare repo
StdCommand::new("git")
- .args(&["remote", "set-url", "origin", remote_dir.to_str().unwrap()])
+ .args(["remote", "set-url", "origin", remote_dir.to_str().unwrap()])
.current_dir(temp.root_path())
.output()
.unwrap();
// Push to create remote branches
StdCommand::new("git")
- .args(&["push", "origin", "main"])
+ .args(["push", "origin", "main"])
.current_dir(temp.root_path())
.output()
.unwrap();
StdCommand::new("git")
- .args(&["push", "origin", "feature/local:feature/remote"])
+ .args(["push", "origin", "feature/local:feature/remote"])
.current_dir(temp.root_path())
.output()
.unwrap();
// Fetch to create remote-tracking branches
StdCommand::new("git")
- .args(&["fetch", "origin"])
+ .args(["fetch", "origin"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -404,7 +404,7 @@ fn test_complete_excludes_remote_branches() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "switch", ""])
+ .args(["complete", "wt", "switch", ""])
.output()
.unwrap();
@@ -439,7 +439,7 @@ fn test_complete_merge_shows_branches() {
// Create another branch without worktree
StdCommand::new("git")
- .args(&["branch", "hotfix/bug"])
+ .args(["branch", "hotfix/bug"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -448,7 +448,7 @@ fn test_complete_merge_shows_branches() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "merge", ""])
+ .args(["complete", "wt", "merge", ""])
.output()
.unwrap();
@@ -468,7 +468,7 @@ fn test_complete_unknown_command_returns_empty() {
// Create some branches
StdCommand::new("git")
- .args(&["branch", "feature/test"])
+ .args(["branch", "feature/test"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -477,7 +477,7 @@ fn test_complete_unknown_command_returns_empty() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "unknown-command", ""])
+ .args(["complete", "wt", "unknown-command", ""])
.output()
.unwrap();
@@ -502,7 +502,7 @@ fn test_complete_with_special_characters_in_branch_names() {
for branch in &branch_names {
StdCommand::new("git")
- .args(&["branch", branch])
+ .args(["branch", branch])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -512,7 +512,7 @@ fn test_complete_with_special_characters_in_branch_names() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "switch", ""])
+ .args(["complete", "wt", "switch", ""])
.output()
.unwrap();
@@ -536,7 +536,7 @@ fn test_complete_list_command_returns_empty() {
// Create branches
StdCommand::new("git")
- .args(&["branch", "feature/test"])
+ .args(["branch", "feature/test"])
.current_dir(temp.root_path())
.output()
.unwrap();
@@ -545,7 +545,7 @@ fn test_complete_list_command_returns_empty() {
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(temp.root_path())
- .args(&["complete", "wt", "list", ""])
+ .args(["complete", "wt", "list", ""])
.output()
.unwrap();
diff --git a/tests/snapshots/integration__integration_tests__directives__remove_internal_directive.snap b/tests/snapshots/integration__integration_tests__directives__remove_internal_directive.snap
index 7312f0112..eb61af9fd 100644
--- a/tests/snapshots/integration__integration_tests__directives__remove_internal_directive.snap
+++ b/tests/snapshots/integration__integration_tests__directives__remove_internal_directive.snap
@@ -3,9 +3,10 @@ source: tests/integration_tests/directives.rs
info:
program: wt
args:
- - finish
+ - remove
- "--internal"
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -20,7 +21,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Error: Git command failed: fatal: 'origin' does not appear to be a git repository
+fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
diff --git a/tests/snapshots/integration__integration_tests__directives__remove_without_internal.snap b/tests/snapshots/integration__integration_tests__directives__remove_without_internal.snap
index 531a28de1..143917a7d 100644
--- a/tests/snapshots/integration__integration_tests__directives__remove_without_internal.snap
+++ b/tests/snapshots/integration__integration_tests__directives__remove_without_internal.snap
@@ -3,8 +3,9 @@ source: tests/integration_tests/directives.rs
info:
program: wt
args:
- - finish
+ - remove
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -19,7 +20,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Error: Git command failed: fatal: 'origin' does not appear to be a git repository
+fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
diff --git a/tests/snapshots/integration__integration_tests__directives__switch_internal_directive.snap b/tests/snapshots/integration__integration_tests__directives__switch_internal_directive.snap
index c0d2f93bb..633bb1f3c 100644
--- a/tests/snapshots/integration__integration_tests__directives__switch_internal_directive.snap
+++ b/tests/snapshots/integration__integration_tests__directives__switch_internal_directive.snap
@@ -7,6 +7,7 @@ info:
- my-feature
- "--internal"
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -21,4 +22,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Error: Git command failed: fatal: invalid reference: my-feature
+fatal: invalid reference: my-feature
diff --git a/tests/snapshots/integration__integration_tests__directives__switch_without_internal.snap b/tests/snapshots/integration__integration_tests__directives__switch_without_internal.snap
index 345b7a49e..058240f43 100644
--- a/tests/snapshots/integration__integration_tests__directives__switch_without_internal.snap
+++ b/tests/snapshots/integration__integration_tests__directives__switch_without_internal.snap
@@ -6,6 +6,7 @@ info:
- switch
- my-feature
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -20,4 +21,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Error: Git command failed: fatal: invalid reference: my-feature
+fatal: invalid reference: my-feature
diff --git a/tests/snapshots/integration__integration_tests__init__init_invalid_hook.snap b/tests/snapshots/integration__integration_tests__init__init_invalid_hook.snap
index f5a4f2047..f7718af91 100644
--- a/tests/snapshots/integration__integration_tests__init__init_invalid_hook.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_invalid_hook.snap
@@ -8,6 +8,7 @@ info:
- "--hook"
- invalid
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -22,4 +23,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Error: Git command failed: Invalid hook mode: invalid
+Invalid hook mode: invalid
diff --git a/tests/snapshots/integration__integration_tests__init__init_invalid_shell.snap b/tests/snapshots/integration__integration_tests__init__init_invalid_shell.snap
index cc094d0b8..5d0dade61 100644
--- a/tests/snapshots/integration__integration_tests__init__init_invalid_shell.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_invalid_shell.snap
@@ -6,6 +6,7 @@ info:
- init
- invalid-shell
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -20,4 +21,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Error: Git command failed: Unsupported shell: invalid-shell
+Unsupported shell: invalid-shell
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap b/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap
index eaa490805..114664107 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap
@@ -6,6 +6,7 @@ info:
- merge
- main
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -20,4 +21,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Error: Git command failed: Working tree has uncommitted changes. Commit or stash them first.
+❌ Working tree has uncommitted changes. Commit or stash them first.
diff --git a/tests/snapshots/integration__integration_tests__push__push_dirty_target.snap b/tests/snapshots/integration__integration_tests__push__push_dirty_target.snap
index c72f2e4ce..7f7bc34f0 100644
--- a/tests/snapshots/integration__integration_tests__push__push_dirty_target.snap
+++ b/tests/snapshots/integration__integration_tests__push__push_dirty_target.snap
@@ -6,6 +6,7 @@ info:
- push
- main
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -20,6 +21,6 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Cannot push: conflicting uncommitted changes in:
+❌ Cannot push: conflicting uncommitted changes in:
- conflict.txt
-Error: Git command failed: Commit or stash changes in [REPO] first
+Commit or stash changes in [REPO] first
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_dirty_working_tree.snap b/tests/snapshots/integration__integration_tests__remove__remove_dirty_working_tree.snap
index 8386111b0..25f856d2d 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_dirty_working_tree.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_dirty_working_tree.snap
@@ -1,10 +1,11 @@
---
-source: tests/integration_tests/finish.rs
+source: tests/integration_tests/remove.rs
info:
program: wt
args:
- - finish
+ - remove
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -19,4 +20,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Error: Git command failed: Working tree has uncommitted changes. Commit or stash them first.
+❌ Working tree has uncommitted changes. Commit or stash them first.
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_base_without_create.snap b/tests/snapshots/integration__integration_tests__switch__switch_base_without_create.snap
index d37a7183a..9355bb26a 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_base_without_create.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_base_without_create.snap
@@ -1,13 +1,14 @@
---
source: tests/integration_tests/switch.rs
info:
- program: arbor
+ program: wt
args:
- switch
- "--base"
- main
- main
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -22,4 +23,4 @@ exit_code: 0
----- stdout -----
----- stderr -----
-Warning: --base flag is only used with --create, ignoring
+🟡 --base flag is only used with --create, ignoring
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_create_existing_error.snap b/tests/snapshots/integration__integration_tests__switch__switch_create_existing_error.snap
index a1ff9aae0..69c514305 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_create_existing_error.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_create_existing_error.snap
@@ -1,12 +1,13 @@
---
source: tests/integration_tests/switch.rs
info:
- program: arbor
+ program: wt
args:
- switch
- "--create"
- feature-y
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -21,4 +22,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-Error: Git command failed: Branch 'feature-y' already exists. Remove --create flag to switch to it.
+❌ Branch 'feature-y' already exists. Remove --create flag to switch to it.