Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Include executed git command in error messages
Maximilian Roos200eea431b7c
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rsindex b2eff96e0..413d5c805 100644--- a/src/git/repository/mod.rs+++ b/src/git/repository/mod.rs@@ -1405,7 +1405,9 @@ impl Repository {};let t0 = Instant::now();- let output = cmd.output().context("Failed to execute git command")?;+ let output = cmd+ .output()+ .with_context(|| format!("Failed to execute: git {}", args.join(" ")))?;let duration = t0.elapsed();// Performance tracing at debug level (enable with RUST_LOG=debug)@@ -1475,7 +1477,9 @@ impl Repository {log::debug!("$ git {} [{}]", args.join(" "), worktree);}- let output = cmd.output().context("Failed to execute git command")?;+ let output = cmd+ .output()+ .with_context(|| format!("Failed to execute: git {}", args.join(" ")))?;let success = output.status.success();if !success {diff --git a/tests/git_error_display.rs b/tests/git_error_display.rsindex 933dc0502..9baf48050 100644--- a/tests/git_error_display.rs+++ b/tests/git_error_display.rs@@ -1,6 +1,6 @@use insta::assert_snapshot;use std::path::PathBuf;-use worktrunk::git::GitError;+use worktrunk::git::{GitError, HookType, WorktrunkError};// ============================================================================// Worktree errors@@ -243,6 +243,16 @@ fn display_parse_error() {assert_snapshot!("parse_error", err.to_string());}+#[test]+fn display_remote_only_branch() {+ let err = GitError::RemoteOnlyBranch {+ branch: "feature".into(),+ remote: "origin".into(),+ };++ assert_snapshot!("remote_only_branch", err.to_string());+}+#[test]fn display_other() {let err = GitError::Other {@@ -251,3 +261,61 @@ fn display_other() {assert_snapshot!("other", err.to_string());}++// ============================================================================+// WorktrunkError display tests+// ============================================================================++#[test]+fn display_hook_command_failed_with_name() {+ let err = WorktrunkError::HookCommandFailed {+ hook_type: HookType::PreMerge,+ command_name: Some("test".into()),+ error: "exit code 1".into(),+ exit_code: Some(1),+ };++ assert_snapshot!("hook_command_failed_with_name", err.to_string());+}++#[test]+fn display_hook_command_failed_without_name() {+ let err = WorktrunkError::HookCommandFailed {+ hook_type: HookType::PostCreate,+ command_name: None,+ error: "command not found".into(),+ exit_code: Some(127),+ };++ assert_snapshot!("hook_command_failed_without_name", err.to_string());+}++// ============================================================================+// Integration test: verify error message includes command when git unavailable+// ============================================================================++/// Test that when git execution fails, the error message includes the command.+/// This is an integration test because it requires running the actual binary.+#[test]+#[cfg(unix)]+fn git_unavailable_error_includes_command() {+ use insta_cmd::get_cargo_bin;+ use std::process::Command;++ let mut cmd = Command::new(get_cargo_bin("wt"));+ cmd.arg("list")+ // Set PATH to empty so git isn't found+ .env("PATH", "/nonexistent")+ // Prevent any fallback mechanisms+ .env_remove("GIT_EXEC_PATH");++ let output = cmd.output().expect("Failed to run wt");+ let stderr = String::from_utf8_lossy(&output.stderr);++ // The error should include the git command that failed+ assert!(+ stderr.contains("Failed to execute: git"),+ "Error should include 'Failed to execute: git', got: {}",+ stderr+ );+}diff --git a/tests/snapshots/git_error_display__hook_command_failed_with_name.snap b/tests/snapshots/git_error_display__hook_command_failed_with_name.snapnew file mode 100644index 000000000..3e07ec863--- /dev/null+++ b/tests/snapshots/git_error_display__hook_command_failed_with_name.snap@@ -0,0 +1,7 @@+---+source: tests/git_error_display.rs+expression: err.to_string()+---+β [31mpre-merge command failed: [1mtest[22m: exit code 1[39m++π‘ [2mUse [90m--no-verify[39m to skip pre-merge commands[22mdiff --git a/tests/snapshots/git_error_display__hook_command_failed_without_name.snap b/tests/snapshots/git_error_display__hook_command_failed_without_name.snapnew file mode 100644index 000000000..56d3d7763--- /dev/null+++ b/tests/snapshots/git_error_display__hook_command_failed_without_name.snap@@ -0,0 +1,7 @@+---+source: tests/git_error_display.rs+expression: err.to_string()+---+β [31mpost-create command failed: command not found[39m++π‘ [2mUse [90m--no-verify[39m to skip post-create commands[22mdiff --git a/tests/snapshots/git_error_display__remote_only_branch.snap b/tests/snapshots/git_error_display__remote_only_branch.snapnew file mode 100644index 000000000..19158791d--- /dev/null+++ b/tests/snapshots/git_error_display__remote_only_branch.snap@@ -0,0 +1,7 @@+---+source: tests/git_error_display.rs+expression: err.to_string()+---+β [31mBranch [1mfeature[22m exists only on remote (origin/feature)[39m++π‘ [2mUse [90mwt switch feature[39m to create a local worktree[22m