Skip to content

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

Consolidate test git commands using helper methods (#339)

Maximilian Roos4709409ccb1f
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 963e3a798..3469b42b0 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -588,7 +588,8 @@ pub fn configure_git_cmd(cmd: &mut Command, git_config_path: &Path) {
/// Shared interface for test repository fixtures.
///
-/// Provides `configure_git_cmd()` and `git_command()` with consistent environment isolation.
+/// Provides `configure_git_cmd()`, `git_command()`, and `run_git_in()` with consistent
+/// environment isolation.
pub trait TestRepoBase {
/// Path to the git config file for this test.
fn git_config_path(&self) -> &Path;
@@ -605,6 +606,34 @@ pub trait TestRepoBase {
self.configure_git_cmd(&mut cmd);
cmd
}
+
+ /// Run a git command in a specific directory, panicking on failure.
+ fn run_git_in(&self, dir: &Path, args: &[&str]) {
+ let output = self.git_command(dir).args(args).output().unwrap();
+ check_git_status(&output, &args.join(" "));
+ }
+
+ /// Create a commit in the specified directory.
+ ///
+ /// Creates or overwrites `file.txt` with the message content, stages it, and commits.
+ fn commit_in(&self, dir: &Path, message: &str) {
+ std::fs::write(dir.join("file.txt"), message).unwrap();
+ self.run_git_in(dir, &["add", "file.txt"]);
+
+ let output = self
+ .git_command(dir)
+ .args(["commit", "-m", message])
+ .output()
+ .unwrap();
+
+ if !output.status.success() {
+ panic!(
+ "Failed to commit:\nstdout: {}\nstderr: {}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ }
+ }
}
/// Create a temporary file for directive output.
@@ -1140,15 +1169,10 @@ impl TestRepo {
self.git_command().args(["add", "."]).output().unwrap();
// Create commit with custom timestamp
- let mut cmd = Command::new("git");
- cmd.env("GIT_CONFIG_GLOBAL", &self.git_config_path);
- cmd.env("GIT_CONFIG_SYSTEM", NULL_DEVICE);
- cmd.env("GIT_AUTHOR_DATE", &timestamp);
- cmd.env("GIT_COMMITTER_DATE", &timestamp);
- cmd.env("LC_ALL", "C");
- cmd.env("LANG", "C");
- cmd.args(["commit", "-m", message])
- .current_dir(&self.root)
+ self.git_command()
+ .env("GIT_AUTHOR_DATE", &timestamp)
+ .env("GIT_COMMITTER_DATE", &timestamp)
+ .args(["commit", "-m", message])
.output()
.unwrap();
}
@@ -1169,14 +1193,10 @@ impl TestRepo {
let commit_time = TEST_EPOCH as i64 - age_seconds;
let timestamp = unix_to_iso8601(commit_time);
- let mut cmd = Command::new("git");
- cmd.env("GIT_CONFIG_GLOBAL", &self.git_config_path);
- cmd.env("GIT_CONFIG_SYSTEM", NULL_DEVICE);
- cmd.env("GIT_AUTHOR_DATE", &timestamp);
- cmd.env("GIT_COMMITTER_DATE", &timestamp);
- cmd.env("LC_ALL", "C");
- cmd.env("LANG", "C");
- cmd.args(["commit", "-m", message])
+ self.git_command()
+ .env("GIT_AUTHOR_DATE", &timestamp)
+ .env("GIT_COMMITTER_DATE", &timestamp)
+ .args(["commit", "-m", message])
.current_dir(dir)
.output()
.unwrap();
@@ -1388,14 +1408,12 @@ impl TestRepo {
/// Check if origin/HEAD is set
pub fn has_origin_head(&self) -> bool {
- let mut cmd = Command::new("git");
- self.configure_git_cmd(&mut cmd);
- let output = cmd
+ self.git_command()
.args(["rev-parse", "--abbrev-ref", "origin/HEAD"])
- .current_dir(&self.root)
.output()
- .unwrap();
- output.status.success()
+ .unwrap()
+ .status
+ .success()
}
/// Switch the primary worktree to a different branch
@@ -1739,6 +1757,137 @@ impl TestRepoBase for TestRepo {
}
}
+/// Helper to create a bare repository test setup.
+///
+/// Bare repositories are useful for testing scenarios where you need worktrees
+/// for the default branch (which isn't possible with normal repos since the
+/// main worktree already has it checked out).
+pub struct BareRepoTest {
+ temp_dir: tempfile::TempDir,
+ bare_repo_path: PathBuf,
+ test_config_path: PathBuf,
+ git_config_path: PathBuf,
+}
+
+impl BareRepoTest {
+ /// Create a new bare repository test setup.
+ ///
+ /// The bare repo is created at `temp_dir/repo` with worktrees configured
+ /// to be created as subdirectories (e.g., `repo/main`, `repo/feature`).
+ pub fn new() -> Self {
+ let temp_dir = tempfile::TempDir::new().unwrap();
+ // Bare repo without .git suffix - worktrees go inside as subdirectories
+ let bare_repo_path = temp_dir.path().join("repo");
+ let test_config_path = temp_dir.path().join("test-config.toml");
+ let git_config_path = temp_dir.path().join("test-gitconfig");
+
+ // Write git config with user settings
+ std::fs::write(
+ &git_config_path,
+ "[user]\n\tname = Test User\n\temail = [email protected]\n\
+ [advice]\n\tmergeConflict = false\n\tresolveConflict = false\n\
+ [init]\n\tdefaultBranch = main\n",
+ )
+ .unwrap();
+
+ let mut test = Self {
+ temp_dir,
+ bare_repo_path,
+ test_config_path,
+ git_config_path,
+ };
+
+ // Create bare repository
+ let mut cmd = Command::new("git");
+ cmd.args(["init", "--bare", "--initial-branch", "main"])
+ .arg(&test.bare_repo_path);
+ test.configure_git_cmd(&mut cmd);
+ let output = cmd.output().unwrap();
+
+ if !output.status.success() {
+ panic!(
+ "Failed to init bare repo:\nstdout: {}\nstderr: {}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ }
+
+ // Canonicalize path (using dunce to avoid \\?\ prefix on Windows)
+ test.bare_repo_path = canonicalize(&test.bare_repo_path).unwrap();
+
+ // Write config with template for worktrees inside bare repo
+ // Template {{ branch }} creates worktrees as subdirectories: repo/main, repo/feature
+ std::fs::write(&test.test_config_path, "worktree-path = \"{{ branch }}\"\n").unwrap();
+
+ test
+ }
+
+ /// Get the path to the bare repository.
+ pub fn bare_repo_path(&self) -> &Path {
+ &self.bare_repo_path
+ }
+
+ /// Get the path to the test config file.
+ pub fn config_path(&self) -> &Path {
+ &self.test_config_path
+ }
+
+ /// Get the temp directory path.
+ pub fn temp_path(&self) -> &Path {
+ self.temp_dir.path()
+ }
+
+ /// Create a worktree from the bare repository.
+ ///
+ /// Worktrees are created inside the bare repo directory: repo/main, repo/feature
+ pub fn create_worktree(&self, branch: &str, worktree_name: &str) -> PathBuf {
+ let worktree_path = self.bare_repo_path.join(worktree_name);
+
+ let output = self
+ .git_command(&self.bare_repo_path)
+ .args([
+ "worktree",
+ "add",
+ "-b",
+ branch,
+ worktree_path.to_str().unwrap(),
+ ])
+ .output()
+ .unwrap();
+
+ if !output.status.success() {
+ panic!(
+ "Failed to create worktree:\nstdout: {}\nstderr: {}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ }
+
+ canonicalize(&worktree_path).unwrap()
+ }
+
+ /// Configure a wt command with test environment.
+ pub fn configure_wt_cmd(&self, cmd: &mut Command) {
+ self.configure_git_cmd(cmd);
+ cmd.env("WORKTRUNK_CONFIG_PATH", &self.test_config_path)
+ .env_remove("NO_COLOR")
+ .env_remove("CLICOLOR_FORCE");
+ }
+
+ /// Create a pre-configured wt command.
+ pub fn wt_command(&self) -> Command {
+ let mut cmd = wt_command();
+ self.configure_wt_cmd(&mut cmd);
+ cmd
+ }
+}
+
+impl TestRepoBase for BareRepoTest {
+ fn git_config_path(&self) -> &Path {
+ &self.git_config_path
+ }
+}
+
/// Add standard env var redactions to insta settings
///
/// These redact volatile metadata captured by insta-cmd in the `info` block.
diff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rs
index bfcb4f36d..5d3ad5337 100644
--- a/tests/integration_tests/bare_repository.rs
+++ b/tests/integration_tests/bare_repository.rs
@@ -1,6 +1,6 @@
use crate::common::{
- TestRepo, TestRepoBase, canonicalize, configure_directive_file, directive_file, repo,
- setup_temp_snapshot_settings, wait_for_file, wt_command,
+ BareRepoTest, TestRepo, TestRepoBase, canonicalize, configure_directive_file, directive_file,
+ repo, setup_temp_snapshot_settings, wait_for_file, wt_command,
};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
@@ -9,155 +9,6 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::time::Duration;
-/// Helper to create a bare repository test setup
-struct BareRepoTest {
- temp_dir: tempfile::TempDir,
- bare_repo_path: PathBuf,
- test_config_path: PathBuf,
- git_config_path: PathBuf,
-}
-
-impl BareRepoTest {
- fn new() -> Self {
- let temp_dir = tempfile::TempDir::new().unwrap();
- // Bare repo without .git suffix - worktrees go inside as subdirectories
- let bare_repo_path = temp_dir.path().join("repo");
- let test_config_path = temp_dir.path().join("test-config.toml");
- let git_config_path = temp_dir.path().join("test-gitconfig");
-
- // Write git config with user settings
- fs::write(
- &git_config_path,
- "[user]\n\tname = Test User\n\temail = [email protected]\n\
- [advice]\n\tmergeConflict = false\n\tresolveConflict = false\n\
- [init]\n\tdefaultBranch = main\n",
- )
- .unwrap();
-
- let mut test = Self {
- temp_dir,
- bare_repo_path,
- test_config_path,
- git_config_path,
- };
-
- // Create bare repository
- let mut cmd = Command::new("git");
- cmd.args(["init", "--bare", "--initial-branch", "main"])
- .arg(&test.bare_repo_path);
- test.configure_git_cmd(&mut cmd);
- let output = cmd.output().unwrap();
-
- if !output.status.success() {
- panic!(
- "Failed to init bare repo:\nstdout: {}\nstderr: {}",
- String::from_utf8_lossy(&output.stdout),
- String::from_utf8_lossy(&output.stderr)
- );
- }
-
- // Canonicalize path (using dunce to avoid \\?\ prefix on Windows)
- test.bare_repo_path = canonicalize(&test.bare_repo_path).unwrap();
-
- // Write config with template for worktrees inside bare repo
- // Template {{ branch }} creates worktrees as subdirectories: repo/main, repo/feature
- fs::write(&test.test_config_path, "worktree-path = \"{{ branch }}\"\n").unwrap();
-
- test
- }
-
- fn bare_repo_path(&self) -> &PathBuf {
- &self.bare_repo_path
- }
-
- fn config_path(&self) -> &PathBuf {
- &self.test_config_path
- }
-
- /// Create a worktree from the bare repository
- /// Worktrees are created inside the bare repo directory: repo/main, repo/feature
- fn create_worktree(&self, branch: &str, worktree_name: &str) -> PathBuf {
- let worktree_path = self.bare_repo_path.join(worktree_name);
-
- let output = self
- .git_command(&self.bare_repo_path)
- .args([
- "worktree",
- "add",
- "-b",
- branch,
- worktree_path.to_str().unwrap(),
- ])
- .output()
- .unwrap();
-
- if !output.status.success() {
- panic!(
- "Failed to create worktree:\nstdout: {}\nstderr: {}",
- String::from_utf8_lossy(&output.stdout),
- String::from_utf8_lossy(&output.stderr)
- );
- }
-
- canonicalize(&worktree_path).unwrap()
- }
-
- /// Create a commit in the specified worktree
- fn commit_in_worktree(&self, worktree_path: &Path, message: &str) {
- // Create a file
- let file_path = worktree_path.join("file.txt");
- fs::write(&file_path, message).unwrap();
-
- // Add file
- let output = self
- .git_command(worktree_path)
- .args(["add", "file.txt"])
- .output()
- .unwrap();
-
- if !output.status.success() {
- panic!(
- "Failed to add file:\nstdout: {}\nstderr: {}",
- String::from_utf8_lossy(&output.stdout),
- String::from_utf8_lossy(&output.stderr)
- );
- }
-
- // Commit
- let output = self
- .git_command(worktree_path)
- .args(["commit", "-m", message])
- .output()
- .unwrap();
-
- if !output.status.success() {
- panic!(
- "Failed to commit:\nstdout: {}\nstderr: {}",
- String::from_utf8_lossy(&output.stdout),
- String::from_utf8_lossy(&output.stderr)
- );
- }
- }
-
- fn temp_path(&self) -> &Path {
- self.temp_dir.path()
- }
-
- /// Configure a wt command with test environment
- fn configure_wt_cmd(&self, cmd: &mut Command) {
- self.configure_git_cmd(cmd);
- cmd.env("WORKTRUNK_CONFIG_PATH", &self.test_config_path)
- .env_remove("NO_COLOR")
- .env_remove("CLICOLOR_FORCE");
- }
-}
-
-impl TestRepoBase for BareRepoTest {
- fn git_config_path(&self) -> &Path {
- &self.git_config_path
- }
-}
-
#[test]
fn test_bare_repo_list_worktrees() {
let test = BareRepoTest::new();
@@ -165,10 +16,10 @@ fn test_bare_repo_list_worktrees() {
// Create worktrees inside bare repo matching template: {{ branch }}
// Worktrees are at repo/main and repo/feature
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit on main");
+ test.commit_in(&main_worktree, "Initial commit on main");
let feature_worktree = test.create_worktree("feature", "feature");
- test.commit_in_worktree(&feature_worktree, "Work on feature");
+ test.commit_in(&feature_worktree, "Work on feature");
let settings = setup_temp_snapshot_settings(test.temp_path());
settings.bind(|| {
@@ -187,7 +38,7 @@ fn test_bare_repo_list_shows_no_bare_entry() {
// Create one worktree
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit");
+ test.commit_in(&main_worktree, "Initial commit");
// Run wt list and verify bare repo is NOT shown (only main worktree appears)
let settings = setup_temp_snapshot_settings(test.temp_path());
@@ -206,7 +57,7 @@ fn test_bare_repo_switch_creates_worktree() {
// Create initial worktree
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit");
+ test.commit_in(&main_worktree, "Initial commit");
// Run wt switch --create to create a new worktree
// Config uses {{ branch }} template, so worktrees are created inside bare repo
@@ -254,7 +105,7 @@ fn test_bare_repo_switch_with_configured_naming() {
// Create initial worktree
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit");
+ test.commit_in(&main_worktree, "Initial commit");
// Config uses "{{ branch }}" template, so worktrees are created inside bare repo
let (directive_path, _guard) = directive_file();
@@ -289,10 +140,10 @@ fn test_bare_repo_remove_worktree() {
// Create two worktrees
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit");
+ test.commit_in(&main_worktree, "Initial commit");
let feature_worktree = test.create_worktree("feature", "feature");
- test.commit_in_worktree(&feature_worktree, "Feature work");
+ test.commit_in(&feature_worktree, "Feature work");
// Remove feature worktree from main worktree
let (directive_path, _guard) = directive_file();
@@ -328,7 +179,7 @@ fn test_bare_repo_identifies_primary_correctly() {
// Create multiple worktrees
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Main commit");
+ test.commit_in(&main_worktree, "Main commit");
let _feature1 = test.create_worktree("feature1", "feature1");
let _feature2 = test.create_worktree("feature2", "feature2");
@@ -350,7 +201,7 @@ fn test_bare_repo_worktree_base_used_for_paths() {
// Create initial worktree
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit");
+ test.commit_in(&main_worktree, "Initial commit");
// Create new worktree - config uses {{ branch }} template
// Worktrees are created inside the bare repo directory
@@ -388,7 +239,7 @@ fn test_bare_repo_equivalent_to_normal_repo(repo: TestRepo) {
// Set up bare repo
let bare_test = BareRepoTest::new();
let bare_main = bare_test.create_worktree("main", "main");
- bare_test.commit_in_worktree(&bare_main, "Commit in bare repo");
+ bare_test.commit_in(&bare_main, "Commit in bare repo");
// Set up normal repo (using fixture)
repo.commit("Commit in normal repo");
@@ -427,7 +278,7 @@ fn test_bare_repo_commands_from_bare_directory() {
// Create a worktree so the repo has some content
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit");
+ test.commit_in(&main_worktree, "Initial commit");
// Run wt list from the bare repo directory itself (not from a worktree)
// Should list the worktree even when run from bare repo, not showing bare repo itself
@@ -452,7 +303,7 @@ fn test_bare_repo_merge_workflow() {
// Create main worktree
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit on main");
+ test.commit_in(&main_worktree, "Initial commit on main");
// Create feature branch worktree using wt switch
// Config uses {{ branch }} template, so worktrees are inside bare repo
@@ -469,7 +320,7 @@ fn test_bare_repo_merge_workflow() {
assert!(feature_worktree.exists(), "Feature worktree should exist");
// Make a commit in feature worktree
- test.commit_in_worktree(&feature_worktree, "Feature work");
+ test.commit_in(&feature_worktree, "Feature work");
// Merge feature into main (explicitly specify target)
let (directive_path, _guard) = directive_file();
@@ -531,11 +382,11 @@ fn test_bare_repo_background_logs_location() {
// Create main worktree
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit");
+ test.commit_in(&main_worktree, "Initial commit");
// Create feature worktree
let feature_worktree = test.create_worktree("feature", "feature");
- test.commit_in_worktree(&feature_worktree, "Feature work");
+ test.commit_in(&feature_worktree, "Feature work");
// Run remove in background to test log file location
let (directive_path, _guard) = directive_file();
@@ -582,7 +433,7 @@ fn test_bare_repo_slashed_branch_with_sanitize() {
// Create main worktree
let main_worktree = test.create_worktree("main", "main");
- test.commit_in_worktree(&main_worktree, "Initial commit");
+ test.commit_in(&main_worktree, "Initial commit");
// Create feature branch with slash using wt switch
let (directive_path, _guard) = directive_file();
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index 1a6bba32a..74e91e24c 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -1,7 +1,6 @@
use crate::common::{TestRepo, repo, wt_command, wt_completion_command};
use insta::Settings;
use rstest::rstest;
-use std::process::Command;
fn only_option_suggestions(stdout: &str) -> bool {
stdout
@@ -35,17 +34,8 @@ fn test_complete_switch_shows_branches(repo: TestRepo) {
repo.commit("initial");
// Create some branches using git
- Command::new("git")
- .args(["branch", "feature/new"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["branch", "hotfix/bug"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature/new"]);
+ repo.run_git(&["branch", "hotfix/bug"]);
// Test completion for switch command
let mut settings = Settings::clone_current();
@@ -68,11 +58,7 @@ fn test_complete_switch_shows_all_branches_including_worktrees(mut repo: TestRep
repo.add_worktree("feature/new");
// Create another branch without worktree
- Command::new("git")
- .args(["branch", "hotfix/bug"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "hotfix/bug"]);
// Test completion - should show branches WITH worktrees and WITHOUT worktrees
let mut settings = Settings::clone_current();
@@ -95,11 +81,7 @@ fn test_complete_push_shows_all_branches(mut repo: TestRepo) {
repo.add_worktree("feature/new");
// Create another branch without worktree
- Command::new("git")
- .args(["branch", "hotfix/bug"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "hotfix/bug"]);
// Test completion for step push (should show ALL branches, including those with worktrees)
let mut settings = Settings::clone_current();
@@ -126,17 +108,8 @@ fn test_complete_base_flag_all_formats(repo: TestRepo) {
repo.commit("initial");
// Create branches
- Command::new("git")
- .args(["branch", "develop"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["branch", "feature/existing"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "develop"]);
+ repo.run_git(&["branch", "feature/existing"]);
// Test all base flag formats: --base, -b, --base=, -b=
// For space-separated (--base ""), cursor is on empty arg after flag
@@ -320,23 +293,9 @@ fn test_complete_with_partial_prefix(repo: TestRepo) {
repo.commit("initial");
// Create branches with common prefix
- Command::new("git")
- .args(["branch", "feature/one"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["branch", "feature/two"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["branch", "hotfix/bug"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature/one"]);
+ repo.run_git(&["branch", "feature/two"]);
+ repo.run_git(&["branch", "hotfix/bug"]);
// Complete with partial prefix - shell does prefix filtering, we return all branches
let mut settings = Settings::clone_current();
@@ -377,53 +336,28 @@ fn test_complete_excludes_remote_branches(repo: TestRepo) {
repo.commit("initial");
// Create local branches
- Command::new("git")
- .args(["branch", "feature/local"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature/local"]);
// Set up a fake remote
- Command::new("git")
- .args(["remote", "add", "origin", "https://example.com/repo.git"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["remote", "add", "origin", "https://example.com/repo.git"]);
// Create a remote-tracking branch by fetching from a local "remote"
// First, create a bare repo to act as remote
let remote_dir = repo.root_path().parent().unwrap().join("remote.git");
- Command::new("git")
+ repo.git_command()
.args(["init", "--bare", remote_dir.to_str().unwrap()])
.output()
.unwrap();
// Update remote URL to point to our bare repo
- Command::new("git")
- .args(["remote", "set-url", "origin", remote_dir.to_str().unwrap()])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["remote", "set-url", "origin", remote_dir.to_str().unwrap()]);
// Push to create remote branches
- Command::new("git")
- .args(["push", "origin", "main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["push", "origin", "feature/local:feature/remote"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["push", "origin", "main"]);
+ repo.run_git(&["push", "origin", "feature/local:feature/remote"]);
// Fetch to create remote-tracking branches
- Command::new("git")
- .args(["fetch", "origin"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["fetch", "origin"]);
// Test completion
let output = repo.completion_cmd(&["wt", "switch", ""]).output().unwrap();
@@ -457,11 +391,7 @@ fn test_complete_merge_shows_branches(mut repo: TestRepo) {
repo.add_worktree("feature/new");
// Create another branch without worktree
- Command::new("git")
- .args(["branch", "hotfix/bug"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "hotfix/bug"]);
// Test completion for merge (should show ALL branches, including those with worktrees)
let output = repo.completion_cmd(&["wt", "merge", ""]).output().unwrap();
@@ -488,11 +418,7 @@ fn test_complete_with_special_characters_in_branch_names(repo: TestRepo) {
];
for branch in &branch_names {
- Command::new("git")
- .args(["branch", branch])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", branch]);
}
// Test completion
@@ -517,17 +443,8 @@ fn test_complete_stops_after_branch_provided(repo: TestRepo) {
repo.commit("initial");
// Create branches
- Command::new("git")
- .args(["branch", "feature/one"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["branch", "feature/two"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature/one"]);
+ repo.run_git(&["branch", "feature/two"]);
// Test that switch stops completing after branch is provided
let mut settings = Settings::clone_current();
@@ -582,11 +499,7 @@ fn test_complete_stops_after_branch_provided(repo: TestRepo) {
fn test_complete_switch_with_create_flag_no_completion(repo: TestRepo) {
repo.commit("initial");
- Command::new("git")
- .args(["branch", "feature/existing"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature/existing"]);
// Test with --create flag (long form)
let mut settings = Settings::clone_current();
@@ -626,11 +539,7 @@ fn test_complete_switch_base_flag_after_branch(repo: TestRepo) {
repo.commit("initial");
// Create branches
- Command::new("git")
- .args(["branch", "develop"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "develop"]);
// Test completion for --base even after --create and branch name
let output = repo
@@ -653,11 +562,7 @@ fn test_complete_remove_excludes_remote_only_branches(mut repo: TestRepo) {
repo.add_worktree("feature/new");
// Create another local branch without worktree
- Command::new("git")
- .args(["branch", "hotfix/bug"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "hotfix/bug"]);
// Test completion for remove (should show local branches, exclude remote-only)
let output = repo.completion_cmd(&["wt", "remove", ""]).output().unwrap();
@@ -812,11 +717,7 @@ fn test_complete_list_format_flag(repo: TestRepo) {
fn test_complete_switch_execute_all_formats(repo: TestRepo) {
repo.commit("initial");
- Command::new("git")
- .args(["branch", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature"]);
// Test all execute flag formats: --execute with space, --execute=, -xvalue
// All should complete branches after the execute value is provided
@@ -850,11 +751,7 @@ fn test_complete_switch_execute_all_formats(repo: TestRepo) {
fn test_complete_switch_with_double_dash_terminator(repo: TestRepo) {
repo.commit("initial");
- Command::new("git")
- .args(["branch", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature"]);
// Test: wt switch -- <cursor>
// After --, everything is positional, should complete branches
@@ -874,11 +771,7 @@ fn test_complete_switch_with_double_dash_terminator(repo: TestRepo) {
fn test_complete_switch_positional_already_provided(repo: TestRepo) {
repo.commit("initial");
- Command::new("git")
- .args(["branch", "existing"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "existing"]);
// Test: wt switch existing <cursor>
// Positional already provided, should NOT complete branches
@@ -899,11 +792,7 @@ fn test_complete_switch_positional_already_provided(repo: TestRepo) {
fn test_complete_switch_completing_execute_value(repo: TestRepo) {
repo.commit("initial");
- Command::new("git")
- .args(["branch", "develop"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "develop"]);
// Test: wt switch --execute <cursor>
// Currently typing the value for --execute, should NOT complete branches
@@ -922,11 +811,7 @@ fn test_complete_switch_completing_execute_value(repo: TestRepo) {
fn test_complete_merge_with_flags(repo: TestRepo) {
repo.commit("initial");
- Command::new("git")
- .args(["branch", "hotfix"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "hotfix"]);
// Test: wt merge --no-remove --yes <cursor>
// Should complete branches for positional (boolean flags don't consume arguments)
@@ -947,17 +832,8 @@ fn test_complete_switch_base_after_execute_equals(repo: TestRepo) {
repo.commit("initial");
// Create branches
- Command::new("git")
- .args(["branch", "develop"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["branch", "production"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "develop"]);
+ repo.run_git(&["branch", "production"]);
// Test: wt switch --create --execute=claude --base <cursor>
// This is the reported failing case - should complete branches for --base
@@ -989,11 +865,7 @@ fn test_complete_switch_base_after_execute_equals(repo: TestRepo) {
fn test_complete_switch_flexible_argument_ordering(repo: TestRepo) {
repo.commit("initial");
- Command::new("git")
- .args(["branch", "develop"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "develop"]);
// Test that .last(true) allows positional before flags
// wt switch feature --base <cursor>
@@ -1048,11 +920,7 @@ fn test_complete_remove_flexible_argument_ordering(mut repo: TestRepo) {
fn test_complete_filters_options_when_positionals_exist(repo: TestRepo) {
repo.commit("initial");
- Command::new("git")
- .args(["branch", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature"]);
// Test: wt switch <cursor>
// Should show branches but NOT options like --config, --verbose, -C
@@ -1110,17 +978,8 @@ fn test_complete_switch_option_prefix_shows_options_not_branches(repo: TestRepo)
repo.commit("initial");
// Create branches that happen to contain "-c" in the name
- Command::new("git")
- .args(["branch", "fish-switch-complete"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["branch", "zsh-bash-complete"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "fish-switch-complete"]);
+ repo.run_git(&["branch", "zsh-bash-complete"]);
// Test: wt switch --c<cursor>
// Should show options starting with --c (like --create), NOT branches containing "-c"
@@ -1153,11 +1012,7 @@ fn test_complete_switch_single_dash_shows_options_not_branches(repo: TestRepo) {
repo.commit("initial");
// Create a branch that contains "-" in the name
- Command::new("git")
- .args(["branch", "feature-branch"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature-branch"]);
// Test: wt switch -<cursor>
// Should show short options, NOT branches containing "-"
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 571408d9c..4b53790fc 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -149,17 +149,18 @@ fn setup_timestamped_worktrees(repo: &mut TestRepo) -> std::path::PathBuf {
)
.unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.env("GIT_AUTHOR_DATE", time);
- cmd.env("GIT_COMMITTER_DATE", time);
- cmd.args(["add", "."]).current_dir(path).output().unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.env("GIT_AUTHOR_DATE", time);
- cmd.env("GIT_COMMITTER_DATE", time);
- cmd.args(["commit", "-m", &format!("Commit at {}", time_short)])
+ repo.git_command()
+ .env("GIT_AUTHOR_DATE", time)
+ .env("GIT_COMMITTER_DATE", time)
+ .args(["add", "."])
+ .current_dir(path)
+ .output()
+ .unwrap();
+
+ repo.git_command()
+ .env("GIT_AUTHOR_DATE", time)
+ .env("GIT_COMMITTER_DATE", time)
+ .args(["commit", "-m", &format!("Commit at {}", time_short)])
.current_dir(path)
.output()
.unwrap();
@@ -354,26 +355,14 @@ fn test_list_json_tree_matches_main_after_merge(mut repo: TestRepo) {
// Make the same commit on main (so trees will match after merge)
std::fs::write(repo.root_path().join("feature.txt"), "feature content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Same content on main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "."]);
+ repo.run_git(&["commit", "-m", "Same content on main"]);
// Merge main into feature (creates merge commit, but tree matches main)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["merge", "main", "-m", "Merge main into feature"])
- .current_dir(&feature_path)
- .output()
- .unwrap();
+ repo.run_git_in(
+ &feature_path,
+ &["merge", "main", "-m", "Merge main into feature"],
+ );
// Now feature-merged is ahead of main (has merge commit) but tree content matches main
// JSON output should show branch_op_state: "TreesMatch" with ahead > 0
@@ -421,12 +410,7 @@ fn test_list_with_remotes_flag(#[from(repo_with_remote)] repo: TestRepo) {
repo.push_branch("remote-feature-2");
// Delete the local branches - now they only exist as origin/remote-feature-*
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "-D", "remote-feature-1", "remote-feature-2"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "-D", "remote-feature-1", "remote-feature-2"]);
// Should show:
// - main worktree (primary)
@@ -447,12 +431,7 @@ fn test_list_with_remotes_and_branches(#[from(repo_with_remote)] repo: TestRepo)
repo.create_branch("remote-only-2");
repo.push_branch("remote-only-1");
repo.push_branch("remote-only-2");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "-D", "remote-only-1", "remote-only-2"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "-D", "remote-only-1", "remote-only-2"]);
// Should show:
// - main worktree
@@ -468,22 +447,15 @@ fn test_list_with_remotes_filters_tracked_worktrees(#[from(repo_with_remote)] mu
// Create a worktree and push with tracking
repo.add_worktree("feature-with-worktree");
let feature_path = repo.worktree_path("feature-with-worktree");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["push", "-u", "origin", "feature-with-worktree"])
- .current_dir(feature_path)
- .output()
- .unwrap();
+ repo.run_git_in(
+ feature_path,
+ &["push", "-u", "origin", "feature-with-worktree"],
+ );
// Create a branch, push it, delete it locally (remote-only)
repo.create_branch("remote-only");
repo.push_branch("remote-only");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "-D", "remote-only"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "-D", "remote-only"]);
// Should show:
// - main worktree
@@ -497,22 +469,12 @@ fn test_list_with_remotes_filters_tracked_worktrees(#[from(repo_with_remote)] mu
fn test_list_with_remotes_filters_tracked_branches(#[from(repo_with_remote)] repo: TestRepo) {
// Create a local branch (no worktree) and push with tracking
repo.create_branch("tracked-branch");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["push", "-u", "origin", "tracked-branch"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["push", "-u", "origin", "tracked-branch"]);
// Create a branch, push it, then delete locally (remote-only)
repo.create_branch("remote-only");
repo.push_branch("remote-only");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "-D", "remote-only"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "-D", "remote-only"]);
// Should show:
// - main worktree
@@ -532,27 +494,12 @@ fn test_list_json_with_display_fields(mut repo: TestRepo) {
// Make commits in the feature worktree
let feature_path = repo.worktree_path("feature-ahead");
std::fs::write(feature_path.join("feature.txt"), "feature content").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(feature_path)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Feature commit 1"])
- .current_dir(feature_path)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "--allow-empty", "-m", "Feature commit 2"])
- .current_dir(feature_path)
- .output()
- .unwrap();
+ repo.run_git_in(feature_path, &["add", "."]);
+ repo.run_git_in(feature_path, &["commit", "-m", "Feature commit 1"]);
+ repo.run_git_in(
+ feature_path,
+ &["commit", "--allow-empty", "-m", "Feature commit 2"],
+ );
// Add uncommitted changes to show working_diff_display
std::fs::write(feature_path.join("uncommitted.txt"), "uncommitted").unwrap();
@@ -585,121 +532,41 @@ fn test_list_with_upstream_tracking(mut repo: TestRepo) {
// Scenario 1: Branch in sync with remote (should show ↑0 ↓0)
let in_sync_wt = repo.add_worktree("in-sync");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["push", "-u", "origin", "in-sync"])
- .current_dir(&in_sync_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&in_sync_wt, &["push", "-u", "origin", "in-sync"]);
// Scenario 2: Branch ahead of remote (should show ↑2)
let ahead_wt = repo.add_worktree("ahead");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["push", "-u", "origin", "ahead"])
- .current_dir(&ahead_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&ahead_wt, &["push", "-u", "origin", "ahead"]);
// Make 2 commits ahead
std::fs::write(ahead_wt.join("ahead1.txt"), "ahead 1").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&ahead_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Ahead commit 1"])
- .current_dir(&ahead_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&ahead_wt, &["add", "."]);
+ repo.run_git_in(&ahead_wt, &["commit", "-m", "Ahead commit 1"]);
std::fs::write(ahead_wt.join("ahead2.txt"), "ahead 2").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&ahead_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Ahead commit 2"])
- .current_dir(&ahead_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&ahead_wt, &["add", "."]);
+ repo.run_git_in(&ahead_wt, &["commit", "-m", "Ahead commit 2"]);
// Scenario 3: Branch behind remote (should show ↓1)
let behind_wt = repo.add_worktree("behind");
std::fs::write(behind_wt.join("behind.txt"), "behind").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&behind_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Behind commit"])
- .current_dir(&behind_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["push", "-u", "origin", "behind"])
- .current_dir(&behind_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&behind_wt, &["add", "."]);
+ repo.run_git_in(&behind_wt, &["commit", "-m", "Behind commit"]);
+ repo.run_git_in(&behind_wt, &["push", "-u", "origin", "behind"]);
// Reset local to one commit behind
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["reset", "--hard", "HEAD~1"])
- .current_dir(&behind_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&behind_wt, &["reset", "--hard", "HEAD~1"]);
// Scenario 4: Branch both ahead and behind (should show ↑1 ↓1)
let diverged_wt = repo.add_worktree("diverged");
std::fs::write(diverged_wt.join("diverged.txt"), "diverged").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&diverged_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Diverged remote commit"])
- .current_dir(&diverged_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["push", "-u", "origin", "diverged"])
- .current_dir(&diverged_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&diverged_wt, &["add", "."]);
+ repo.run_git_in(&diverged_wt, &["commit", "-m", "Diverged remote commit"]);
+ repo.run_git_in(&diverged_wt, &["push", "-u", "origin", "diverged"]);
// Reset and make different commit
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["reset", "--hard", "HEAD~1"])
- .current_dir(&diverged_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&diverged_wt, &["reset", "--hard", "HEAD~1"]);
std::fs::write(diverged_wt.join("different.txt"), "different").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&diverged_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Diverged local commit"])
- .current_dir(&diverged_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&diverged_wt, &["add", "."]);
+ repo.run_git_in(&diverged_wt, &["commit", "-m", "Diverged local commit"]);
// Scenario 5: Branch without upstream (should show blank)
let no_upstream_wt = repo.add_worktree("no-upstream");
@@ -707,12 +574,7 @@ fn test_list_with_upstream_tracking(mut repo: TestRepo) {
// Run git status to ensure the worktree is fully initialized on Windows.
// Without this, Windows CI may show 55y (Unix epoch) because the worktree
// isn't ready when wt list tries to read commit timestamps.
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["status", "--porcelain"])
- .current_dir(&no_upstream_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&no_upstream_wt, &["status", "--porcelain"]);
// Run list --branches --full to show all columns including Remote
let settings = setup_snapshot_settings(&repo);
@@ -815,25 +677,14 @@ fn test_list_json_with_git_operation(mut repo: TestRepo) {
"main line 1\nmain line 2\n",
)
.unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Main conflicting changes"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "."]);
+ repo.run_git(&["commit", "-m", "Main conflicting changes"]);
// Start rebase which will create conflicts and git operation state
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let rebase_output = cmd
- .args(["rebase", "main"])
+ let rebase_output = repo
+ .git_command()
.current_dir(&feature)
+ .args(["rebase", "main"])
.output()
.unwrap();
@@ -852,12 +703,7 @@ fn test_list_branch_only_with_status(repo: TestRepo) {
// Test that branch-only entries (no worktree) can display branch-keyed status
// Create a branch-only entry (no worktree)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "branch-only"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "branch-only"]);
// Set branch-keyed status for the branch-only entry
repo.set_marker("branch-only", "🌿");
@@ -952,15 +798,15 @@ pub mod handlers {
"#,
)
.unwrap();
- run_git(repo, &["add", "api.rs"], repo.root_path());
+ repo.run_git(&["add", "api.rs"]);
repo.commit_staged_with_age("Initial API implementation", DAY, repo.root_path());
repo.setup_remote("main");
// Make main behind its remote: push a teammate's commit, then reset local
// Story: A teammate pushed a hotfix while we were working on features
repo.commit_with_age("Fix production timeout issue", 2 * HOUR);
- run_git(repo, &["push", "origin", "main"], repo.root_path());
- run_git(repo, &["reset", "--hard", "HEAD~1"], repo.root_path());
+ repo.run_git(&["push", "origin", "main"]);
+ repo.run_git(&["reset", "--hard", "HEAD~1"]);
// === Create fix-auth worktree ===
// Story: Security audit found the token validation was too weak.
@@ -1005,7 +851,7 @@ pub mod handlers {
"#,
)
.unwrap();
- run_git(repo, &["add", "api.rs"], &fix_auth);
+ repo.run_git_in(&fix_auth, &["add", "api.rs"]);
repo.commit_staged_with_age("Harden token validation", 6 * HOUR, &fix_auth);
// Second commit: Add secure token storage
@@ -1054,11 +900,11 @@ pub mod handlers {
"#,
)
.unwrap();
- run_git(repo, &["add", "api.rs"], &fix_auth);
+ repo.run_git_in(&fix_auth, &["add", "api.rs"]);
repo.commit_staged_with_age("Add secure token storage", 5 * HOUR, &fix_auth);
// Push fix-auth and sync with remote
- run_git(repo, &["push", "-u", "origin", "fix-auth"], &fix_auth);
+ repo.run_git_in(&fix_auth, &["push", "-u", "origin", "fix-auth"]);
// === Create feature-api worktree ===
// Story: Major API refactoring - replacing the legacy handlers with a proper
@@ -1187,9 +1033,9 @@ pub enum Method { Get, Post, Put, Delete }
"#,
)
.unwrap();
- run_git(repo, &["add", "api.rs", "routes.rs"], &feature_api);
+ repo.run_git_in(&feature_api, &["add", "api.rs", "routes.rs"]);
repo.commit_staged_with_age("Refactor API to REST modules", 4 * HOUR, &feature_api);
- run_git(repo, &["push", "-u", "origin", "feature-api"], &feature_api);
+ repo.run_git_in(&feature_api, &["push", "-u", "origin", "feature-api"]);
// More commits (ahead of remote - unpushed local work)
std::fs::write(
@@ -1304,7 +1150,7 @@ pub enum AuthError { MissingToken, InvalidToken }
"#,
)
.unwrap();
- run_git(repo, &["add", "middleware.rs"], &feature_api);
+ repo.run_git_in(&feature_api, &["add", "middleware.rs"]);
repo.commit_staged_with_age("Add request middleware", 3 * HOUR, &feature_api);
std::fs::write(
@@ -1319,7 +1165,7 @@ pub fn validate(body: &[u8], headers: &Headers) -> Result<(), Error> {
"#,
)
.unwrap();
- run_git(repo, &["add", "validation.rs"], &feature_api);
+ repo.run_git_in(&feature_api, &["add", "validation.rs"]);
repo.commit_staged_with_age("Add request validation", 2 * HOUR, &feature_api);
std::fs::write(
@@ -1340,7 +1186,7 @@ mod tests {
"#,
)
.unwrap();
- run_git(repo, &["add", "tests.rs"], &feature_api);
+ repo.run_git_in(&feature_api, &["add", "tests.rs"]);
repo.commit_staged_with_age("Add API tests", 30 * MINUTE, &feature_api);
// Staged changes: new files + refactor existing (creates mixed +/- for HEAD±)
@@ -1417,10 +1263,9 @@ fn validate_headers(h: &Headers) -> Result<(), ValidationError> {
"#,
)
.unwrap();
- run_git(
- repo,
- &["add", "cache.rs", "rate_limit.rs", "validation.rs"],
+ repo.run_git_in(
&feature_api,
+ &["add", "cache.rs", "rate_limit.rs", "validation.rs"],
);
// === Create branches without worktrees ===
@@ -1430,11 +1275,7 @@ fn validate_headers(h: &Headers) -> Result<(), ValidationError> {
// Narrative: Someone explored GraphQL as an alternative to REST, got pretty far with
// schema design and resolvers, but the team decided to stick with REST for now.
let exp_wt = repo.root_path().parent().unwrap().join("temp-exp");
- run_git(
- repo,
- &["worktree", "add", "-b", "exp", exp_wt.to_str().unwrap()],
- repo.root_path(),
- );
+ repo.run_git(&["worktree", "add", "-b", "exp", exp_wt.to_str().unwrap()]);
std::fs::write(
exp_wt.join("graphql.rs"),
@@ -1506,7 +1347,7 @@ pub struct PageInfo {
"#,
)
.unwrap();
- run_git(repo, &["add", "graphql.rs"], &exp_wt);
+ repo.run_git_in(&exp_wt, &["add", "graphql.rs"]);
repo.commit_staged_with_age("Explore GraphQL schema design", 2 * DAY, &exp_wt);
std::fs::write(
@@ -1586,15 +1427,11 @@ impl SubscriptionRoot {
"#,
)
.unwrap();
- run_git(repo, &["add", "resolvers.rs"], &exp_wt);
+ repo.run_git_in(&exp_wt, &["add", "resolvers.rs"]);
repo.commit_staged_with_age("Add GraphQL resolvers scaffold", 2 * DAY, &exp_wt);
// Remove the worktree but keep the branch
- run_git(
- repo,
- &["worktree", "remove", exp_wt.to_str().unwrap()],
- repo.root_path(),
- );
+ repo.run_git(&["worktree", "remove", exp_wt.to_str().unwrap()]);
// Create 'wip' branch with commits (work-in-progress docs)
// Narrative: Someone started API docs last week. Main has since advanced
@@ -1602,9 +1439,9 @@ impl SubscriptionRoot {
// Save current main commit, then add a commit to main (simulating fix-auth merge)
let wip_base = {
- let output = std::process::Command::new("git")
+ let output = repo
+ .git_command()
.args(["rev-parse", "HEAD"])
- .current_dir(repo.root_path())
.output()
.unwrap();
String::from_utf8_lossy(&output.stdout).trim().to_string()
@@ -1615,18 +1452,14 @@ impl SubscriptionRoot {
// Create wip from the earlier commit (before main advanced)
let wip_wt = repo.root_path().parent().unwrap().join("temp-wip");
- run_git(
- repo,
- &[
- "worktree",
- "add",
- "-b",
- "wip",
- wip_wt.to_str().unwrap(),
- &wip_base,
- ],
- repo.root_path(),
- );
+ repo.run_git(&[
+ "worktree",
+ "add",
+ "-b",
+ "wip",
+ wip_wt.to_str().unwrap(),
+ &wip_base,
+ ]);
std::fs::write(
wip_wt.join("API.md"),
@@ -1666,15 +1499,11 @@ TODO: Add request/response examples for each endpoint
"#,
)
.unwrap();
- run_git(repo, &["add", "API.md"], &wip_wt);
+ repo.run_git_in(&wip_wt, &["add", "API.md"]);
repo.commit_staged_with_age("Start API documentation", 3 * DAY, &wip_wt);
// Remove the worktree but keep the branch
- run_git(
- repo,
- &["worktree", "remove", wip_wt.to_str().unwrap()],
- repo.root_path(),
- );
+ repo.run_git(&["worktree", "remove", wip_wt.to_str().unwrap()]);
// === Mock CI status ===
// CI requires --full flag, but we mock it so examples show realistic output
@@ -1687,21 +1516,12 @@ TODO: Add request/response examples for each endpoint
feature_api
}
-/// Helper to run git commands
-fn run_git(repo: &TestRepo, args: &[&str], cwd: &std::path::Path) {
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(args).current_dir(cwd).output().unwrap();
-}
-
/// Mock CI status by writing to file-based cache
fn mock_ci_status(repo: &TestRepo, branch: &str, status: &str, source: &str, is_stale: bool) {
// Get HEAD commit for the branch
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
+ let output = repo
+ .git_command()
.args(["rev-parse", branch])
- .current_dir(repo.root_path())
.output()
.unwrap();
let head = String::from_utf8_lossy(&output.stdout).trim().to_string();
@@ -1720,11 +1540,9 @@ fn mock_ci_status(repo: &TestRepo, branch: &str, status: &str, source: &str, is_
);
// Get git common dir for cache location
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
+ let output = repo
+ .git_command()
.args(["rev-parse", "--git-common-dir"])
- .current_dir(repo.root_path())
.output()
.unwrap();
let git_dir = String::from_utf8_lossy(&output.stdout).trim().to_string();
@@ -1882,31 +1700,14 @@ fn test_list_task_dag_with_upstream(mut repo: TestRepo) {
// Branch in sync
let in_sync = repo.add_worktree("in-sync");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["push", "-u", "origin", "in-sync"])
- .current_dir(&in_sync)
- .output()
- .unwrap();
+ repo.run_git_in(&in_sync, &["push", "-u", "origin", "in-sync"]);
// Branch ahead
let ahead = repo.add_worktree("ahead");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["push", "-u", "origin", "ahead"])
- .current_dir(&ahead)
- .output()
- .unwrap();
+ repo.run_git_in(&ahead, &["push", "-u", "origin", "ahead"]);
std::fs::write(ahead.join("ahead.txt"), "ahead").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."]).current_dir(&ahead).output().unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Ahead commit"])
- .current_dir(&ahead)
- .output()
- .unwrap();
+ repo.run_git_in(&ahead, &["add", "."]);
+ repo.run_git_in(&ahead, &["commit", "-m", "Ahead commit"]);
snapshot_list_progressive_full("task_dag_with_upstream", &repo);
}
@@ -2041,18 +1842,8 @@ fn test_list_large_diffs_alignment(mut repo: TestRepo) {
std::fs::write(large_wt.join("large.txt"), &large_content).unwrap();
// Commit it
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&large_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add 100 lines"])
- .current_dir(&large_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&large_wt, &["add", "."]);
+ repo.run_git_in(&large_wt, &["commit", "-m", "Add 100 lines"]);
// Add large uncommitted changes (both added and deleted lines)
// Add a new file with many lines
@@ -2091,18 +1882,8 @@ fn test_list_large_diffs_alignment(mut repo: TestRepo) {
.collect::<Vec<_>>()
.join("\n");
std::fs::write(diverged_wt.join("test.txt"), &diverged_content).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&diverged_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Diverged commit"])
- .current_dir(&diverged_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&diverged_wt, &["add", "."]);
+ repo.run_git_in(&diverged_wt, &["commit", "-m", "Diverged commit"]);
// Add uncommitted changes
let modified_diverged = (1..=40)
@@ -2130,19 +1911,8 @@ fn test_list_status_column_padding_with_emoji(mut repo: TestRepo) {
.join("\n");
std::fs::write(wli_seq.join("main.txt"), &initial_content).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&wli_seq)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Initial content"])
- .current_dir(&wli_seq)
- .output()
- .unwrap();
+ repo.run_git_in(&wli_seq, &["add", "."]);
+ repo.run_git_in(&wli_seq, &["commit", "-m", "Initial content"]);
// Modify to create desired diff: remove ~111 lines, add different content
let modified_content = (1..=89)
@@ -2166,18 +1936,8 @@ fn test_list_status_column_padding_with_emoji(mut repo: TestRepo) {
// Commit to make it ahead
std::fs::write(pr_link.join("pr.txt"), "pr content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&pr_link)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "PR commit"])
- .current_dir(&pr_link)
- .output()
- .unwrap();
+ repo.run_git_in(&pr_link, &["add", "."]);
+ repo.run_git_in(&pr_link, &["commit", "-m", "PR commit"]);
// Set same emoji type
repo.set_marker("pr-link", "🤖");
@@ -2185,18 +1945,8 @@ fn test_list_status_column_padding_with_emoji(mut repo: TestRepo) {
// Create "main-symbol" with different emoji
let main_sym = repo.add_worktree("main-symbol");
std::fs::write(main_sym.join("sym.txt"), "symbol").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&main_sym)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Symbol commit"])
- .current_dir(&main_sym)
- .output()
- .unwrap();
+ repo.run_git_in(&main_sym, &["add", "."]);
+ repo.run_git_in(&main_sym, &["commit", "-m", "Symbol commit"]);
repo.set_marker("main-symbol", "💬");
@@ -2217,19 +1967,8 @@ fn test_list_maximum_working_tree_symbols(mut repo: TestRepo) {
std::fs::write(feature.join("file-c.txt"), "original c").unwrap();
std::fs::write(feature.join("file-d.txt"), "original d").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&feature)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add files"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["add", "."]);
+ repo.run_git_in(&feature, &["commit", "-m", "Add files"]);
// 1. Create untracked file (?)
std::fs::write(feature.join("untracked.txt"), "new file").unwrap();
@@ -2239,28 +1978,13 @@ fn test_list_maximum_working_tree_symbols(mut repo: TestRepo) {
// 3. Stage some changes (+)
std::fs::write(feature.join("file-b.txt"), "staged changes").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "file-b.txt"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["add", "file-b.txt"]);
// 4. Rename a file and stage it (»)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["mv", "file-c.txt", "renamed-c.txt"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["mv", "file-c.txt", "renamed-c.txt"]);
// 5. Delete a file in index (✘)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["rm", "file-d.txt"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["rm", "file-d.txt"]);
// Result should show: ?!+»✘
snapshot_list("maximum_working_tree_symbols", &repo);
@@ -2291,18 +2015,8 @@ fn test_list_maximum_status_with_git_operation(mut repo: TestRepo) {
)
.unwrap();
std::fs::write(feature.join("feature.txt"), "feature-specific content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&feature)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Feature changes"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["add", "."]);
+ repo.run_git_in(&feature, &["commit", "-m", "Feature changes"]);
// Main makes conflicting changes
std::fs::write(
@@ -2311,23 +2025,12 @@ fn test_list_maximum_status_with_git_operation(mut repo: TestRepo) {
)
.unwrap();
std::fs::write(repo.root_path().join("main-only.txt"), "main content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Main conflicting changes"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "."]);
+ repo.run_git(&["commit", "-m", "Main conflicting changes"]);
// Start rebase which will create conflicts and git operation state
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let rebase_output = cmd
+ let rebase_output = repo
+ .git_command()
.args(["rebase", "main"])
.current_dir(&feature)
.output()
@@ -2348,20 +2051,10 @@ fn test_list_maximum_status_with_git_operation(mut repo: TestRepo) {
// 3. Staged file (+) - stage the conflict resolution
std::fs::write(feature.join("new-staged.txt"), "staged during rebase").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "new-staged.txt"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["add", "new-staged.txt"]);
// Lock the worktree (⊠)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["worktree", "lock", feature.to_str().unwrap()])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["worktree", "lock", feature.to_str().unwrap()]);
// Set user marker emoji (🤖)
repo.set_marker("feature", "🤖");
@@ -2396,18 +2089,8 @@ fn test_list_maximum_status_symbols(mut repo: TestRepo) {
// Make feature diverge from main (ahead) with conflicting change
std::fs::write(feature.join("shared.txt"), "feature version").unwrap();
std::fs::write(feature.join("feature.txt"), "feature content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&feature)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Feature work"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["add", "."]);
+ repo.run_git_in(&feature, &["commit", "-m", "Feature work"]);
// Create a real bare remote so upstream exists, but keep all graph crafting local for determinism
repo.setup_remote("main");
@@ -2480,18 +2163,8 @@ fn test_list_maximum_status_symbols(mut repo: TestRepo) {
// Make main advance with conflicting change (so feature is behind with conflicts)
std::fs::write(repo.root_path().join("shared.txt"), "main version").unwrap();
std::fs::write(repo.root_path().join("main2.txt"), "more main").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Main advances"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "."]);
+ repo.run_git(&["commit", "-m", "Main advances"]);
// Add all 5 working tree symbol types (without rebase, so we keep divergence)
// 1. Untracked (?)
@@ -2502,36 +2175,16 @@ fn test_list_maximum_status_symbols(mut repo: TestRepo) {
// 3. Staged (+)
std::fs::write(feature.join("new-staged.txt"), "staged content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "new-staged.txt"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["add", "new-staged.txt"]);
// 4. Renamed (»)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["mv", "file-c.txt", "renamed-c.txt"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["mv", "file-c.txt", "renamed-c.txt"]);
// 5. Deleted (✘)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["rm", "file-d.txt"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["rm", "file-d.txt"]);
// Lock the worktree (⊠)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["worktree", "lock", feature.to_str().unwrap()])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["worktree", "lock", feature.to_str().unwrap()]);
// Set user marker emoji (🤖)
repo.set_marker("feature", "🤖");
@@ -2595,18 +2248,8 @@ fn test_list_full_clean_working_tree_uses_commit_conflicts(mut repo: TestRepo) {
// Make a conflicting commit on feature (different change to shared.txt)
std::fs::write(feature.join("shared.txt"), "feature's committed version").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "."])
- .current_dir(&feature)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Feature changes shared.txt"])
- .current_dir(&feature)
- .output()
- .unwrap();
+ repo.run_git_in(&feature, &["add", "."]);
+ repo.run_git_in(&feature, &["commit", "-m", "Feature changes shared.txt"]);
// Advance main with a different change to the shared file
std::fs::write(repo.root_path().join("shared.txt"), "main's version").unwrap();
diff --git a/tests/integration_tests/list_column_alignment.rs b/tests/integration_tests/list_column_alignment.rs
index 6d8019585..459e108f4 100644
--- a/tests/integration_tests/list_column_alignment.rs
+++ b/tests/integration_tests/list_column_alignment.rs
@@ -35,12 +35,7 @@ fn test_status_column_width_consistency(mut repo: TestRepo) {
std::fs::write(wt1.join("new.txt"), "new").unwrap(); // Just untracked (?)
std::fs::write(wt2.join("new1.txt"), "new").unwrap(); // Multiple: ?, !, +
std::fs::write(wt2.join("file.txt"), "modified").unwrap();
- let mut cmd = std::process::Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "file.txt"])
- .current_dir(&wt2)
- .output()
- .unwrap();
+ repo.run_git_in(&wt2, &["add", "file.txt"]);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
diff --git a/tests/integration_tests/list_config.rs b/tests/integration_tests/list_config.rs
index b590f4ad8..09ec78c8d 100644
--- a/tests/integration_tests/list_config.rs
+++ b/tests/integration_tests/list_config.rs
@@ -39,12 +39,7 @@ full = true
#[rstest]
fn test_list_config_branches_enabled(repo: TestRepo, temp_home: TempDir) {
// Create a branch without a worktree
- let mut cmd = std::process::Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature"]);
// Create user config with list.branches = true
let global_config_dir = temp_home.path().join(".config").join("worktrunk");
@@ -74,12 +69,7 @@ branches = true
#[rstest]
fn test_list_config_cli_override(repo: TestRepo, temp_home: TempDir) {
// Create a branch without a worktree
- let mut cmd = std::process::Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature"]);
// Create user config with list.branches = false (default)
let global_config_dir = temp_home.path().join(".config").join("worktrunk");
@@ -112,12 +102,7 @@ branches = false
#[rstest]
fn test_list_config_full_and_branches(repo: TestRepo, temp_home: TempDir) {
// Create a branch without a worktree
- let mut cmd = std::process::Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature"]);
// Create user config with both full and branches enabled
let global_config_dir = temp_home.path().join(".config").join("worktrunk");
@@ -148,12 +133,7 @@ branches = true
#[rstest]
fn test_list_no_config(repo: TestRepo, temp_home: TempDir) {
// Create a branch without a worktree
- let mut cmd = std::process::Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature"]);
// Create minimal user config without list settings
let global_config_dir = temp_home.path().join(".config").join("worktrunk");
@@ -292,12 +272,7 @@ fn test_list_json_no_url_without_template(repo: TestRepo, temp_home: TempDir) {
#[rstest]
fn test_list_url_with_branches_flag(repo: TestRepo, temp_home: TempDir) {
// Create a branch without a worktree
- let mut cmd = std::process::Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature"]);
// Create project config with URL template
repo.write_project_config(
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index c477253c4..23019dd5c 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -7,7 +7,6 @@ use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
use std::fs;
use std::path::{Path, PathBuf};
-use std::process::Command;
/// Helper to create snapshot with normalized paths
fn snapshot_merge(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&Path>) {
@@ -108,19 +107,8 @@ fn test_merge_not_fast_forward(mut repo: TestRepo) {
// Add commit to main (repo root)
std::fs::write(repo.root_path().join("main.txt"), "main content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "main.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add main file"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "main.txt"]);
+ repo.run_git(&["commit", "-m", "Add main file"]);
// Create a feature worktree branching from before the main commit
let feature_wt = repo.add_feature();
@@ -140,66 +128,37 @@ fn test_merge_not_fast_forward(mut repo: TestRepo) {
#[rstest]
fn test_merge_no_commit_not_fast_forward(repo: TestRepo) {
// Get the initial commit SHA to create feature branch from there
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let initial_sha = cmd
- .args(["rev-parse", "HEAD"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let initial_sha = String::from_utf8_lossy(&initial_sha.stdout)
- .trim()
- .to_string();
+ let initial_sha = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["rev-parse", "HEAD"])
+ .output()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
// Add commit to main (this advances main beyond the initial commit)
std::fs::write(repo.root_path().join("main.txt"), "main content").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "main.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add main file"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "main.txt"]);
+ repo.run_git(&["commit", "-m", "Add main file"]);
// Create feature worktree from the INITIAL commit (before main advanced)
let feature_path = repo.root_path().parent().unwrap().join("feature");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args([
+ repo.run_git(&[
"worktree",
"add",
"-b",
"feature",
feature_path.to_str().unwrap(),
&initial_sha,
- ])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ ]);
// Add a commit on feature branch
std::fs::write(feature_path.join("feature.txt"), "feature content").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "feature.txt"])
- .current_dir(&feature_path)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add feature file"])
- .current_dir(&feature_path)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_path, &["add", "feature.txt"]);
+ repo.run_git_in(&feature_path, &["commit", "-m", "Add feature file"]);
// Try to merge with --no-commit --no-remove (skips rebase, so push fails with not-fast-forward)
// Main has "Add main file" commit that feature doesn't have as ancestor
@@ -215,75 +174,44 @@ fn test_merge_no_commit_not_fast_forward(repo: TestRepo) {
fn test_merge_rebase_conflict(repo: TestRepo) {
// Create a shared file
std::fs::write(repo.root_path().join("shared.txt"), "initial content\n").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "shared.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
+ repo.run_git(&["add", "shared.txt"]);
repo.commit("Add shared file");
// Modify shared.txt in main branch (from the base commit)
std::fs::write(repo.root_path().join("shared.txt"), "main version\n").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "shared.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Update shared.txt in main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "shared.txt"]);
+ repo.run_git(&["commit", "-m", "Update shared.txt in main"]);
// Create a feature worktree branching from before the main commit
// We need to create it from the original commit, not current main
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
- .args(["rev-parse", "HEAD~1"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let base_commit = String::from_utf8_lossy(&output.stdout).trim().to_string();
+ let base_commit = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["rev-parse", "HEAD~1"])
+ .output()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
let feature_wt = repo.root_path().parent().unwrap().join("repo.feature");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args([
+ repo.run_git(&[
"worktree",
"add",
feature_wt.to_str().unwrap(),
"-b",
"feature",
&base_commit,
- ])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ ]);
// Modify the same file with conflicting content
std::fs::write(feature_wt.join("shared.txt"), "feature version\n").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "shared.txt"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Update shared.txt in feature"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "shared.txt"]);
+ repo.run_git_in(
+ &feature_wt,
+ &["commit", "-m", "Update shared.txt in feature"],
+ );
// Try to merge - should fail with rebase conflict
snapshot_merge("merge_rebase_conflict", &repo, &["main"], Some(&feature_wt));
@@ -1009,19 +937,8 @@ pub fn refresh(refresh_token: &str) -> String {
"#;
std::fs::write(feature_wt.join("auth.rs"), auth_rs).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "auth.rs"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Implement JWT validation"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "auth.rs"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Implement JWT validation"]);
// Snapshot the merge command
snapshot_merge("readme_example_simple", &repo, &["main"], Some(&feature_wt));
@@ -1123,19 +1040,8 @@ EOF
fs::write(config_dir.join("wt.toml"), config_content).unwrap();
// Commit the config and mock cargo
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", ".config/wt.toml", ".bin"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add project automation config"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", ".config/wt.toml", ".bin"]);
+ repo.run_git(&["commit", "-m", "Add project automation config"]);
// Create a feature worktree and make multiple commits
let feature_wt = repo.add_worktree("feature-auth");
@@ -1151,18 +1057,8 @@ pub fn needs_rotation(issued_at: u64, ttl: u64, now: u64) -> bool {
}
"#;
std::fs::write(feature_wt.join("auth.rs"), commit_one).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "auth.rs"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add token refresh logic"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "auth.rs"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Add token refresh logic"]);
// Second commit: JWT validation
let commit_two = r#"// JWT validation
@@ -1175,18 +1071,8 @@ pub fn decode_claims(token: &str) -> Option<&str> {
}
"#;
std::fs::write(feature_wt.join("jwt.rs"), commit_two).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "jwt.rs"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Implement JWT validation"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "jwt.rs"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Implement JWT validation"]);
// Third commit: tests
let commit_three = r#"// Tests
@@ -1208,18 +1094,8 @@ mod tests {
}
"#;
std::fs::write(feature_wt.join("auth_test.rs"), commit_three).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "auth_test.rs"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add authentication tests"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "auth_test.rs"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Add authentication tests"]);
// Configure LLM in worktrunk config for deterministic, high-quality commit messages
let llm_path = bin_dir.join("llm");
@@ -1311,19 +1187,8 @@ fi
fs::write(config_dir.join("wt.toml"), config_content).unwrap();
// Commit the config
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", ".config/wt.toml", ".bin"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add project hooks"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", ".config/wt.toml", ".bin"]);
+ repo.run_git(&["commit", "-m", "Add project hooks"]);
// Set PATH to include mock commands and run switch --create with --yes
let path_with_bin = format!(
@@ -1435,19 +1300,8 @@ fi
fs::write(config_dir.join("wt.toml"), config_content).unwrap();
// Commit the config
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", ".config/wt.toml", ".bin"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add pre-merge hooks"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", ".config/wt.toml", ".bin"]);
+ repo.run_git(&["commit", "-m", "Add pre-merge hooks"]);
// Create a feature worktree and make multiple commits
let feature_wt = repo.add_worktree("feature-auth");
@@ -1474,18 +1328,8 @@ def login(username: str, password: str) -> Optional[Dict]:
return {'token': token, 'expires_in': 3600}
"#;
std::fs::write(feature_wt.join("api/auth.py"), auth_py_v1).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "api/auth.py"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add login endpoint"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "api/auth.py"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Add login endpoint"]);
// Second commit - add tests
fs::create_dir_all(feature_wt.join("tests")).unwrap();
@@ -1505,18 +1349,8 @@ def test_token_validation():
assert login('valid_user', 'valid_pass')['expires_in'] == 3600
"#;
std::fs::write(feature_wt.join("tests/test_auth.py"), test_auth_py).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "tests/test_auth.py"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add authentication tests"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "tests/test_auth.py"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Add authentication tests"]);
// Third commit - add refresh endpoint
let auth_py_v2 = r#"# Authentication API endpoints
@@ -1552,18 +1386,8 @@ def refresh_token(token: str) -> Optional[Dict]:
return None
"#;
std::fs::write(feature_wt.join("api/auth.py"), auth_py_v2).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "api/auth.py"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add validation"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "api/auth.py"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Add validation"]);
// Configure LLM in worktrunk config
let llm_path = bin_dir.join("llm");
@@ -1718,20 +1542,8 @@ fn test_merge_rebase_fast_forward(mut repo: TestRepo) {
// Advance main with a new commit (in the primary worktree which is on main)
fs::write(repo.root_path().join("main-update.txt"), "main content").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "main-update.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Update main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "main-update.txt"]);
+ repo.run_git(&["commit", "-m", "Update main"]);
// Merge - should fast-forward (no commits to replay)
snapshot_merge(
@@ -1757,20 +1569,8 @@ fn test_merge_rebase_true_rebase(mut repo: TestRepo) {
// Advance main with a new commit (in the primary worktree which is on main)
fs::write(repo.root_path().join("main-update.txt"), "main content").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "main-update.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Update main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "main-update.txt"]);
+ repo.run_git(&["commit", "-m", "Update main"]);
// Merge - should show rebasing progress (has commits to replay)
snapshot_merge(
@@ -1810,20 +1610,8 @@ fn test_merge_no_rebase_when_not_rebased(mut repo: TestRepo) {
// Advance main with a new commit (makes feature branch diverge)
fs::write(repo.root_path().join("main-update.txt"), "main content").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "main-update.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Update main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "main-update.txt"]);
+ repo.run_git(&["commit", "-m", "Update main"]);
// --no-rebase should fail because feature is not rebased onto main
snapshot_merge(
@@ -1862,37 +1650,21 @@ fn test_merge_primary_on_different_branch(mut repo: TestRepo) {
fn test_merge_primary_on_different_branch_dirty(mut repo: TestRepo) {
// Make main and develop diverge - modify file.txt on main
fs::write(repo.root_path().join("file.txt"), "main version").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "file.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Update file on main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "file.txt"]);
+ repo.run_git(&["commit", "-m", "Update file on main"]);
// Create a develop branch from the previous commit (before the main update)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
- .args(["rev-parse", "HEAD~1"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let base_commit = String::from_utf8_lossy(&output.stdout).trim().to_string();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["switch", "-c", "develop", &base_commit])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ let base_commit = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["rev-parse", "HEAD~1"])
+ .output()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
+ repo.run_git(&["switch", "-c", "develop", &base_commit]);
// Modify file.txt in develop (uncommitted) to a different value
// This will conflict when trying to switch to main
@@ -1932,36 +1704,20 @@ fn test_merge_race_condition_commit_after_push(mut repo_with_feature_worktree: T
// after the merge/push but before worktree removal and branch deletion.
// Since feature is already checked out in feature_wt, we'll add the commit directly there.
fs::write(feature_wt.join("extra.txt"), "race condition commit").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "extra.txt"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add extra file (race condition)"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "extra.txt"]);
+ repo.run_git_in(
+ &feature_wt,
+ &["commit", "-m", "Add extra file (race condition)"],
+ );
// Now simulate what wt merge would do: remove the worktree
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["worktree", "remove", feature_wt.to_str().unwrap()])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["worktree", "remove", feature_wt.to_str().unwrap()]);
// Try to delete the branch with -d (safe delete)
// This should FAIL because the branch has the race condition commit not in main
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
+ let output = repo
+ .git_command()
.args(["branch", "-d", "feature"])
- .current_dir(repo.root_path())
.output()
.unwrap();
@@ -1980,11 +1736,9 @@ fn test_merge_race_condition_commit_after_push(mut repo_with_feature_worktree: T
);
// Verify the branch still exists (wasn't deleted)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
+ let output = repo
+ .git_command()
.args(["branch", "--list", "feature"])
- .current_dir(repo.root_path())
.output()
.unwrap();
@@ -1998,67 +1752,35 @@ fn test_merge_race_condition_commit_after_push(mut repo_with_feature_worktree: T
#[rstest]
fn test_merge_to_non_default_target(repo: TestRepo) {
// Switch back to main and add a commit there
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["switch", "main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
+ repo.run_git(&["switch", "main"]);
std::fs::write(repo.root_path().join("main-file.txt"), "main content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "main-file.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add main-specific file"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "main-file.txt"]);
+ repo.run_git(&["commit", "-m", "Add main-specific file"]);
// Create a staging branch from BEFORE the main commit
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
- .args(["rev-parse", "HEAD~1"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let base_commit = String::from_utf8_lossy(&output.stdout).trim().to_string();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["switch", "-c", "staging", &base_commit])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ let base_commit = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["rev-parse", "HEAD~1"])
+ .output()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
+ repo.run_git(&["switch", "-c", "staging", &base_commit]);
// Add a commit to staging to make it different from main
std::fs::write(repo.root_path().join("staging-file.txt"), "staging content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "staging-file.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add staging-specific file"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "staging-file.txt"]);
+ repo.run_git(&["commit", "-m", "Add staging-specific file"]);
+
+ // Switch back to main before creating the staging worktree
+ repo.run_git(&["switch", "main"]);
// Create a worktree for staging
let staging_wt = repo.root_path().parent().unwrap().join("repo.staging-wt");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["worktree", "add", staging_wt.to_str().unwrap(), "staging"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["worktree", "add", staging_wt.to_str().unwrap(), "staging"]);
// Create a feature worktree from the base commit (before both main and staging diverged)
let feature_wt = repo
@@ -2066,35 +1788,18 @@ fn test_merge_to_non_default_target(repo: TestRepo) {
.parent()
.unwrap()
.join("repo.feature-for-staging");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args([
+ repo.run_git(&[
"worktree",
"add",
feature_wt.to_str().unwrap(),
"-b",
"feature-for-staging",
&base_commit,
- ])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ ]);
std::fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "feature.txt"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add feature for staging"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "feature.txt"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Add feature for staging"]);
// Merge to staging explicitly (NOT to main)
// This should rebase onto staging (which has staging-file.txt)
@@ -2116,33 +1821,13 @@ fn test_merge_squash_with_working_tree_creates_backup(mut repo_with_main_worktre
// First commit
std::fs::write(feature_wt.join("file1.txt"), "content 1").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "file1.txt"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "feat: add file 1"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "file1.txt"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "feat: add file 1"]);
// Second commit
std::fs::write(feature_wt.join("file2.txt"), "content 2").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "file2.txt"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "feat: add file 2"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "file2.txt"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "feat: add file 2"]);
// Add uncommitted tracked changes that will be included in the squash
std::fs::write(feature_wt.join("file1.txt"), "updated content 1").unwrap();
@@ -2162,11 +1847,9 @@ fn test_merge_squash_with_working_tree_creates_backup(mut repo_with_main_worktre
// Verify that a backup was created in the reflog
// Note: The worktree has been removed by the merge, so we check from the repo root
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
+ let output = repo
+ .git_command()
.args(["reflog", "show", "refs/wt-backup/feature"])
- .current_dir(repo.root_path())
.output()
.unwrap();
@@ -2193,12 +1876,7 @@ fn test_merge_does_not_permanently_set_receive_deny_current_branch(
let (repo, feature_wt) = merge_scenario;
// Explicitly set config to "refuse" - this would block pushes to checked-out branches
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["config", "receive.denyCurrentBranch", "refuse"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["config", "receive.denyCurrentBranch", "refuse"]);
// Perform merge - should succeed despite "refuse" setting because we use --receive-pack
let mut cmd = make_snapshot_cmd(&repo, "merge", &["main"], Some(&feature_wt));
@@ -2213,11 +1891,9 @@ fn test_merge_does_not_permanently_set_receive_deny_current_branch(
);
// Check config after merge - should still be "refuse" (not permanently changed)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let after = cmd
+ let after = repo
+ .git_command()
.args(["config", "receive.denyCurrentBranch"])
- .current_dir(repo.root_path())
.output()
.unwrap();
let after_value = String::from_utf8_lossy(&after.stdout).trim().to_string();
@@ -2285,32 +1961,12 @@ fn test_step_squash_with_no_verify_flag(mut repo: TestRepo) {
// Commit the config as part of first commit to avoid untracked file warnings
fs::write(feature_wt.join("file1.txt"), "content 1").expect("Failed to write file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", ".config", "file1.txt"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to add files");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "feat: add file 1"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to commit");
+ repo.run_git_in(&feature_wt, &["add", ".config", "file1.txt"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "feat: add file 1"]);
fs::write(feature_wt.join("file2.txt"), "content 2").expect("Failed to write file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "file2.txt"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to add file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "feat: add file 2"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to commit");
+ repo.run_git_in(&feature_wt, &["add", "file2.txt"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "feat: add file 2"]);
snapshot_step_squash_with_env(
"step_squash_no_verify",
@@ -2332,32 +1988,12 @@ fn test_step_squash_with_stage_tracked_flag(mut repo: TestRepo) {
let feature_wt = repo.add_worktree("feature");
fs::write(feature_wt.join("file1.txt"), "content 1").expect("Failed to write file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "file1.txt"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to add file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "feat: add file 1"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to commit");
+ repo.run_git_in(&feature_wt, &["add", "file1.txt"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "feat: add file 1"]);
fs::write(feature_wt.join("file2.txt"), "content 2").expect("Failed to write file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "file2.txt"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to add file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "feat: add file 2"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to commit");
+ repo.run_git_in(&feature_wt, &["add", "file2.txt"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "feat: add file 2"]);
// Add uncommitted tracked changes
fs::write(feature_wt.join("file1.txt"), "updated content").expect("Failed to write file");
@@ -2392,32 +2028,12 @@ fn test_step_squash_with_both_flags(mut repo: TestRepo) {
// Commit the config as part of first commit to avoid untracked file warnings
fs::write(feature_wt.join("file1.txt"), "content 1").expect("Failed to write file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", ".config", "file1.txt"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to add files");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "feat: add file 1"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to commit");
+ repo.run_git_in(&feature_wt, &["add", ".config", "file1.txt"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "feat: add file 1"]);
fs::write(feature_wt.join("file2.txt"), "content 2").expect("Failed to write file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "file2.txt"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to add file");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "feat: add file 2"])
- .current_dir(&feature_wt)
- .output()
- .expect("Failed to commit");
+ repo.run_git_in(&feature_wt, &["add", "file2.txt"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "feat: add file 2"]);
fs::write(feature_wt.join("file1.txt"), "updated content").expect("Failed to write file");
@@ -2698,27 +2314,14 @@ fn test_step_rebase_with_merge_commit(mut repo: TestRepo) {
// Advance main with a new commit
fs::write(repo.root_path().join("main-update.txt"), "main content").unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "main-update.txt"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Update main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "main-update.txt"]);
+ repo.run_git(&["commit", "-m", "Update main"]);
// Merge main INTO the feature branch (creating a merge commit)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
- .args(["merge", "main", "-m", "Merge main into feature"])
+ let output = repo
+ .git_command()
.current_dir(&feature_wt)
+ .args(["merge", "main", "-m", "Merge main into feature"])
.output()
.unwrap();
assert!(
diff --git a/tests/integration_tests/push.rs b/tests/integration_tests/push.rs
index ab91c057f..54ae3ccd1 100644
--- a/tests/integration_tests/push.rs
+++ b/tests/integration_tests/push.rs
@@ -4,7 +4,6 @@ use crate::common::{
};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
-use std::process::Command;
/// Helper to create snapshot with normalized paths
fn snapshot_push(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&std::path::Path>) {
@@ -82,13 +81,7 @@ fn test_push_with_dirty_target(mut repo: TestRepo) {
let main_contents = std::fs::read_to_string(repo.root_path().join("conflict.txt")).unwrap();
assert_eq!(main_contents, "old content");
- let mut git_cmd = Command::new("git");
- repo.configure_git_cmd(&mut git_cmd);
- let stash_list = git_cmd
- .args(["stash", "list"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ let stash_list = repo.git_command().args(["stash", "list"]).output().unwrap();
assert!(
String::from_utf8_lossy(&stash_list.stdout)
.trim()
@@ -116,13 +109,7 @@ fn test_push_dirty_target_autostash(mut repo: TestRepo) {
assert_eq!(notes, "temporary notes");
// Autostash should clean up after itself
- let mut git_cmd = Command::new("git");
- repo.configure_git_cmd(&mut git_cmd);
- let stash_list = git_cmd
- .args(["stash", "list"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ let stash_list = repo.git_command().args(["stash", "list"]).output().unwrap();
assert!(
String::from_utf8_lossy(&stash_list.stdout)
.trim()
@@ -156,19 +143,11 @@ fn test_push_dirty_target_overlap_renamed_file(mut repo: TestRepo) {
std::fs::write(repo.root_path().join("file.txt"), "modified in target").unwrap();
// In feature worktree, rename file.txt to renamed.txt and commit
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["mv", "file.txt", "renamed.txt"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Rename file.txt to renamed.txt"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["mv", "file.txt", "renamed.txt"]);
+ repo.run_git_in(
+ &feature_wt,
+ &["commit", "-m", "Rename file.txt to renamed.txt"],
+ );
// Try to push from feature to main (should fail due to conflicting changes)
// The renamed file.txt (now renamed.txt) conflicts with uncommitted file.txt changes
@@ -183,13 +162,7 @@ fn test_push_dirty_target_overlap_renamed_file(mut repo: TestRepo) {
let main_contents = std::fs::read_to_string(repo.root_path().join("file.txt")).unwrap();
assert_eq!(main_contents, "modified in target");
- let mut git_cmd = Command::new("git");
- repo.configure_git_cmd(&mut git_cmd);
- let stash_list = git_cmd
- .args(["stash", "list"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ let stash_list = repo.git_command().args(["stash", "list"]).output().unwrap();
assert!(
String::from_utf8_lossy(&stash_list.stdout)
.trim()
@@ -235,29 +208,16 @@ fn test_push_with_merge_commits(mut repo: TestRepo) {
let feature_wt = repo.add_worktree_with_commit("feature", "file1.txt", "content1", "Commit 1");
// Create another branch for merging
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["checkout", "-b", "temp"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["checkout", "-b", "temp"]);
repo.commit_in_worktree(&feature_wt, "file2.txt", "content2", "Commit 2");
// Switch back to feature and merge temp (creating merge commit)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["checkout", "feature"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["merge", "temp", "--no-ff", "-m", "Merge temp"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["checkout", "feature"]);
+ repo.run_git_in(
+ &feature_wt,
+ &["merge", "temp", "--no-ff", "-m", "Merge temp"],
+ );
// Push to main (should succeed - merge commits are allowed)
snapshot_push(
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index b986e5ffc..4757dda87 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -1,13 +1,11 @@
use crate::common::{
- TestRepo, canonicalize, configure_directive_file, directive_file, make_snapshot_cmd, repo,
- repo_with_remote, setup_snapshot_settings, setup_temp_snapshot_settings, wt_command,
+ BareRepoTest, TestRepo, TestRepoBase, configure_directive_file, directive_file,
+ make_snapshot_cmd, repo, repo_with_remote, setup_snapshot_settings,
+ setup_temp_snapshot_settings, wt_command,
};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
-use std::path::PathBuf;
-use std::process::Command;
use std::time::Duration;
-use tempfile::TempDir;
/// Helper to create snapshot with normalized paths
fn snapshot_remove(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&std::path::Path>) {
@@ -57,12 +55,7 @@ fn test_remove_already_on_default(repo: TestRepo) {
#[rstest]
fn test_remove_switch_to_default(repo: TestRepo) {
// Create and switch to a feature branch in the main repo
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["switch", "-c", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["switch", "-c", "feature"]);
snapshot_remove("remove_switch_to_default", &repo, &[], None);
}
@@ -212,29 +205,10 @@ fn test_remove_multiple_nonexistent_force(repo: TestRepo) {
#[rstest]
fn test_remove_remote_only_branch(#[from(repo_with_remote)] repo: TestRepo) {
// Create a remote-only branch by pushing a branch then deleting it locally
- Command::new("git")
- .args(["branch", "remote-feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["push", "origin", "remote-feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["branch", "-D", "remote-feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- Command::new("git")
- .args(["fetch", "origin"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "remote-feature"]);
+ repo.run_git(&["push", "origin", "remote-feature"]);
+ repo.run_git(&["branch", "-D", "remote-feature"]);
+ repo.run_git(&["fetch", "origin"]);
// Try to remove a branch that only exists on remote - should get helpful error
snapshot_remove(
@@ -783,12 +757,7 @@ fn test_remove_main_worktree_vs_linked_worktree(mut repo: TestRepo) {
);
// Part 5: Create a feature branch IN the main worktree, verify STILL cannot remove
- let mut cmd = std::process::Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["switch", "-c", "feature-in-main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["switch", "-c", "feature-in-main"]);
snapshot_remove(
"remove_main_vs_linked__main_on_feature_fails",
@@ -799,12 +768,7 @@ fn test_remove_main_worktree_vs_linked_worktree(mut repo: TestRepo) {
// Part 6: Verify main worktree CANNOT be removed by name from a linked worktree
// Switch back to main branch in main worktree, then create a new linked worktree
- let mut cmd = std::process::Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["switch", "main"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["switch", "main"]);
let linked_for_test = repo.add_worktree("test-from-linked");
snapshot_remove(
@@ -824,107 +788,20 @@ fn test_remove_main_worktree_vs_linked_worktree(mut repo: TestRepo) {
/// branch in a normal repo (the main worktree already has it checked out).
#[test]
fn test_remove_default_branch_no_tautology() {
- // Create bare repository
- let temp_dir = TempDir::new().unwrap();
- let bare_repo_path = temp_dir.path().join("repo.git");
- let test_config_path = temp_dir.path().join("test-config.toml");
-
- let output = Command::new("git")
- .args(["init", "--bare", "--initial-branch", "main"])
- .current_dir(temp_dir.path())
- .arg(&bare_repo_path)
- .env("GIT_CONFIG_GLOBAL", "/dev/null")
- .env("GIT_CONFIG_SYSTEM", "/dev/null")
- .output()
- .unwrap();
- assert!(output.status.success(), "Failed to init bare repo");
-
- let bare_repo_path: PathBuf = canonicalize(&bare_repo_path).unwrap();
-
- // Create worktree for main branch
- let main_worktree = temp_dir.path().join("repo.main");
- let output = Command::new("git")
- .args([
- "-C",
- bare_repo_path.to_str().unwrap(),
- "worktree",
- "add",
- "-b",
- "main",
- main_worktree.to_str().unwrap(),
- ])
- .env("GIT_CONFIG_GLOBAL", "/dev/null")
- .env("GIT_CONFIG_SYSTEM", "/dev/null")
- .env("GIT_AUTHOR_DATE", "2025-01-01T00:00:00Z")
- .env("GIT_COMMITTER_DATE", "2025-01-01T00:00:00Z")
- .output()
- .unwrap();
- assert!(output.status.success(), "Failed to create main worktree");
-
- let main_worktree = canonicalize(&main_worktree).unwrap();
-
- // Create initial commit in main worktree
- std::fs::write(main_worktree.join("file.txt"), "initial").unwrap();
- let output = Command::new("git")
- .args(["add", "file.txt"])
- .current_dir(&main_worktree)
- .env("GIT_CONFIG_GLOBAL", "/dev/null")
- .env("GIT_CONFIG_SYSTEM", "/dev/null")
- .output()
- .unwrap();
- assert!(output.status.success());
- let output = Command::new("git")
- .args(["commit", "-m", "Initial commit"])
- .current_dir(&main_worktree)
- .env("GIT_CONFIG_GLOBAL", "/dev/null")
- .env("GIT_CONFIG_SYSTEM", "/dev/null")
- .env("GIT_AUTHOR_NAME", "Test User")
- .env("GIT_AUTHOR_EMAIL", "[email protected]")
- .env("GIT_AUTHOR_DATE", "2025-01-01T00:00:00Z")
- .env("GIT_COMMITTER_NAME", "Test User")
- .env("GIT_COMMITTER_EMAIL", "[email protected]")
- .env("GIT_COMMITTER_DATE", "2025-01-01T00:00:00Z")
- .output()
- .unwrap();
- assert!(output.status.success());
-
- // Create a second worktree (feature) so we have somewhere to run remove from
- let feature_worktree = temp_dir.path().join("repo.feature");
- let output = Command::new("git")
- .args([
- "-C",
- bare_repo_path.to_str().unwrap(),
- "worktree",
- "add",
- "-b",
- "feature",
- feature_worktree.to_str().unwrap(),
- ])
- .env("GIT_CONFIG_GLOBAL", "/dev/null")
- .env("GIT_CONFIG_SYSTEM", "/dev/null")
- .env("GIT_AUTHOR_DATE", "2025-01-01T00:00:00Z")
- .env("GIT_COMMITTER_DATE", "2025-01-01T00:00:00Z")
- .output()
- .unwrap();
- assert!(output.status.success(), "Failed to create feature worktree");
+ let test = BareRepoTest::new();
- let feature_worktree = canonicalize(&feature_worktree).unwrap();
+ // Create worktrees for main and feature branches
+ let main_worktree = test.create_worktree("main", "main");
+ test.commit_in(&main_worktree, "Initial commit on main");
+ let feature_worktree = test.create_worktree("feature", "feature");
// Remove main worktree by name from feature worktree (foreground for snapshot)
// Should NOT show "(ancestor of main)" - that would be tautological
- let settings = setup_temp_snapshot_settings(temp_dir.path());
+ let settings = setup_temp_snapshot_settings(test.temp_path());
settings.bind(|| {
- let mut cmd = wt_command();
+ let mut cmd = test.wt_command();
cmd.args(["remove", "--no-background", "main"])
- .current_dir(&feature_worktree)
- .env("WORKTRUNK_CONFIG_PATH", test_config_path.to_str().unwrap())
- .env("GIT_CONFIG_GLOBAL", "/dev/null")
- .env("GIT_CONFIG_SYSTEM", "/dev/null")
- .env("GIT_AUTHOR_DATE", "2025-01-01T00:00:00Z")
- .env("GIT_COMMITTER_DATE", "2025-01-01T00:00:00Z")
- .env("GIT_EDITOR", "")
- .env("LANG", "C")
- .env("LC_ALL", "C");
+ .current_dir(&feature_worktree);
assert_cmd_snapshot!("remove_default_branch_no_tautology", cmd);
});
diff --git a/tests/integration_tests/security.rs b/tests/integration_tests/security.rs
index 072cbf91d..a1f1d6fe1 100644
--- a/tests/integration_tests/security.rs
+++ b/tests/integration_tests/security.rs
@@ -121,13 +121,7 @@ fn test_git_rejects_nul_in_commit_messages(repo: TestRepo) {
// Create a file to commit
std::fs::write(repo.root_path().join("test.txt"), "content").unwrap();
- let mut add_cmd = Command::new("git");
- repo.configure_git_cmd(&mut add_cmd);
- add_cmd
- .args(["add", "."])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", "."]);
// Try to commit with NUL in message using shell redirection
let shell_cmd = format!(
@@ -168,10 +162,8 @@ fn test_rust_prevents_nul_bytes_in_args(repo: TestRepo) {
// Rust's Command API should reject NUL bytes in arguments
let malicious_branch = "feature\0__WORKTRUNK_EXEC__echo PWNED";
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", malicious_branch])
- .current_dir(repo.root_path());
+ let mut cmd = repo.git_command();
+ cmd.args(["branch", malicious_branch]);
// Command::output() should fail with InvalidInput error
let result = cmd.output();
@@ -203,12 +195,11 @@ fn test_branch_name_is_directive_not_executed(repo: TestRepo) {
let malicious_branch = "__WORKTRUNK_EXEC__echo PWNED > /tmp/hacked2";
// Try to create this branch
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", malicious_branch])
- .current_dir(repo.root_path());
-
- let result = cmd.output().unwrap();
+ let result = repo
+ .git_command()
+ .args(["branch", malicious_branch])
+ .output()
+ .unwrap();
if !result.status.success() {
// Git rejected the malicious branch name
@@ -243,12 +234,11 @@ fn test_branch_name_is_directive_not_executed(repo: TestRepo) {
fn test_branch_name_with_newline_directive_not_executed(repo: TestRepo) {
let malicious_branch = "feature\n__WORKTRUNK_EXEC__echo PWNED > /tmp/hacked3";
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", malicious_branch])
- .current_dir(repo.root_path());
-
- let result = cmd.output().unwrap();
+ let result = repo
+ .git_command()
+ .args(["branch", malicious_branch])
+ .output()
+ .unwrap();
if !result.status.success() {
return;
@@ -346,12 +336,11 @@ fn test_branch_name_with_cd_directive_not_executed(repo: TestRepo) {
// Branch name that IS a CD directive (no NUL - git allows this)
let malicious_branch = "__WORKTRUNK_CD__/tmp";
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", malicious_branch])
- .current_dir(repo.root_path());
-
- let result = cmd.output().unwrap();
+ let result = repo
+ .git_command()
+ .args(["branch", malicious_branch])
+ .output()
+ .unwrap();
if !result.status.success() {
// Git rejected it - that's fine, nothing to test
@@ -414,12 +403,11 @@ fn test_execute_flag_with_directive_like_branch_name(repo: TestRepo) {
// Branch name that looks like a directive
let malicious_branch = "__WORKTRUNK_EXEC__echo PWNED > /tmp/hacked7";
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", malicious_branch])
- .current_dir(repo.root_path());
-
- let result = cmd.output().unwrap();
+ let result = repo
+ .git_command()
+ .args(["branch", malicious_branch])
+ .output()
+ .unwrap();
if !result.status.success() {
// Git rejected the branch name
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index f2165857a..cdf9fd5fd 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -2152,19 +2152,8 @@ fi
fs::write(config_dir.join("wt.toml"), config_content).unwrap();
// Commit the config
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", ".config/wt.toml", ".bin"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add pre-merge hooks"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", ".config/wt.toml", ".bin"]);
+ repo.run_git(&["commit", "-m", "Add pre-merge hooks"]);
// Create a feature worktree and make multiple commits
let feature_wt = repo.add_worktree("feature-auth");
@@ -2191,18 +2180,8 @@ def login(username: str, password: str) -> Optional[Dict]:
return {'token': token, 'expires_in': 3600}
"#;
std::fs::write(feature_wt.join("api/auth.py"), auth_py_v1).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "api/auth.py"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add login endpoint"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "api/auth.py"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Add login endpoint"]);
// Second commit - add tests
fs::create_dir_all(feature_wt.join("tests")).unwrap();
@@ -2222,18 +2201,8 @@ def test_token_validation():
assert login('valid_user', 'valid_pass')['expires_in'] == 3600
"#;
std::fs::write(feature_wt.join("tests/test_auth.py"), test_auth_py).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "tests/test_auth.py"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add authentication tests"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "tests/test_auth.py"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Add authentication tests"]);
// Third commit - add refresh endpoint
let auth_py_v2 = r#"# Authentication API endpoints
@@ -2269,18 +2238,8 @@ def refresh_token(token: str) -> Optional[Dict]:
return None
"#;
std::fs::write(feature_wt.join("api/auth.py"), auth_py_v2).unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "api/auth.py"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add validation"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_wt, &["add", "api/auth.py"]);
+ repo.run_git_in(&feature_wt, &["commit", "-m", "Add validation"]);
// Configure LLM in worktrunk config
let llm_path = bin_dir.join("llm");
@@ -2371,19 +2330,8 @@ fi
fs::write(config_dir.join("wt.toml"), config_content).unwrap();
// Commit the config
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", ".config/wt.toml", ".bin"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Add project hooks"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["add", ".config/wt.toml", ".bin"]);
+ repo.run_git(&["commit", "-m", "Add project hooks"]);
// Set PATH with mock binaries and run switch --create
let path_with_bin = format!(
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index b62f63d2d..8cd3ed315 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -66,30 +66,12 @@ fn test_switch_create_existing_branch_error(mut repo: TestRepo) {
#[rstest]
fn test_switch_create_with_remote_branch_only(#[from(repo_with_remote)] repo: TestRepo) {
- use std::process::Command;
-
// Create a branch on the remote only (no local branch)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "remote-feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["push", "origin", "remote-feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "remote-feature"]);
+ repo.run_git(&["push", "origin", "remote-feature"]);
// Delete the local branch
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "-D", "remote-feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "-D", "remote-feature"]);
// Now we have origin/remote-feature but no local remote-feature
// This should succeed with --create (previously would fail)
@@ -413,15 +395,8 @@ fn test_switch_previous_branch_no_history(repo: TestRepo) {
#[rstest]
fn test_switch_main_branch(repo: TestRepo) {
- use std::process::Command;
-
// Create a feature branch
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "feature-a"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature-a"]);
// Switch to feature-a first
snapshot_switch("switch_main_branch_to_feature", &repo, &["feature-a"]);
@@ -457,22 +432,15 @@ fn test_switch_no_warning_when_branch_matches(mut repo: TestRepo) {
/// Test switching to a worktree at an unexpected path shows a hint
#[rstest]
fn test_switch_path_mismatch_shows_hint(repo: TestRepo) {
- use std::process::Command;
-
// Create a worktree at a non-standard path (sibling to repo, not following template)
let wrong_path = repo.root_path().parent().unwrap().join("wrong-path");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args([
+ repo.run_git(&[
"worktree",
"add",
wrong_path.to_str().unwrap(),
"-b",
"feature",
- ])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ ]);
// Switch to feature - should show hint about path mismatch
snapshot_switch_with_directive_file("switch_path_mismatch_shows_hint", &repo, &["feature"]);
@@ -486,30 +454,18 @@ fn test_switch_path_mismatch_shows_hint(repo: TestRepo) {
/// branch currently occupies the path.
#[rstest]
fn test_switch_error_path_occupied_different_branch(repo: TestRepo) {
- use std::process::Command;
-
// Create a worktree for "feature" branch at expected path
let feature_path = repo.root_path().parent().unwrap().join("repo.feature");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args([
+ repo.run_git(&[
"worktree",
"add",
feature_path.to_str().unwrap(),
"-b",
"feature",
- ])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ ]);
// Switch that worktree to a different branch "bugfix"
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["switch", "-c", "bugfix"])
- .current_dir(&feature_path)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_path, &["switch", "-c", "bugfix"]);
// Switch to feature - should error since path is occupied by bugfix worktree
snapshot_switch_with_directive_file(
@@ -522,39 +478,26 @@ fn test_switch_error_path_occupied_different_branch(repo: TestRepo) {
/// Test that switching to a branch errors when path is occupied by detached HEAD worktree
#[rstest]
fn test_switch_error_path_occupied_detached(repo: TestRepo) {
- use std::process::Command;
-
// Create a worktree for "feature" branch at expected path
let feature_path = repo.root_path().parent().unwrap().join("repo.feature");
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args([
+ repo.run_git(&[
"worktree",
"add",
feature_path.to_str().unwrap(),
"-b",
"feature",
- ])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ ]);
// Get the HEAD commit and detach
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- let output = cmd
+ let output = repo
+ .git_command()
.args(["rev-parse", "HEAD"])
.current_dir(&feature_path)
.output()
.unwrap();
let commit = String::from_utf8_lossy(&output.stdout).trim().to_string();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["checkout", "--detach", &commit])
- .current_dir(&feature_path)
- .output()
- .unwrap();
+ repo.run_git_in(&feature_path, &["checkout", "--detach", &commit]);
// Switch to feature - should error since path is occupied by detached worktree
snapshot_switch_with_directive_file("switch_error_path_occupied_detached", &repo, &["feature"]);
@@ -567,15 +510,8 @@ fn test_switch_error_path_occupied_detached(repo: TestRepo) {
/// explaining how to get there. This matches GitHub issue #327.
#[rstest]
fn test_switch_main_worktree_on_different_branch(repo: TestRepo) {
- use std::process::Command;
-
// Switch the main worktree to a different branch
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["checkout", "-b", "feature"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["checkout", "-b", "feature"]);
// Now try to switch to main - should error since main worktree is on different branch
snapshot_switch_with_directive_file(
@@ -591,18 +527,11 @@ fn test_switch_main_worktree_on_different_branch(repo: TestRepo) {
/// switched to a different branch, and user runs `wt switch <default-branch>`.
#[rstest]
fn test_switch_default_branch_from_feature_worktree(mut repo: TestRepo) {
- use std::process::Command;
-
// Create a feature worktree to work from
let feature_a_path = repo.add_worktree("feature-a");
// Switch main worktree to a different branch (simulates user running git checkout there)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["checkout", "-b", "feature-rpa"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["checkout", "-b", "feature-rpa"]);
// From feature-a worktree, try to switch to main (default branch)
// This should error because main worktree is now on feature-rpa
@@ -650,16 +579,9 @@ fn test_switch_internal_execute_with_output_before_exit(repo: TestRepo) {
/// when recording new history, not any previously stored value.
#[rstest]
fn test_switch_previous_with_stale_history(repo: TestRepo) {
- use std::process::Command;
-
// Create branches with worktrees
for branch in ["branch-a", "branch-b", "branch-c"] {
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", branch])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", branch]);
}
// Switch to branch-a, then branch-b to establish history
@@ -669,12 +591,7 @@ fn test_switch_previous_with_stale_history(repo: TestRepo) {
// Now manually set history to simulate user changing worktrees without wt switch.
// History stores just the previous branch (branch-a from the earlier switches).
// If user manually cd'd to branch-c's worktree, history would still say branch-a.
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["config", "worktrunk.history", "branch-a"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["config", "worktrunk.history", "branch-a"]);
// Run wt switch - from branch-b's worktree.
// Should go to branch-a (what history says), and record actual current branch as new previous.
@@ -691,15 +608,8 @@ fn test_switch_previous_with_stale_history(repo: TestRepo) {
/// changes the working directory before the next command runs.
#[rstest]
fn test_switch_ping_pong_realistic(repo: TestRepo) {
- use std::process::Command;
-
// Create feature-a branch
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["branch", "feature-a"])
- .current_dir(repo.root_path())
- .output()
- .unwrap();
+ repo.run_git(&["branch", "feature-a"]);
// Step 1: From main worktree, switch to feature-a (creates worktree)
// History: current=feature-a, previous=main
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_to_non_default_target.snap b/tests/snapshots/integration__integration_tests__merge__merge_to_non_default_target.snap
index fdc5b6113..929686a43 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_to_non_default_target.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_to_non_default_target.snap
@@ -38,4 +38,4 @@ exit_code: 0
  1 file changed, 1 insertion(+)
✓ Merged to staging (1 commit, 1 file, +1)
◎ Removing feature-for-staging worktree & branch in background (same commit as staging, _)
-○ Switched to worktree for staging @ _REPO_
+○ Switched to worktree for staging @ _REPO_.staging-wt
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_default_branch_no_tautology.snap b/tests/snapshots/integration__integration_tests__remove__remove_default_branch_no_tautology.snap
index 114da478d..bff47074f 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_default_branch_no_tautology.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_default_branch_no_tautology.snap
@@ -7,15 +7,17 @@ info:
- "--no-background"
- main
env:
- CLICOLOR_FORCE: "1"
+ CLICOLOR_FORCE: ""
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
LANG: C
LC_ALL: C
+ NO_COLOR: ""
RUST_LOG: warn
SOURCE_DATE_EPOCH: "1735776000"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
@@ -25,5 +27,5 @@ exit_code: 0
----- stdout -----
----- stderr -----
-◎ Removing main worktree...
-✓ Removed main worktree & branch
+◎ Removing main worktree...
+✓ Removed main worktree & branch