Skip to content

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

Fix test isolation for wt commands and improve test API (#314)

Maximilian Roosbceedcade708
diff --git a/tests/CLAUDE.md b/tests/CLAUDE.md
index 154cd5bc2..68e88b5d7 100644
--- a/tests/CLAUDE.md
+++ b/tests/CLAUDE.md
@@ -1,5 +1,60 @@
# Testing Guidelines
+## Running `wt` Commands in Tests
+
+**Use the correct helper to ensure test isolation.** Tests that spawn `wt` must
+be isolated from the host environment to prevent:
+
+- **Directive leakage**: Test commands writing to the user's shell directive file
+- **Config pollution**: Tests reading/writing the user's real config
+- **Git interference**: Host GIT_* environment variables affecting test behavior
+
+### With a TestRepo fixture (most tests)
+
+Use `repo.wt_command()` which returns a pre-configured Command:
+
+```rust
+// ✅ GOOD: Simple case
+let output = repo.wt_command()
+ .args(["switch", "--create", "feature"])
+ .output()?;
+
+// ✅ GOOD: With additional configuration (piped stdin, etc.)
+let mut cmd = repo.wt_command();
+cmd.args(["switch", "--create", "feature"])
+ .stdin(Stdio::piped());
+```
+
+```rust
+// ❌ BAD: Missing isolation - inherits host environment
+let output = Command::new(env!("CARGO_BIN_EXE_wt"))
+ .args(["switch", "--create", "feature"])
+ .current_dir(repo.root_path())
+ .output()?;
+```
+
+### Without a TestRepo (e.g., readme_sync tests)
+
+Use the free function `wt_command()`:
+
+```rust
+use crate::common::wt_command;
+
+// ✅ GOOD: Isolated from host environment
+let output = wt_command()
+ .args(["--help"])
+ .current_dir(project_root)
+ .output()?;
+```
+
+### Method reference
+
+| Method | Use when |
+|--------|----------|
+| `repo.wt_command()` | Running wt commands with a TestRepo |
+| `wt_command()` | Running wt without a TestRepo (free function) |
+| `repo.git_command()` | Running git commands |
+
## Timing Tests: Long Timeouts with Fast Polling
**Core principle:** Use long timeouts (5+ seconds) for reliability on slow CI, but poll frequently (10-50ms) so tests complete quickly when things work.
diff --git a/tests/common/list_snapshots.rs b/tests/common/list_snapshots.rs
index 26845ced4..d182b3d13 100644
--- a/tests/common/list_snapshots.rs
+++ b/tests/common/list_snapshots.rs
@@ -21,7 +21,7 @@ pub fn json_settings(repo: &TestRepo) -> Settings {
pub fn command(repo: &TestRepo, cwd: &Path) -> Command {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(cwd);
cmd
}
@@ -100,7 +100,7 @@ pub fn command_progressive_full(repo: &TestRepo) -> Command {
pub fn command_progressive_from_dir(repo: &TestRepo, cwd: &Path) -> Command {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.args(["list", "--progressive"]).current_dir(cwd);
cmd
}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 7402afcc5..55690c991 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -526,6 +526,7 @@ const NULL_DEVICE: &str = "/dev/null";
/// - All host `GIT_*` and `WORKTRUNK_*` variables are cleared
/// - Color output is forced (`CLICOLOR_FORCE=1`) so ANSI styling appears in snapshots
/// - Terminal width set to 150 columns (`COLUMNS=150`)
+#[must_use]
pub fn wt_command() -> Command {
let mut cmd = Command::new(get_cargo_bin("wt"));
configure_cli_command(&mut cmd);
@@ -593,7 +594,7 @@ pub fn configure_cli_command(cmd: &mut Command) {
}
}
// Set to non-existent path to prevent loading user's real config.
- // Tests that need config should use TestRepo::clean_cli_env() which overrides this.
+ // Tests that need config should use TestRepo::configure_wt_cmd() which overrides this.
// Note: env_remove above may cause insta-cmd to capture empty values in snapshots,
// but correctness (isolating from host WORKTRUNK_* vars) trumps snapshot aesthetics.
cmd.env("WORKTRUNK_CONFIG_PATH", "/nonexistent/test/config.toml");
@@ -908,25 +909,21 @@ impl TestRepo {
]
}
- /// Create a configured git command with args and current_dir set
+ /// Create a `git` command pre-configured for this test repo.
///
- /// This is a convenience wrapper around configure_git_cmd that reduces boilerplate.
- /// Returns a Command ready to execute with .output(), .status(), etc.
+ /// Returns an isolated Command with test-specific git config.
+ /// Chain `.args()` to add arguments.
///
/// # 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()?;
+ /// repo.git_command()
+ /// .args(["status", "--porcelain"])
+ /// .output()?;
/// ```
- pub fn git_command(&self, args: &[&str]) -> Command {
+ #[must_use]
+ pub fn git_command(&self) -> Command {
let mut cmd = Command::new("git");
self.configure_git_cmd(&mut cmd);
- cmd.args(args);
cmd.current_dir(&self.root);
cmd
}
@@ -934,7 +931,10 @@ impl TestRepo {
/// Configure command for CLI tests with isolated environment.
///
/// Sets `WORKTRUNK_CONFIG_PATH`, `HOME`, and mock gh/glab commands.
- pub fn clean_cli_env(&self, cmd: &mut Command) {
+ ///
+ /// **Internal helper** - used by `wt_command()` and `make_snapshot_cmd()`.
+ /// Tests should use `repo.wt_command()` instead of calling this directly.
+ pub fn configure_wt_cmd(&self, cmd: &mut Command) {
configure_cli_command(cmd);
self.configure_git_cmd(cmd);
cmd.env("WORKTRUNK_CONFIG_PATH", &self.test_config_path);
@@ -942,6 +942,26 @@ impl TestRepo {
self.configure_mock_commands(cmd);
}
+ /// Create a `wt` command pre-configured for this test repo.
+ ///
+ /// This is the preferred way to run wt commands in tests. The returned
+ /// Command is isolated from the host environment (no WORKTRUNK_* leakage,
+ /// no GIT_* interference) and configured with the test repo's config.
+ ///
+ /// # Example
+ /// ```ignore
+ /// let output = repo.wt_command()
+ /// .args(["switch", "--create", "feature"])
+ /// .output()?;
+ /// ```
+ #[must_use]
+ pub fn wt_command(&self) -> Command {
+ let mut cmd = Command::new(get_cargo_bin("wt"));
+ self.configure_wt_cmd(&mut cmd);
+ cmd.current_dir(self.root_path());
+ cmd
+ }
+
/// Get the isolated HOME directory for this test.
///
/// This is the temp directory containing the repo and can be used to set up
@@ -969,7 +989,7 @@ impl TestRepo {
pub fn completion_cmd_for_shell(&self, words: &[&str], shell: &str) -> Command {
let mut cmd = wt_command();
configure_completion_invocation_for_shell(&mut cmd, words, shell);
- self.clean_cli_env(&mut cmd);
+ self.configure_wt_cmd(&mut cmd);
cmd.current_dir(self.root_path());
cmd
}
@@ -982,7 +1002,7 @@ impl TestRepo {
/// Get the path to the isolated test config file
///
/// This config path is automatically set via WORKTRUNK_CONFIG_PATH when using
- /// `clean_cli_env()`, ensuring tests don't pollute the user's real config.
+ /// `configure_wt_cmd()`, ensuring tests don't pollute the user's real config.
pub fn test_config_path(&self) -> &Path {
&self.test_config_path
}
@@ -1012,9 +1032,10 @@ impl TestRepo {
let file_path = self.root.join("file.txt");
std::fs::write(&file_path, message).unwrap();
- self.git_command(&["add", "."]).output().unwrap();
+ self.git_command().args(["add", "."]).output().unwrap();
- self.git_command(&["commit", "-m", message])
+ self.git_command()
+ .args(["commit", "-m", message])
.output()
.unwrap();
}
@@ -1031,9 +1052,10 @@ impl TestRepo {
let file_path = self.root.join(format!("file-{}.txt", sanitized));
std::fs::write(&file_path, message).unwrap();
- self.git_command(&["add", "."]).output().unwrap();
+ self.git_command().args(["add", "."]).output().unwrap();
- self.git_command(&["commit", "-m", message])
+ self.git_command()
+ .args(["commit", "-m", message])
.output()
.unwrap();
}
@@ -1062,7 +1084,7 @@ impl TestRepo {
let file_path = self.root.join("file.txt");
std::fs::write(&file_path, message).unwrap();
- self.git_command(&["add", "."]).output().unwrap();
+ self.git_command().args(["add", "."]).output().unwrap();
// Create commit with custom timestamp
let mut cmd = Command::new("git");
@@ -1759,7 +1781,8 @@ exit 1
pub fn set_marker(&self, branch: &str, marker: &str) {
let config_key = format!("worktrunk.state.{branch}.marker");
let json_value = format!(r#"{{"marker":"{}","set_at":{}}}"#, marker, TEST_EPOCH);
- self.git_command(&["config", &config_key, &json_value])
+ self.git_command()
+ .args(["config", &config_key, &json_value])
.output()
.unwrap();
}
@@ -2061,7 +2084,7 @@ pub fn make_snapshot_cmd_with_global_flags(
global_flags: &[&str],
) -> Command {
let mut cmd = Command::new(insta_cmd::get_cargo_bin("wt"));
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.args(global_flags)
.arg(subcommand)
.args(args)
@@ -2393,7 +2416,11 @@ mod tests {
repo.commit_with_age("Ten minutes ago", 10 * MINUTE);
// Verify commits were created (1 from fixture + 4 = 5 commits)
- let output = repo.git_command(&["log", "--oneline"]).output().unwrap();
+ let output = repo
+ .git_command()
+ .args(["log", "--oneline"])
+ .output()
+ .unwrap();
let log = String::from_utf8_lossy(&output.stdout);
assert_eq!(log.lines().count(), 5);
}
diff --git a/tests/common/shell.rs b/tests/common/shell.rs
index cf8a502c5..a8293374b 100644
--- a/tests/common/shell.rs
+++ b/tests/common/shell.rs
@@ -158,7 +158,7 @@ pub fn execute_shell_script(repo: &TestRepo, shell: &str, script: &str) -> Strin
/// Generate `wt config shell init <shell>` output for the repo.
pub fn generate_init_code(repo: &TestRepo, shell: &str) -> String {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
let output = cmd
.args(["config", "shell", "init", shell])
diff --git a/tests/integration_tests/approval_ui.rs b/tests/integration_tests/approval_ui.rs
index 2c64363b0..7420b9fcd 100644
--- a/tests/integration_tests/approval_ui.rs
+++ b/tests/integration_tests/approval_ui.rs
@@ -5,7 +5,7 @@ use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
use std::fs;
use std::io::Write;
-use std::process::{Command, Stdio};
+use std::process::Stdio;
/// Helper to create snapshot with test environment
fn snapshot_approval(test_name: &str, repo: &TestRepo, args: &[&str], approve: bool) {
@@ -119,13 +119,10 @@ fn test_yes_flag_does_not_save_approvals(repo: TestRepo) {
});
// Clean up the worktree
- let mut cmd = Command::new(insta_cmd::get_cargo_bin("wt"));
- repo.clean_cli_env(&mut cmd);
- cmd.arg("remove")
- .arg("test-yes")
- .arg("--yes")
- .current_dir(repo.root_path());
- cmd.output().unwrap();
+ repo.wt_command()
+ .args(["remove", "test-yes", "--yes"])
+ .output()
+ .unwrap();
// Run again WITHOUT --yes - should prompt
snapshot_approval(
@@ -335,14 +332,15 @@ fn test_hook_post_merge_target_is_current_branch(repo: TestRepo) {
repo.commit("Add post-merge hook");
// Create and switch to a feature branch
- repo.git_command(&["checkout", "-b", "my-feature-branch"])
+ repo.git_command()
+ .args(["checkout", "-b", "my-feature-branch"])
.output()
.unwrap();
// Run the hook with --yes to skip approval
- let output = Command::new(env!("CARGO_BIN_EXE_wt"))
+ let output = repo
+ .wt_command()
.args(["hook", "post-merge", "--yes"])
- .current_dir(repo.root_path())
.env("NO_COLOR", "1")
.output()
.expect("Failed to run wt hook post-merge");
@@ -372,14 +370,15 @@ fn test_hook_pre_merge_target_is_current_branch(repo: TestRepo) {
repo.commit("Add pre-merge hook");
// Create and switch to a feature branch
- repo.git_command(&["checkout", "-b", "my-feature-branch"])
+ repo.git_command()
+ .args(["checkout", "-b", "my-feature-branch"])
.output()
.unwrap();
// Run the hook with --yes to skip approval
- let output = Command::new(env!("CARGO_BIN_EXE_wt"))
+ let output = repo
+ .wt_command()
.args(["hook", "pre-merge", "--yes"])
- .current_dir(repo.root_path())
.env("NO_COLOR", "1")
.output()
.expect("Failed to run wt hook pre-merge");
@@ -415,9 +414,9 @@ build = "echo 'running build' > build.txt"
repo.commit("Add pre-merge hooks");
// Run only the "lint" command with --yes to skip approval
- let output = Command::new(env!("CARGO_BIN_EXE_wt"))
+ let output = repo
+ .wt_command()
.args(["hook", "pre-merge", "lint", "--yes"])
- .current_dir(repo.root_path())
.env("NO_COLOR", "1")
.output()
.expect("Failed to run wt hook pre-merge lint");
@@ -493,9 +492,9 @@ third = "echo 'third' >> output.txt"
repo.commit("Add pre-merge hooks");
// Run without name filter (all commands should run)
- let output = Command::new(env!("CARGO_BIN_EXE_wt"))
+ let output = repo
+ .wt_command()
.args(["hook", "pre-merge", "--yes"])
- .current_dir(repo.root_path())
.env("NO_COLOR", "1")
.output()
.expect("Failed to run wt hook pre-merge");
diff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rs
index ff9761bde..c8f014a51 100644
--- a/tests/integration_tests/bare_repository.rs
+++ b/tests/integration_tests/bare_repository.rs
@@ -424,7 +424,7 @@ worktree-path = "{{ branch }}"
bare_list.arg("list").current_dir(&bare_main);
let mut normal_list = wt_command();
- repo.clean_cli_env(&mut normal_list);
+ repo.configure_wt_cmd(&mut normal_list);
normal_list.arg("list").current_dir(repo.root_path());
let bare_output = bare_list.output().unwrap();
diff --git a/tests/integration_tests/ci_status.rs b/tests/integration_tests/ci_status.rs
index aa65a76ef..2c091640f 100644
--- a/tests/integration_tests/ci_status.rs
+++ b/tests/integration_tests/ci_status.rs
@@ -19,7 +19,8 @@ use std::process::Command;
/// Get the HEAD commit SHA for a branch
fn get_branch_sha(repo: &TestRepo, branch: &str) -> String {
let output = repo
- .git_command(&["rev-parse", branch])
+ .git_command()
+ .args(["rev-parse", branch])
.output()
.expect("Failed to get commit SHA");
String::from_utf8_lossy(&output.stdout).trim().to_string()
@@ -29,14 +30,15 @@ fn get_branch_sha(repo: &TestRepo, branch: &str) -> String {
#[rstest]
fn test_list_full_with_github_pr_passed(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -73,14 +75,15 @@ fn test_list_full_with_github_pr_passed(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_github_pr_failed(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -117,14 +120,15 @@ fn test_list_full_with_github_pr_failed(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_github_pr_running(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -161,14 +165,15 @@ fn test_list_full_with_github_pr_running(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_github_pr_conflicts(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -205,14 +210,15 @@ fn test_list_full_with_github_pr_conflicts(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_status_context_pending(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -249,14 +255,15 @@ fn test_list_full_with_status_context_pending(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_status_context_failure(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -293,14 +300,15 @@ fn test_list_full_with_status_context_failure(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_github_workflow_run(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it (so has_upstream is true)
repo.add_worktree("feature");
@@ -333,14 +341,15 @@ fn test_list_full_with_github_workflow_run(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_github_workflow_running(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -373,14 +382,15 @@ fn test_list_full_with_github_workflow_running(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_stale_pr(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -428,14 +438,15 @@ fn test_list_full_with_stale_pr(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_mixed_check_types(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -474,14 +485,15 @@ fn test_list_full_with_mixed_check_types(mut repo: TestRepo) {
#[rstest]
fn test_list_full_with_no_ci_checks(mut repo: TestRepo) {
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/test-owner/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/test-owner/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
@@ -516,14 +528,15 @@ fn test_list_full_with_no_ci_checks(mut repo: TestRepo) {
#[rstest]
fn test_list_full_filters_by_repo_owner(mut repo: TestRepo) {
// Add GitHub remote with specific owner
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/my-org/test-repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/my-org/test-repo.git",
+ ])
+ .output()
+ .unwrap();
// Create a feature branch and push it
repo.add_worktree("feature");
diff --git a/tests/integration_tests/column_alignment_verification.rs b/tests/integration_tests/column_alignment_verification.rs
index 762ce89a7..548352a6f 100644
--- a/tests/integration_tests/column_alignment_verification.rs
+++ b/tests/integration_tests/column_alignment_verification.rs
@@ -327,7 +327,7 @@ fn test_alignment_verification_with_varying_content(mut repo: TestRepo) {
// Run wt list and capture output
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().unwrap();
@@ -355,7 +355,7 @@ fn test_alignment_with_unicode_content(mut repo: TestRepo) {
// Run wt list
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().unwrap();
@@ -391,7 +391,7 @@ fn test_alignment_with_sparse_columns(mut repo: TestRepo) {
// Run wt list
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().unwrap();
@@ -439,7 +439,7 @@ fn test_alignment_real_world_scenario(mut repo: TestRepo) {
// Run wt list at a width where Dirty column is visible
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().unwrap();
@@ -469,7 +469,7 @@ fn test_alignment_at_different_terminal_widths(mut repo: TestRepo) {
println!("\n### Testing at width {} ###", width);
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("list")
.current_dir(repo.root_path())
.env("COLUMNS", width.to_string());
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index dabd45cfa..bed1361bc 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -41,7 +41,7 @@ server = "npm run dev"
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -69,7 +69,7 @@ fn test_config_show_no_project_config(mut repo: TestRepo, temp_home: TempDir) {
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -130,7 +130,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
// Force compinit warning for deterministic tests across environments
cmd.env("WORKTRUNK_TEST_COMPINIT_MISSING", "1");
@@ -173,7 +173,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -209,7 +209,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -249,7 +249,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
// Keep PATH minimal so the probe zsh doesn't find a globally-installed `wt`.
cmd.env("PATH", "/usr/bin:/bin");
cmd.env("ZDOTDIR", temp_home.path());
@@ -296,7 +296,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
// Keep PATH minimal so the probe zsh doesn't find a globally-installed `wt`.
cmd.env("PATH", "/usr/bin:/bin");
cmd.env("ZDOTDIR", temp_home.path());
@@ -340,7 +340,7 @@ fn test_config_show_warns_unknown_project_keys(mut repo: TestRepo, temp_home: Te
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -367,7 +367,7 @@ fn test_config_show_warns_unknown_user_keys(mut repo: TestRepo, temp_home: TempD
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -395,7 +395,7 @@ fn test_config_show_full_not_configured(mut repo: TestRepo, temp_home: TempDir)
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
// Override WORKTRUNK_CONFIG_PATH to point to our test config
cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
@@ -433,7 +433,7 @@ args = ["-m", "test-model"]
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
// Override WORKTRUNK_CONFIG_PATH to point to our test config
cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
@@ -454,14 +454,15 @@ fn test_config_show_github_remote(mut repo: TestRepo, temp_home: TempDir) {
repo.setup_mock_ci_tools_unauthenticated();
// Add GitHub remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://github.com/example/repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://github.com/example/repo.git",
+ ])
+ .output()
+ .unwrap();
// Create fake global config
let global_config_dir = temp_home.path().join(".config").join("worktrunk");
@@ -476,7 +477,7 @@ fn test_config_show_github_remote(mut repo: TestRepo, temp_home: TempDir) {
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -492,14 +493,15 @@ fn test_config_show_gitlab_remote(mut repo: TestRepo, temp_home: TempDir) {
repo.setup_mock_ci_tools_unauthenticated();
// Add GitLab remote
- repo.git_command(&[
- "remote",
- "add",
- "origin",
- "https://gitlab.com/example/repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "add",
+ "origin",
+ "https://gitlab.com/example/repo.git",
+ ])
+ .output()
+ .unwrap();
// Create fake global config
let global_config_dir = temp_home.path().join(".config").join("worktrunk");
@@ -514,7 +516,7 @@ fn test_config_show_gitlab_remote(mut repo: TestRepo, temp_home: TempDir) {
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -547,7 +549,7 @@ fn test_config_show_empty_project_config(mut repo: TestRepo, temp_home: TempDir)
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -580,7 +582,7 @@ fn test_config_show_whitespace_only_project_config(mut repo: TestRepo, temp_home
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
diff --git a/tests/integration_tests/config_state.rs b/tests/integration_tests/config_state.rs
index d12515e7a..c7d2af692 100644
--- a/tests/integration_tests/config_state.rs
+++ b/tests/integration_tests/config_state.rs
@@ -30,7 +30,7 @@ fn write_ci_cache(repo: &TestRepo, branch: &str, json: &str) {
/// Create a command for `wt config state <key> <action> [args...]`
fn wt_state_cmd(repo: &TestRepo, key: &str, action: &str, args: &[&str]) -> Command {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.args(["config", "state", key, action]);
cmd.args(args);
cmd.current_dir(repo.root_path());
@@ -39,7 +39,7 @@ fn wt_state_cmd(repo: &TestRepo, key: &str, action: &str, args: &[&str]) -> Comm
fn wt_state_get_cmd(repo: &TestRepo) -> Command {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.args(["config", "state", "get"]);
cmd.current_dir(repo.root_path());
cmd
@@ -47,7 +47,7 @@ fn wt_state_get_cmd(repo: &TestRepo) -> Command {
fn wt_state_get_json_cmd(repo: &TestRepo) -> Command {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.args(["config", "state", "get", "--format=json"]);
cmd.current_dir(repo.root_path());
cmd
@@ -88,7 +88,8 @@ fn test_state_set_default_branch(repo: TestRepo) {
// Verify it was set in worktrunk's cache
let output = repo
- .git_command(&["config", "--get", "worktrunk.default-branch"])
+ .git_command()
+ .args(["config", "--get", "worktrunk.default-branch"])
.output()
.unwrap();
assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "develop");
@@ -112,7 +113,8 @@ fn test_state_clear_default_branch(mut repo: TestRepo) {
// Verify worktrunk's cache was cleared
let output = repo
- .git_command(&["config", "--get", "worktrunk.default-branch"])
+ .git_command()
+ .args(["config", "--get", "worktrunk.default-branch"])
.output()
.unwrap();
assert!(!output.status.success());
@@ -121,7 +123,8 @@ fn test_state_clear_default_branch(mut repo: TestRepo) {
#[rstest]
fn test_state_clear_default_branch_empty(repo: TestRepo) {
// Set up remote but don't set default branch cache
- repo.git_command(&["remote", "add", "origin", "https://example.com/repo.git"])
+ repo.git_command()
+ .args(["remote", "add", "origin", "https://example.com/repo.git"])
.output()
.unwrap();
@@ -209,7 +212,10 @@ fn test_state_get_ci_status(repo: TestRepo) {
#[rstest]
fn test_state_get_ci_status_specific_branch(repo: TestRepo) {
- repo.git_command(&["branch", "feature"]).status().unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
+ .status()
+ .unwrap();
// Without any CI configured, should return "no-ci"
let output = wt_state_cmd(&repo, "ci-status", "get", &["--branch", "feature"])
@@ -242,7 +248,7 @@ fn test_state_clear_ci_status_all_empty(repo: TestRepo) {
#[rstest]
fn test_state_clear_ci_status_branch(repo: TestRepo) {
// Add CI cache entry
- repo.git_command(&[
+ repo.git_command().args([
"config",
"worktrunk.state.main.ci-status",
&format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345"}}"#),
@@ -291,7 +297,10 @@ fn test_state_get_marker_empty(repo: TestRepo) {
#[rstest]
fn test_state_get_marker_specific_branch(repo: TestRepo) {
- repo.git_command(&["branch", "feature"]).status().unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
+ .status()
+ .unwrap();
// Set a marker for feature branch (using JSON format)
repo.set_marker("feature", "🔧");
@@ -319,7 +328,10 @@ fn test_state_set_marker_branch_default(repo: TestRepo) {
#[rstest]
fn test_state_set_marker_branch_specific(repo: TestRepo) {
- repo.git_command(&["branch", "feature"]).status().unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
+ .status()
+ .unwrap();
let output = wt_state_cmd(&repo, "marker", "set", &["🔧", "--branch", "feature"])
.output()
@@ -347,7 +359,8 @@ fn test_state_clear_marker_branch_default(repo: TestRepo) {
// Verify it was unset
let output = repo
- .git_command(&["config", "--get", "worktrunk.state.main.marker"])
+ .git_command()
+ .args(["config", "--get", "worktrunk.state.main.marker"])
.output()
.unwrap();
assert!(!output.status.success());
@@ -366,7 +379,8 @@ fn test_state_clear_marker_branch_specific(repo: TestRepo) {
// Verify it was unset
let output = repo
- .git_command(&["config", "--get", "worktrunk.state.feature.marker"])
+ .git_command()
+ .args(["config", "--get", "worktrunk.state.feature.marker"])
.output()
.unwrap();
assert!(!output.status.success());
@@ -387,7 +401,8 @@ fn test_state_clear_marker_all(repo: TestRepo) {
// Verify all were unset
let output = repo
- .git_command(&["config", "--get-regexp", r"^worktrunk\.state\..+\.marker$"])
+ .git_command()
+ .args(["config", "--get-regexp", r"^worktrunk\.state\..+\.marker$"])
.output()
.unwrap();
assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "");
@@ -540,7 +555,8 @@ fn test_state_clear_all_empty(repo: TestRepo) {
fn test_state_clear_all_comprehensive(repo: TestRepo) {
// Set up various state
// Previous branch
- repo.git_command(&["config", "worktrunk.history", "feature"])
+ repo.git_command()
+ .args(["config", "worktrunk.history", "feature"])
.status()
.unwrap();
@@ -566,7 +582,8 @@ fn test_state_clear_all_comprehensive(repo: TestRepo) {
// Verify everything was cleared
assert!(
- repo.git_command(&["config", "--get", "worktrunk.history"])
+ repo.git_command()
+ .args(["config", "--get", "worktrunk.history"])
.output()
.unwrap()
.status
@@ -574,7 +591,8 @@ fn test_state_clear_all_comprehensive(repo: TestRepo) {
== Some(1)
); // Not found
assert!(
- repo.git_command(&["config", "--get", "worktrunk.state.main.marker"])
+ repo.git_command()
+ .args(["config", "--get", "worktrunk.state.main.marker"])
.output()
.unwrap()
.status
@@ -660,25 +678,28 @@ fn test_state_get_with_ci_entries(repo: TestRepo) {
#[rstest]
fn test_state_get_comprehensive(repo: TestRepo) {
// Set up previous branch
- repo.git_command(&["config", "worktrunk.history", "feature"])
+ repo.git_command()
+ .args(["config", "worktrunk.history", "feature"])
.status()
.unwrap();
// Set up branch markers (JSON format with timestamps for deterministic age)
- repo.git_command(&[
- "config",
- "worktrunk.state.feature.marker",
- &format!(r#"{{"marker":"🚧 WIP","set_at":{TEST_EPOCH}}}"#),
- ])
- .status()
- .unwrap();
- repo.git_command(&[
- "config",
- "worktrunk.state.bugfix.marker",
- &format!(r#"{{"marker":"🐛 debugging","set_at":{TEST_EPOCH}}}"#),
- ])
- .status()
- .unwrap();
+ repo.git_command()
+ .args([
+ "config",
+ "worktrunk.state.feature.marker",
+ &format!(r#"{{"marker":"🚧 WIP","set_at":{TEST_EPOCH}}}"#),
+ ])
+ .status()
+ .unwrap();
+ repo.git_command()
+ .args([
+ "config",
+ "worktrunk.state.bugfix.marker",
+ &format!(r#"{{"marker":"🐛 debugging","set_at":{TEST_EPOCH}}}"#),
+ ])
+ .status()
+ .unwrap();
// Set up CI cache (file-based)
write_ci_cache(
@@ -719,18 +740,20 @@ fn test_state_get_json_empty(repo: TestRepo) {
#[rstest]
fn test_state_get_json_comprehensive(repo: TestRepo) {
// Set up previous branch
- repo.git_command(&["config", "worktrunk.history", "feature"])
+ repo.git_command()
+ .args(["config", "worktrunk.history", "feature"])
.status()
.unwrap();
// Set up branch markers (JSON format with timestamps)
- repo.git_command(&[
- "config",
- "worktrunk.state.feature.marker",
- &format!(r#"{{"marker":"🚧 WIP","set_at":{TEST_EPOCH}}}"#),
- ])
- .status()
- .unwrap();
+ repo.git_command()
+ .args([
+ "config",
+ "worktrunk.state.feature.marker",
+ &format!(r#"{{"marker":"🚧 WIP","set_at":{TEST_EPOCH}}}"#),
+ ])
+ .status()
+ .unwrap();
// Set up CI cache (file-based)
write_ci_cache(
@@ -849,10 +872,13 @@ fn test_state_clear_ci_status_all_single_entry(repo: TestRepo) {
#[rstest]
fn test_state_clear_ci_status_specific_branch(repo: TestRepo) {
// Create a feature branch
- repo.git_command(&["branch", "feature"]).status().unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
+ .status()
+ .unwrap();
// Add CI cache via git config for the specific branch
- repo.git_command(&[
+ repo.git_command().args([
"config",
"worktrunk.state.feature.ci-status",
&format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345"}}"#),
@@ -870,7 +896,10 @@ fn test_state_clear_ci_status_specific_branch(repo: TestRepo) {
#[rstest]
fn test_state_clear_ci_status_specific_branch_not_cached(repo: TestRepo) {
// Create a feature branch without any CI cache
- repo.git_command(&["branch", "feature"]).status().unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
+ .status()
+ .unwrap();
let output = wt_state_cmd(&repo, "ci-status", "clear", &["--branch", "feature"])
.output()
@@ -882,7 +911,10 @@ fn test_state_clear_ci_status_specific_branch_not_cached(repo: TestRepo) {
#[rstest]
fn test_state_clear_marker_specific_branch(repo: TestRepo) {
// Create a feature branch and set marker
- repo.git_command(&["branch", "feature"]).status().unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
+ .status()
+ .unwrap();
repo.set_marker("feature", "🔧");
let output = wt_state_cmd(&repo, "marker", "clear", &["--branch", "feature"])
@@ -895,7 +927,10 @@ fn test_state_clear_marker_specific_branch(repo: TestRepo) {
#[rstest]
fn test_state_clear_marker_specific_branch_not_set(repo: TestRepo) {
// Create a feature branch without any marker
- repo.git_command(&["branch", "feature"]).status().unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
+ .status()
+ .unwrap();
let output = wt_state_cmd(&repo, "marker", "clear", &["--branch", "feature"])
.output()
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index 04536ff1a..0f193bb94 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -16,7 +16,7 @@ fn test_configure_shell_with_yes(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
// Force compinit warning for deterministic tests across environments
@@ -59,7 +59,7 @@ fn test_configure_shell_specific_shell(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
// Force compinit warning for deterministic tests across environments
@@ -105,7 +105,7 @@ fn test_configure_shell_already_exists(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
@@ -138,7 +138,7 @@ fn test_configure_shell_fish(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/fish");
cmd.arg("config")
@@ -191,7 +191,7 @@ fn test_configure_shell_fish_extension_exists(repo: TestRepo, temp_home: TempDir
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/fish");
cmd.arg("config")
@@ -251,7 +251,7 @@ fn test_configure_shell_fish_all_already_configured(repo: TestRepo, temp_home: T
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/fish");
cmd.arg("config")
@@ -272,7 +272,7 @@ fn test_configure_shell_no_files(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
@@ -307,7 +307,7 @@ fn test_configure_shell_multiple_configs(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
// Force compinit warning for deterministic tests across environments
@@ -367,7 +367,7 @@ fn test_configure_shell_mixed_states(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
// Force compinit warning for deterministic tests across environments
@@ -425,7 +425,7 @@ fn test_uninstall_shell(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
@@ -482,7 +482,7 @@ fn test_uninstall_shell_multiple(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
@@ -531,7 +531,7 @@ fn test_uninstall_shell_not_found(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
@@ -568,7 +568,7 @@ fn test_uninstall_shell_fish(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/fish");
cmd.arg("config")
@@ -609,7 +609,7 @@ fn test_install_uninstall_roundtrip(repo: TestRepo, temp_home: TempDir) {
// First install
{
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
@@ -630,7 +630,7 @@ fn test_install_uninstall_roundtrip(repo: TestRepo, temp_home: TempDir) {
// Then uninstall
{
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
@@ -672,7 +672,7 @@ fn test_install_uninstall_no_blank_line_accumulation(repo: TestRepo, temp_home:
// Install
{
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.args(["config", "shell", "install", "zsh", "--yes"]);
@@ -690,7 +690,7 @@ fn test_install_uninstall_no_blank_line_accumulation(repo: TestRepo, temp_home:
// Uninstall
{
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.args(["config", "shell", "uninstall", "zsh", "--yes"]);
@@ -708,7 +708,7 @@ fn test_install_uninstall_no_blank_line_accumulation(repo: TestRepo, temp_home:
// Re-install
{
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.args(["config", "shell", "install", "zsh", "--yes"]);
@@ -744,7 +744,7 @@ fn test_configure_shell_no_warning_when_compinit_enabled(repo: TestRepo, temp_ho
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.env("ZDOTDIR", temp_home.path()); // Point zsh to our test home for config
@@ -783,7 +783,7 @@ fn test_configure_shell_no_warning_for_bash_user(repo: TestRepo, temp_home: Temp
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/bash"); // User's primary shell is bash
cmd.arg("config")
@@ -820,7 +820,7 @@ fn test_configure_shell_no_warning_for_fish_install(repo: TestRepo, temp_home: T
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh"); // User is zsh user, but installing fish
cmd.arg("config")
@@ -859,7 +859,7 @@ fn test_configure_shell_no_warning_when_already_configured(repo: TestRepo, temp_
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
@@ -894,7 +894,7 @@ fn test_configure_shell_no_warning_when_shell_unset(repo: TestRepo, temp_home: T
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env_remove("SHELL"); // Explicitly unset SHELL
cmd.arg("config")
diff --git a/tests/integration_tests/default_branch.rs b/tests/integration_tests/default_branch.rs
index 9d043855b..582dc9e0f 100644
--- a/tests/integration_tests/default_branch.rs
+++ b/tests/integration_tests/default_branch.rs
@@ -24,7 +24,8 @@ fn test_get_default_branch_without_origin_head(#[from(repo_with_remote)] repo: T
// Verify that worktrunk's cache is now set
let cached = repo
- .git_command(&["config", "--get", "worktrunk.default-branch"])
+ .git_command()
+ .args(["config", "--get", "worktrunk.default-branch"])
.output()
.unwrap();
assert_eq!(String::from_utf8_lossy(&cached.stdout).trim(), "main");
@@ -35,13 +36,15 @@ fn test_get_default_branch_caches_result(#[from(repo_with_remote)] repo: TestRep
// Clear both caches to force remote query
repo.clear_origin_head();
let _ = repo
- .git_command(&["config", "--unset", "worktrunk.default-branch"])
+ .git_command()
+ .args(["config", "--unset", "worktrunk.default-branch"])
.output();
// First call queries remote and caches to worktrunk config
Repository::at(repo.root_path()).default_branch().unwrap();
let cached = repo
- .git_command(&["config", "--get", "worktrunk.default-branch"])
+ .git_command()
+ .args(["config", "--get", "worktrunk.default-branch"])
.output()
.unwrap();
assert!(cached.status.success());
@@ -100,8 +103,14 @@ fn test_branch_exists_with_custom_remote(mut repo: TestRepo) {
#[rstest]
fn test_get_default_branch_no_remote_common_names_fallback(repo: TestRepo) {
// Create additional branches (no remote configured)
- repo.git_command(&["branch", "feature"]).status().unwrap();
- repo.git_command(&["branch", "bugfix"]).status().unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
+ .status()
+ .unwrap();
+ repo.git_command()
+ .args(["branch", "bugfix"])
+ .status()
+ .unwrap();
// Now we have multiple branches: main, feature, bugfix
// Should detect "main" from the common names list
@@ -112,11 +121,18 @@ fn test_get_default_branch_no_remote_common_names_fallback(repo: TestRepo) {
#[rstest]
fn test_get_default_branch_no_remote_master_fallback(repo: TestRepo) {
// Rename main to master, then create other branches
- repo.git_command(&["branch", "-m", "main", "master"])
+ repo.git_command()
+ .args(["branch", "-m", "main", "master"])
+ .status()
+ .unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
+ .status()
+ .unwrap();
+ repo.git_command()
+ .args(["branch", "bugfix"])
.status()
.unwrap();
- repo.git_command(&["branch", "feature"]).status().unwrap();
- repo.git_command(&["branch", "bugfix"]).status().unwrap();
// Now we have: master, feature, bugfix (no "main")
// Should detect "master" from the common names list
@@ -127,13 +143,18 @@ fn test_get_default_branch_no_remote_master_fallback(repo: TestRepo) {
#[rstest]
fn test_get_default_branch_no_remote_init_default_branch_config(repo: TestRepo) {
// Rename main to something non-standard, create the configured default
- repo.git_command(&["branch", "-m", "main", "primary"])
+ repo.git_command()
+ .args(["branch", "-m", "main", "primary"])
+ .status()
+ .unwrap();
+ repo.git_command()
+ .args(["branch", "feature"])
.status()
.unwrap();
- repo.git_command(&["branch", "feature"]).status().unwrap();
// Set init.defaultBranch - this should be checked before common names
- repo.git_command(&["config", "init.defaultBranch", "primary"])
+ repo.git_command()
+ .args(["config", "init.defaultBranch", "primary"])
.status()
.unwrap();
@@ -146,11 +167,12 @@ fn test_get_default_branch_no_remote_init_default_branch_config(repo: TestRepo)
#[rstest]
fn test_get_default_branch_no_remote_fails_when_no_match(repo: TestRepo) {
// Rename main to something non-standard
- repo.git_command(&["branch", "-m", "main", "xyz"])
+ repo.git_command()
+ .args(["branch", "-m", "main", "xyz"])
.status()
.unwrap();
- repo.git_command(&["branch", "abc"]).status().unwrap();
- repo.git_command(&["branch", "def"]).status().unwrap();
+ repo.git_command().args(["branch", "abc"]).status().unwrap();
+ repo.git_command().args(["branch", "def"]).status().unwrap();
// Now we have: xyz, abc, def - no common names, no init.defaultBranch
// Should fail with an error
diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rs
index 46d828107..eec293bcf 100644
--- a/tests/integration_tests/directives.rs
+++ b/tests/integration_tests/directives.rs
@@ -23,7 +23,7 @@ fn test_switch_directive_file(#[from(repo_with_remote)] mut repo: TestRepo) {
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("switch")
.arg("feature")
@@ -53,7 +53,7 @@ fn test_merge_directive_file(mut repo_with_remote_and_feature: TestRepo) {
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("merge").arg("main").current_dir(feature_wt);
@@ -80,7 +80,7 @@ fn test_remove_directive_file(#[from(repo_with_remote)] mut repo: TestRepo) {
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("remove").current_dir(&feature_wt);
@@ -107,7 +107,7 @@ fn test_switch_without_directive_file(repo: TestRepo) {
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("switch")
.arg("my-feature")
.current_dir(repo.root_path());
@@ -123,7 +123,7 @@ fn test_remove_without_directive_file(repo: TestRepo) {
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("remove").current_dir(repo.root_path());
assert_cmd_snapshot!(cmd);
@@ -141,7 +141,7 @@ fn test_merge_directive_no_remove(mut repo_with_feature_worktree: TestRepo) {
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("merge")
.arg("main")
@@ -164,7 +164,7 @@ fn test_merge_directive_remove(mut repo_with_feature_worktree: TestRepo) {
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("merge").arg("main").current_dir(feature_wt);
diff --git a/tests/integration_tests/hook_show.rs b/tests/integration_tests/hook_show.rs
index 999f52eef..e06daeaeb 100644
--- a/tests/integration_tests/hook_show.rs
+++ b/tests/integration_tests/hook_show.rs
@@ -40,7 +40,7 @@ test = "cargo test"
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("hook").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -64,7 +64,7 @@ fn test_hook_show_no_hooks(repo: TestRepo, temp_home: TempDir) {
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("hook").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
@@ -103,7 +103,7 @@ deploy = "scripts/deploy.sh"
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("hook")
.arg("show")
.arg("pre-merge")
@@ -143,7 +143,7 @@ test = "cargo test"
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
// Override config path to point to our test config with approval
cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
cmd.arg("hook").arg("show").current_dir(repo.root_path());
@@ -193,7 +193,7 @@ worktree-path = "../project.{{ branch }}"
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("hook").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
diff --git a/tests/integration_tests/init.rs b/tests/integration_tests/init.rs
index b041d177f..7b1395f4f 100644
--- a/tests/integration_tests/init.rs
+++ b/tests/integration_tests/init.rs
@@ -21,7 +21,7 @@ fn snapshot_init(test_name: &str, repo: &TestRepo, shell: &str, extra_args: &[&s
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("config").arg("shell").arg("init").arg(shell);
for arg in extra_args {
@@ -52,7 +52,7 @@ fn test_init_invalid_shell(repo: TestRepo) {
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("config")
.arg("shell")
.arg("init")
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 146a57f5e..571408d9c 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -235,14 +235,14 @@ fn test_list_previous_worktree_gutter(mut repo: TestRepo) {
// Step 1: From main, switch to feature (history: current=feature, previous=main)
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.args(["switch", "feature"])
.current_dir(repo.root_path());
cmd.output().unwrap();
// Step 2: From feature, switch back to main (history: current=main, previous=feature)
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.args(["switch", "main"]).current_dir(&feature_path);
cmd.output().unwrap();
@@ -719,7 +719,7 @@ fn test_list_with_upstream_tracking(mut repo: TestRepo) {
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
cmd.arg("list")
.arg("--branches")
@@ -2415,7 +2415,8 @@ fn test_list_maximum_status_symbols(mut repo: TestRepo) {
// Remember the shared base (Feature work)
let base_sha = {
let output = repo
- .git_command(&["rev-parse", "HEAD"])
+ .git_command()
+ .args(["rev-parse", "HEAD"])
.current_dir(&feature)
.output()
.unwrap();
@@ -2424,17 +2425,20 @@ fn test_list_maximum_status_symbols(mut repo: TestRepo) {
// Remote-only commit
std::fs::write(feature.join("remote-file.txt"), "remote content").unwrap();
- repo.git_command(&["add", "remote-file.txt"])
+ repo.git_command()
+ .args(["add", "remote-file.txt"])
.current_dir(&feature)
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Remote commit"])
+ repo.git_command()
+ .args(["commit", "-m", "Remote commit"])
.current_dir(&feature)
.output()
.unwrap();
let remote_sha = {
let output = repo
- .git_command(&["rev-parse", "HEAD"])
+ .git_command()
+ .args(["rev-parse", "HEAD"])
.current_dir(&feature)
.output()
.unwrap();
@@ -2442,28 +2446,33 @@ fn test_list_maximum_status_symbols(mut repo: TestRepo) {
};
// Reset back to base so the remote commit is not in the local branch history
- repo.git_command(&["reset", "--hard", &base_sha])
+ repo.git_command()
+ .args(["reset", "--hard", &base_sha])
.current_dir(&feature)
.output()
.unwrap();
// Local-only commit (divergence on the local side)
std::fs::write(feature.join("local-file.txt"), "local content").unwrap();
- repo.git_command(&["add", "local-file.txt"])
+ repo.git_command()
+ .args(["add", "local-file.txt"])
.current_dir(&feature)
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Local commit"])
+ repo.git_command()
+ .args(["commit", "-m", "Local commit"])
.current_dir(&feature)
.output()
.unwrap();
// Wire up upstream tracking deterministically: point origin/feature at the remote-only commit
- repo.git_command(&["update-ref", "refs/remotes/origin/feature", &remote_sha])
+ repo.git_command()
+ .args(["update-ref", "refs/remotes/origin/feature", &remote_sha])
.current_dir(&feature)
.output()
.unwrap();
- repo.git_command(&["branch", "--set-upstream-to=origin/feature", "feature"])
+ repo.git_command()
+ .args(["branch", "--set-upstream-to=origin/feature", "feature"])
.current_dir(&feature)
.output()
.unwrap();
@@ -2644,24 +2653,33 @@ fn test_list_shows_warning_on_git_error(mut repo: TestRepo) {
#[rstest]
fn test_list_handles_orphan_branch(repo: TestRepo) {
// Create an orphan branch (no common ancestor with main)
- repo.git_command(&["checkout", "--orphan", "assets"])
+ repo.git_command()
+ .args(["checkout", "--orphan", "assets"])
.output()
.unwrap();
// Clear working tree and create new content
- repo.git_command(&["rm", "-rf", "."]).output().unwrap();
+ repo.git_command()
+ .args(["rm", "-rf", "."])
+ .output()
+ .unwrap();
std::fs::write(repo.root_path().join("asset.txt"), "asset content\n").unwrap();
- repo.git_command(&["add", "."]).output().unwrap();
- repo.git_command(&["commit", "-m", "Add asset"])
+ repo.git_command().args(["add", "."]).output().unwrap();
+ repo.git_command()
+ .args(["commit", "-m", "Add asset"])
.output()
.unwrap();
// Go back to main
- repo.git_command(&["checkout", "main"]).output().unwrap();
+ repo.git_command()
+ .args(["checkout", "main"])
+ .output()
+ .unwrap();
// Verify no merge base exists (this confirms we have a true orphan branch)
let output = repo
- .git_command(&["merge-base", "main", "assets"])
+ .git_command()
+ .args(["merge-base", "main", "assets"])
.output()
.unwrap();
assert!(
diff --git a/tests/integration_tests/list_config.rs b/tests/integration_tests/list_config.rs
index d33fb91bc..b590f4ad8 100644
--- a/tests/integration_tests/list_config.rs
+++ b/tests/integration_tests/list_config.rs
@@ -27,7 +27,7 @@ full = true
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
@@ -62,7 +62,7 @@ branches = true
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
@@ -97,7 +97,7 @@ branches = false
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
// CLI flag --branches should override config
cmd.arg("list")
@@ -136,7 +136,7 @@ branches = true
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
@@ -168,7 +168,7 @@ fn test_list_no_config(repo: TestRepo, temp_home: TempDir) {
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
@@ -199,7 +199,7 @@ url = "http://localhost:{{ branch | hash_port }}"
let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
@@ -228,7 +228,7 @@ url = "http://localhost:{{ branch | hash_port }}"
.unwrap();
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.args(["list", "--format=json"])
.current_dir(repo.root_path());
@@ -269,7 +269,7 @@ fn test_list_json_no_url_without_template(repo: TestRepo, temp_home: TempDir) {
.unwrap();
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.args(["list", "--format=json"])
.current_dir(repo.root_path());
@@ -317,7 +317,7 @@ url = "http://localhost:{{ branch | hash_port }}"
.unwrap();
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.args(["list", "--branches", "--format=json"])
.current_dir(repo.root_path());
@@ -358,7 +358,7 @@ url = "http://localhost:8080/{{ branch }}"
.unwrap();
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
cmd.args(["list", "--format=json"])
.current_dir(repo.root_path());
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index bb633a6dc..19a644e2b 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -2663,7 +2663,7 @@ fn test_merge_error_conflicting_changes_in_target(mut repo_with_alternate_primar
fn test_step_commit_show_prompt(repo: TestRepo) {
// Create some staged changes so there's a diff to include in the prompt
fs::write(repo.root_path().join("new_file.txt"), "new content").expect("Failed to write file");
- repo.git_command(&["add", "new_file.txt"]);
+ repo.git_command().args(["add", "new_file.txt"]);
// The prompt should be written to stdout
snapshot_step_commit_with_env(
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 9161c3b09..fd8e20703 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -251,7 +251,8 @@ approved-commands = ["echo 'Default: {{ default_branch }}' > default.txt"]
#[rstest]
fn test_post_create_git_variables_template(#[from(repo_with_remote)] repo: TestRepo) {
// Set up an upstream tracking branch
- repo.git_command(&["push", "-u", "origin", "main"])
+ repo.git_command()
+ .args(["push", "-u", "origin", "main"])
.output()
.expect("failed to push");
@@ -323,7 +324,8 @@ worktree_name = "echo 'Worktree Name: {{ worktree_name }}' >> git_vars.txt"
#[rstest]
fn test_post_create_upstream_template(#[from(repo_with_remote)] repo: TestRepo) {
// Push main to set up tracking
- repo.git_command(&["push", "-u", "origin", "main"])
+ repo.git_command()
+ .args(["push", "-u", "origin", "main"])
.output()
.expect("failed to push main");
diff --git a/tests/integration_tests/readme_sync.rs b/tests/integration_tests/readme_sync.rs
index fe89d54ea..72c96e5ab 100644
--- a/tests/integration_tests/readme_sync.rs
+++ b/tests/integration_tests/readme_sync.rs
@@ -19,11 +19,11 @@
//! 4. **Updating**: `update_section()` finds markers and replaces content
#![cfg(not(windows))]
+use crate::common::wt_command;
use ansi_to_html::convert as ansi_to_html;
use regex::Regex;
use std::fs;
use std::path::Path;
-use std::process::Command;
use std::sync::LazyLock;
/// Unified pattern for all AUTO-GENERATED markers (README and docs)
@@ -558,8 +558,8 @@ fn get_help_output(id: &str, project_root: &Path) -> Result<String, String> {
return Err(format!("Command must end with '--help-md': {}", command));
}
- // Use the already-built binary from cargo test
- let output = Command::new(env!("CARGO_BIN_EXE_wt"))
+ // Use the already-built binary from cargo test (wt_command provides isolation)
+ let output = wt_command()
.args(&args[1..]) // Skip "wt" prefix
.current_dir(project_root)
.output()
@@ -1175,7 +1175,7 @@ fn test_command_pages_are_in_sync() {
}
// Run wt <cmd> --help-page (outputs START marker + content + END marker)
- let output = Command::new(env!("CARGO_BIN_EXE_wt"))
+ let output = wt_command()
.args([cmd, "--help-page"])
.current_dir(project_root)
.output()
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index 5983e4dfd..b986e5ffc 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -149,7 +149,7 @@ fn test_remove_nonexistent_worktree(repo: TestRepo) {
#[rstest]
fn test_remove_branch_no_worktree_path_occupied(mut repo: TestRepo) {
// Create branch `npm` without a worktree
- repo.git_command(&["branch", "npm"]).output().unwrap();
+ repo.git_command().args(["branch", "npm"]).output().unwrap();
// Create a worktree for a different branch at the path where `npm` worktree would be
// (the path template puts worktrees at ../repo.branch, so ../repo.npm would be npm's path)
@@ -167,24 +167,26 @@ fn test_remove_branch_no_worktree_path_occupied(mut repo: TestRepo) {
));
// Remove the worktree metadata and move the directory
- repo.git_command(&[
- "worktree",
- "remove",
- "--force",
- other_path.to_str().unwrap(),
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "worktree",
+ "remove",
+ "--force",
+ other_path.to_str().unwrap(),
+ ])
+ .output()
+ .unwrap();
// Create worktree at npm's expected path but for the "other" branch
- repo.git_command(&[
- "worktree",
- "add",
- npm_expected_path.to_str().unwrap(),
- "other",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "worktree",
+ "add",
+ npm_expected_path.to_str().unwrap(),
+ "other",
+ ])
+ .output()
+ .unwrap();
// Now: branch `npm` exists, no worktree for it, but npm's expected path has `other` branch
// Running `wt remove npm` should show "No worktree found" NOT "Cannot create worktree"
@@ -326,11 +328,13 @@ fn test_remove_branch_not_fully_merged(mut repo: TestRepo) {
// Add a commit to the feature branch that's not in main
std::fs::write(worktree_path.join("feature.txt"), "new feature").unwrap();
- repo.git_command(&["add", "feature.txt"])
+ repo.git_command()
+ .args(["add", "feature.txt"])
.current_dir(&worktree_path)
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Add feature"])
+ repo.git_command()
+ .args(["commit", "-m", "Add feature"])
.current_dir(&worktree_path)
.output()
.unwrap();
@@ -366,11 +370,13 @@ fn test_remove_foreground_unmerged(mut repo: TestRepo) {
// Add a commit to the feature branch that's not in main
std::fs::write(worktree_path.join("feature.txt"), "new feature").unwrap();
- repo.git_command(&["add", "feature.txt"])
+ repo.git_command()
+ .args(["add", "feature.txt"])
.current_dir(&worktree_path)
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Add feature"])
+ repo.git_command()
+ .args(["commit", "-m", "Add feature"])
.current_dir(&worktree_path)
.output()
.unwrap();
@@ -410,17 +416,22 @@ fn test_remove_foreground_no_delete_branch_unmerged(mut repo: TestRepo) {
// Add a commit to the feature branch that's not in main
std::fs::write(worktree_path.join("feature.txt"), "new feature").unwrap();
- repo.git_command(&["add", "feature.txt"])
+ repo.git_command()
+ .args(["add", "feature.txt"])
.current_dir(&worktree_path)
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Add feature"])
+ repo.git_command()
+ .args(["commit", "-m", "Add feature"])
.current_dir(&worktree_path)
.output()
.unwrap();
// Go back to main
- repo.git_command(&["checkout", "main"]).output().unwrap();
+ repo.git_command()
+ .args(["checkout", "main"])
+ .output()
+ .unwrap();
// Remove with both --no-background and --no-delete-branch
// No hint because:
@@ -460,17 +471,22 @@ fn test_remove_no_delete_branch_unmerged(mut repo: TestRepo) {
// Add a commit to the feature branch that's not in main
std::fs::write(worktree_path.join("feature.txt"), "new feature").unwrap();
- repo.git_command(&["add", "feature.txt"])
+ repo.git_command()
+ .args(["add", "feature.txt"])
.current_dir(&worktree_path)
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Add feature"])
+ repo.git_command()
+ .args(["commit", "-m", "Add feature"])
.current_dir(&worktree_path)
.output()
.unwrap();
// Go back to main before removing
- repo.git_command(&["checkout", "main"]).output().unwrap();
+ repo.git_command()
+ .args(["checkout", "main"])
+ .output()
+ .unwrap();
// Remove worktree with --no-delete-branch flag
// Since branch is unmerged, the flag has no effect - no hint shown
@@ -485,7 +501,8 @@ fn test_remove_no_delete_branch_unmerged(mut repo: TestRepo) {
#[rstest]
fn test_remove_branch_only_merged(repo: TestRepo) {
// Create a branch from main without a worktree (already merged)
- repo.git_command(&["branch", "feature-merged"])
+ repo.git_command()
+ .args(["branch", "feature-merged"])
.output()
.unwrap();
@@ -501,20 +518,29 @@ fn test_remove_branch_only_merged(repo: TestRepo) {
#[rstest]
fn test_remove_branch_only_unmerged(repo: TestRepo) {
// Create a branch with a unique commit (not in main)
- repo.git_command(&["branch", "feature-unmerged"])
+ repo.git_command()
+ .args(["branch", "feature-unmerged"])
.output()
.unwrap();
// Add a commit to the branch that's not in main
- repo.git_command(&["checkout", "feature-unmerged"])
+ repo.git_command()
+ .args(["checkout", "feature-unmerged"])
.output()
.unwrap();
std::fs::write(repo.root_path().join("feature.txt"), "new feature").unwrap();
- repo.git_command(&["add", "feature.txt"]).output().unwrap();
- repo.git_command(&["commit", "-m", "Add feature"])
+ repo.git_command()
+ .args(["add", "feature.txt"])
+ .output()
+ .unwrap();
+ repo.git_command()
+ .args(["commit", "-m", "Add feature"])
+ .output()
+ .unwrap();
+ repo.git_command()
+ .args(["checkout", "main"])
.output()
.unwrap();
- repo.git_command(&["checkout", "main"]).output().unwrap();
// Try to remove the branch (no worktree exists, branch not merged)
// Branch deletion should fail but not error
@@ -529,20 +555,29 @@ fn test_remove_branch_only_unmerged(repo: TestRepo) {
#[rstest]
fn test_remove_branch_only_force_delete(repo: TestRepo) {
// Create a branch with a unique commit (not in main)
- repo.git_command(&["branch", "feature-force"])
+ repo.git_command()
+ .args(["branch", "feature-force"])
.output()
.unwrap();
// Add a commit to the branch that's not in main
- repo.git_command(&["checkout", "feature-force"])
+ repo.git_command()
+ .args(["checkout", "feature-force"])
.output()
.unwrap();
std::fs::write(repo.root_path().join("feature.txt"), "new feature").unwrap();
- repo.git_command(&["add", "feature.txt"]).output().unwrap();
- repo.git_command(&["commit", "-m", "Add feature"])
+ repo.git_command()
+ .args(["add", "feature.txt"])
+ .output()
+ .unwrap();
+ repo.git_command()
+ .args(["commit", "-m", "Add feature"])
+ .output()
+ .unwrap();
+ repo.git_command()
+ .args(["checkout", "main"])
.output()
.unwrap();
- repo.git_command(&["checkout", "main"]).output().unwrap();
// Force delete the branch (no worktree exists)
snapshot_remove(
@@ -626,31 +661,45 @@ fn test_remove_at_from_detached_head_in_worktree(mut repo: TestRepo) {
#[rstest]
fn test_remove_branch_matching_tree_content(repo: TestRepo) {
// Create a feature branch from main
- repo.git_command(&["branch", "feature-squashed"])
+ repo.git_command()
+ .args(["branch", "feature-squashed"])
.output()
.unwrap();
// On feature branch: add a file
- repo.git_command(&["checkout", "feature-squashed"])
+ repo.git_command()
+ .args(["checkout", "feature-squashed"])
.output()
.unwrap();
std::fs::write(repo.root_path().join("feature.txt"), "squash content").unwrap();
- repo.git_command(&["add", "feature.txt"]).output().unwrap();
- repo.git_command(&["commit", "-m", "Add feature (on feature branch)"])
+ repo.git_command()
+ .args(["add", "feature.txt"])
+ .output()
+ .unwrap();
+ repo.git_command()
+ .args(["commit", "-m", "Add feature (on feature branch)"])
.output()
.unwrap();
// On main: add the same file with same content (simulates squash merge result)
- repo.git_command(&["checkout", "main"]).output().unwrap();
+ repo.git_command()
+ .args(["checkout", "main"])
+ .output()
+ .unwrap();
std::fs::write(repo.root_path().join("feature.txt"), "squash content").unwrap();
- repo.git_command(&["add", "feature.txt"]).output().unwrap();
- repo.git_command(&["commit", "-m", "Add feature (squash merged)"])
+ repo.git_command()
+ .args(["add", "feature.txt"])
+ .output()
+ .unwrap();
+ repo.git_command()
+ .args(["commit", "-m", "Add feature (squash merged)"])
.output()
.unwrap();
// Verify the setup: feature-squashed is NOT an ancestor of main (different commits)
let is_ancestor = repo
- .git_command(&["merge-base", "--is-ancestor", "feature-squashed", "main"])
+ .git_command()
+ .args(["merge-base", "--is-ancestor", "feature-squashed", "main"])
.output()
.unwrap();
assert!(
@@ -660,14 +709,16 @@ fn test_remove_branch_matching_tree_content(repo: TestRepo) {
// Verify: tree SHAs should match
let feature_tree = String::from_utf8(
- repo.git_command(&["rev-parse", "feature-squashed^{tree}"])
+ repo.git_command()
+ .args(["rev-parse", "feature-squashed^{tree}"])
.output()
.unwrap()
.stdout,
)
.unwrap();
let main_tree = String::from_utf8(
- repo.git_command(&["rev-parse", "main^{tree}"])
+ repo.git_command()
+ .args(["rev-parse", "main^{tree}"])
.output()
.unwrap()
.stdout,
@@ -895,42 +946,55 @@ fn test_remove_default_branch_no_tautology() {
#[rstest]
fn test_remove_squash_merged_then_main_advanced(repo: TestRepo) {
// Create feature branch
- repo.git_command(&["checkout", "-b", "feature-squash"])
+ repo.git_command()
+ .args(["checkout", "-b", "feature-squash"])
.output()
.unwrap();
// Make changes on feature branch (file A)
std::fs::write(repo.root_path().join("feature-a.txt"), "feature content").unwrap();
- repo.git_command(&["add", "feature-a.txt"])
+ repo.git_command()
+ .args(["add", "feature-a.txt"])
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Add feature A"])
+ repo.git_command()
+ .args(["commit", "-m", "Add feature A"])
.output()
.unwrap();
// Go back to main
- repo.git_command(&["checkout", "main"]).output().unwrap();
+ repo.git_command()
+ .args(["checkout", "main"])
+ .output()
+ .unwrap();
// Squash merge feature into main (simulating GitHub squash merge)
// This creates a NEW commit on main with the same content changes
std::fs::write(repo.root_path().join("feature-a.txt"), "feature content").unwrap();
- repo.git_command(&["add", "feature-a.txt"])
+ repo.git_command()
+ .args(["add", "feature-a.txt"])
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Add feature A (squash merged)"])
+ repo.git_command()
+ .args(["commit", "-m", "Add feature A (squash merged)"])
.output()
.unwrap();
// Main advances with another commit (file B)
std::fs::write(repo.root_path().join("main-b.txt"), "main content").unwrap();
- repo.git_command(&["add", "main-b.txt"]).output().unwrap();
- repo.git_command(&["commit", "-m", "Main advances with B"])
+ repo.git_command()
+ .args(["add", "main-b.txt"])
+ .output()
+ .unwrap();
+ repo.git_command()
+ .args(["commit", "-m", "Main advances with B"])
.output()
.unwrap();
// Verify setup: feature-squash is NOT an ancestor of main (squash creates different SHAs)
let is_ancestor = repo
- .git_command(&["merge-base", "--is-ancestor", "feature-squash", "main"])
+ .git_command()
+ .args(["merge-base", "--is-ancestor", "feature-squash", "main"])
.output()
.unwrap();
assert!(
@@ -940,14 +1004,16 @@ fn test_remove_squash_merged_then_main_advanced(repo: TestRepo) {
// Verify setup: trees don't match (main has file B that feature doesn't)
let feature_tree = String::from_utf8(
- repo.git_command(&["rev-parse", "feature-squash^{tree}"])
+ repo.git_command()
+ .args(["rev-parse", "feature-squash^{tree}"])
.output()
.unwrap()
.stdout,
)
.unwrap();
let main_tree = String::from_utf8(
- repo.git_command(&["rev-parse", "main^{tree}"])
+ repo.git_command()
+ .args(["rev-parse", "main^{tree}"])
.output()
.unwrap()
.stdout,
@@ -1069,7 +1135,7 @@ approved-commands = ["echo 'hook ran' > {}"]
// Remove in background mode (default)
let mut cmd = std::process::Command::new(env!("CARGO_BIN_EXE_wt"));
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.current_dir(repo.root_path())
.args(["remove", "feature-bg"])
.output()
@@ -1143,13 +1209,14 @@ approved-commands = ["echo 'hook ran' > {}"]
));
// Create a branch without a worktree
- repo.git_command(&["branch", "branch-only"])
+ repo.git_command()
+ .args(["branch", "branch-only"])
.output()
.unwrap();
// Remove the branch (no worktree)
let mut cmd = std::process::Command::new(env!("CARGO_BIN_EXE_wt"));
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.current_dir(repo.root_path())
.args(["remove", "branch-only"])
.output()
diff --git a/tests/integration_tests/repository.rs b/tests/integration_tests/repository.rs
index 063c28f35..f8b6fed65 100644
--- a/tests/integration_tests/repository.rs
+++ b/tests/integration_tests/repository.rs
@@ -141,7 +141,8 @@ fn test_available_branches_all_have_worktrees() {
fn test_available_branches_some_without_worktrees() {
let repo = TestRepo::new();
// Create a branch without a worktree
- repo.git_command(&["branch", "orphan-branch"])
+ repo.git_command()
+ .args(["branch", "orphan-branch"])
.output()
.unwrap();
@@ -162,8 +163,14 @@ fn test_available_branches_some_without_worktrees() {
fn test_all_branches() {
let repo = TestRepo::new();
// Create some branches
- repo.git_command(&["branch", "alpha"]).output().unwrap();
- repo.git_command(&["branch", "beta"]).output().unwrap();
+ repo.git_command()
+ .args(["branch", "alpha"])
+ .output()
+ .unwrap();
+ repo.git_command()
+ .args(["branch", "beta"])
+ .output()
+ .unwrap();
let repository = Repository::at(repo.root_path().to_path_buf());
let branches = repository.all_branches().unwrap();
@@ -182,14 +189,15 @@ fn test_project_identifier_https() {
let mut repo = TestRepo::new();
repo.setup_remote("main");
// Override the remote URL to https format
- repo.git_command(&[
- "remote",
- "set-url",
- "origin",
- "https://github.com/user/repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "set-url",
+ "origin",
+ "https://github.com/user/repo.git",
+ ])
+ .output()
+ .unwrap();
let repository = Repository::at(repo.root_path().to_path_buf());
let id = repository.project_identifier().unwrap();
@@ -201,14 +209,15 @@ fn test_project_identifier_http() {
let mut repo = TestRepo::new();
repo.setup_remote("main");
// Override the remote URL to http format (no SSL)
- repo.git_command(&[
- "remote",
- "set-url",
- "origin",
- "http://gitlab.example.com/team/project.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "set-url",
+ "origin",
+ "http://gitlab.example.com/team/project.git",
+ ])
+ .output()
+ .unwrap();
let repository = Repository::at(repo.root_path().to_path_buf());
let id = repository.project_identifier().unwrap();
@@ -220,14 +229,15 @@ fn test_project_identifier_ssh_colon() {
let mut repo = TestRepo::new();
repo.setup_remote("main");
// Override the remote URL to SSH format with colon
- repo.git_command(&[
- "remote",
- "set-url",
- "origin",
- "[email protected]:user/repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "set-url",
+ "origin",
+ "[email protected]:user/repo.git",
+ ])
+ .output()
+ .unwrap();
let repository = Repository::at(repo.root_path().to_path_buf());
let id = repository.project_identifier().unwrap();
@@ -239,14 +249,15 @@ fn test_project_identifier_ssh_protocol() {
let mut repo = TestRepo::new();
repo.setup_remote("main");
// Override the remote URL to ssh:// format
- repo.git_command(&[
- "remote",
- "set-url",
- "origin",
- "ssh://[email protected]/user/repo.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "set-url",
+ "origin",
+ "ssh://[email protected]/user/repo.git",
+ ])
+ .output()
+ .unwrap();
let repository = Repository::at(repo.root_path().to_path_buf());
let id = repository.project_identifier().unwrap();
@@ -259,14 +270,15 @@ fn test_project_identifier_ssh_protocol_with_port() {
let mut repo = TestRepo::new();
repo.setup_remote("main");
// Override the remote URL to ssh:// format with port
- repo.git_command(&[
- "remote",
- "set-url",
- "origin",
- "ssh://[email protected]:2222/team/project.git",
- ])
- .output()
- .unwrap();
+ repo.git_command()
+ .args([
+ "remote",
+ "set-url",
+ "origin",
+ "ssh://[email protected]:2222/team/project.git",
+ ])
+ .output()
+ .unwrap();
let repository = Repository::at(repo.root_path().to_path_buf());
let id = repository.project_identifier().unwrap();
@@ -292,7 +304,8 @@ fn test_project_identifier_no_remote_fallback() {
#[test]
fn test_get_config_exists() {
let repo = TestRepo::new();
- repo.git_command(&["config", "test.key", "test-value"])
+ repo.git_command()
+ .args(["config", "test.key", "test-value"])
.output()
.unwrap();
diff --git a/tests/integration_tests/security.rs b/tests/integration_tests/security.rs
index 0d6eb3106..072cbf91d 100644
--- a/tests/integration_tests/security.rs
+++ b/tests/integration_tests/security.rs
@@ -221,7 +221,7 @@ fn test_branch_name_is_directive_not_executed(repo: TestRepo) {
settings.bind(|| {
let (directive_path, _guard) = directive_file();
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("switch")
.arg("--create")
@@ -260,7 +260,7 @@ fn test_branch_name_with_newline_directive_not_executed(repo: TestRepo) {
settings.bind(|| {
let (directive_path, _guard) = directive_file();
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("switch")
.arg("--create")
@@ -295,7 +295,7 @@ fn test_commit_message_with_directive_not_executed(mut repo: TestRepo) {
// Run 'wt list' which might show commit messages
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
// Verify output - commit message should be escaped/sanitized
@@ -326,7 +326,7 @@ fn test_path_with_directive_not_executed(repo: TestRepo) {
// Run a command that might display this path
settings.bind(|| {
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
assert_cmd_snapshot!(cmd);
@@ -363,7 +363,7 @@ fn test_branch_name_with_cd_directive_not_executed(repo: TestRepo) {
settings.bind(|| {
let (directive_path, _guard) = directive_file();
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("switch")
.arg("--create")
@@ -388,7 +388,7 @@ fn test_error_message_with_directive_not_executed(repo: TestRepo) {
settings.bind(|| {
let (directive_path, _guard) = directive_file();
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("switch")
.arg(malicious_branch)
@@ -432,7 +432,7 @@ fn test_execute_flag_with_directive_like_branch_name(repo: TestRepo) {
settings.bind(|| {
let (directive_path, _guard) = directive_file();
let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
configure_directive_file(&mut cmd, &directive_path);
cmd.arg("switch")
.arg("--create")
diff --git a/tests/integration_tests/select.rs b/tests/integration_tests/select.rs
index c59bb42cb..a14630818 100644
--- a/tests/integration_tests/select.rs
+++ b/tests/integration_tests/select.rs
@@ -369,7 +369,8 @@ fn test_select_with_branches(mut repo: TestRepo) {
repo.add_worktree("active-worktree");
// Create a branch without a worktree
let output = repo
- .git_command(&["branch", "orphan-branch"])
+ .git_command()
+ .args(["branch", "orphan-branch"])
.output()
.unwrap();
assert!(output.status.success(), "Failed to create branch");
@@ -398,12 +399,14 @@ fn test_select_preview_panel_uncommitted(mut repo: TestRepo) {
// First, create and commit a file so we have something to modify
std::fs::write(feature_path.join("tracked.txt"), "Original content\n").unwrap();
let output = repo
- .git_command(&["-C", feature_path.to_str().unwrap(), "add", "tracked.txt"])
+ .git_command()
+ .args(["-C", feature_path.to_str().unwrap(), "add", "tracked.txt"])
.output()
.unwrap();
assert!(output.status.success(), "Failed to add file");
let output = repo
- .git_command(&[
+ .git_command()
+ .args([
"-C",
feature_path.to_str().unwrap(),
"commit",
@@ -456,12 +459,14 @@ fn test_select_preview_panel_log(mut repo: TestRepo) {
)
.unwrap();
let output = repo
- .git_command(&["-C", feature_path.to_str().unwrap(), "add", "."])
+ .git_command()
+ .args(["-C", feature_path.to_str().unwrap(), "add", "."])
.output()
.unwrap();
assert!(output.status.success(), "Failed to add files");
let output = repo
- .git_command(&[
+ .git_command()
+ .args([
"-C",
feature_path.to_str().unwrap(),
"commit",
@@ -513,12 +518,14 @@ fn test_select_preview_panel_main_diff(mut repo: TestRepo) {
)
.unwrap();
let output = repo
- .git_command(&["-C", feature_path.to_str().unwrap(), "add", "."])
+ .git_command()
+ .args(["-C", feature_path.to_str().unwrap(), "add", "."])
.output()
.unwrap();
assert!(output.status.success(), "Failed to add files");
let output = repo
- .git_command(&[
+ .git_command()
+ .args([
"-C",
feature_path.to_str().unwrap(),
"commit",
@@ -540,12 +547,14 @@ fn test_new_feature() {
)
.unwrap();
let output = repo
- .git_command(&["-C", feature_path.to_str().unwrap(), "add", "."])
+ .git_command()
+ .args(["-C", feature_path.to_str().unwrap(), "add", "."])
.output()
.unwrap();
assert!(output.status.success(), "Failed to add files");
let output = repo
- .git_command(&[
+ .git_command()
+ .args([
"-C",
feature_path.to_str().unwrap(),
"commit",
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index df88f8ca9..0e3916f91 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -170,7 +170,7 @@ fn generate_wrapper(repo: &TestRepo, shell: &str) -> String {
cmd.arg("config").arg("shell").arg("init").arg(shell);
// Configure environment
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
let output = cmd.output().unwrap_or_else(|e| {
panic!(
diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rs
index 5f39f7b78..0dcd73509 100644
--- a/tests/integration_tests/statusline.rs
+++ b/tests/integration_tests/statusline.rs
@@ -21,7 +21,7 @@ fn run_statusline_from_dir(
cmd.args(args);
// Apply repo's git environment
- repo.clean_cli_env(&mut cmd);
+ repo.configure_wt_cmd(&mut cmd);
if stdin_json.is_some() {
cmd.stdin(Stdio::piped());
@@ -73,21 +73,25 @@ fn add_commits_ahead(repo: &mut TestRepo) {
// Add commits in the feature worktree
std::fs::write(feature_path.join("feature.txt"), "feature content").unwrap();
- repo.git_command(&["add", "."])
+ repo.git_command()
+ .args(["add", "."])
.current_dir(&feature_path)
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Feature commit 1"])
+ repo.git_command()
+ .args(["commit", "-m", "Feature commit 1"])
.current_dir(&feature_path)
.output()
.unwrap();
std::fs::write(feature_path.join("feature2.txt"), "more content").unwrap();
- repo.git_command(&["add", "."])
+ repo.git_command()
+ .args(["add", "."])
.current_dir(&feature_path)
.output()
.unwrap();
- repo.git_command(&["commit", "-m", "Feature commit 2"])
+ repo.git_command()
+ .args(["commit", "-m", "Feature commit 2"])
.current_dir(&feature_path)
.output()
.unwrap();
@@ -220,9 +224,13 @@ fn test_statusline_reflects_checked_out_branch(mut repo: TestRepo) {
);
// Create and checkout a different branch "other" in the feature worktree
- repo.git_command(&["branch", "other"]).output().unwrap();
+ repo.git_command()
+ .args(["branch", "other"])
+ .output()
+ .unwrap();
let checkout_output = repo
- .git_command(&["checkout", "other"])
+ .git_command()
+ .args(["checkout", "other"])
.current_dir(&feature_path)
.output()
.unwrap();
@@ -251,7 +259,8 @@ fn test_statusline_detached_head(mut repo: TestRepo) {
let feature_path = repo.add_worktree("feature");
// Detach HEAD
- repo.git_command(&["checkout", "--detach"])
+ repo.git_command()
+ .args(["checkout", "--detach"])
.current_dir(&feature_path)
.output()
.unwrap();
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index fc349c970..2aa4936b5 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -122,7 +122,7 @@ fn test_switch_existing_with_shell_integration_configured(mut repo: TestRepo) {
repo.add_worktree("shell-configured");
// Simulate shell integration configured in user's shell rc files
- // (repo.home_path() is automatically set as HOME by clean_cli_env)
+ // (repo.home_path() is automatically set as HOME by configure_wt_cmd)
let zshrc_path = repo.home_path().join(".zshrc");
fs::write(
&zshrc_path,
@@ -368,7 +368,7 @@ fn test_switch_no_config_commands_with_yes(repo: TestRepo) {
repo.commit("Add config");
// With --no-verify, even --yes shouldn't execute config commands
- // (HOME is automatically set to repo.home_path() by clean_cli_env)
+ // (HOME is automatically set to repo.home_path() by configure_wt_cmd)
snapshot_switch(
"switch_no_hooks_with_yes",
&repo,
@@ -737,14 +737,12 @@ fn test_switch_missing_argument_shows_hints(repo: TestRepo) {
#[rstest]
fn test_switch_execute_stdin_inheritance(repo: TestRepo) {
use std::io::Write;
- use std::process::{Command, Stdio};
+ use std::process::Stdio;
let test_input = "stdin_inheritance_test_content\n";
- let mut cmd = Command::new(env!("CARGO_BIN_EXE_wt"));
- repo.configure_git_cmd(&mut cmd);
+ let mut cmd = repo.wt_command();
cmd.args(["switch", "--create", "stdin-test", "--execute", "cat"])
- .current_dir(repo.root_path())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());