Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add helper methods to TestRepo for common test patterns
Maximilian Roose8d99854ec90
diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 78324d6c2..110f967b8 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -826,6 +826,117 @@ impl TestRepo {main_wt}+ /// Creates a worktree with a file and commits it.+ ///+ /// This is a convenience method that combines the common pattern of:+ /// 1. Creating a worktree for a new branch+ /// 2. Writing a file to it+ /// 3. Staging and committing the file+ ///+ /// # Example+ /// ```ignore+ /// let feature_wt = repo.add_worktree_with_commit(+ /// "feature",+ /// "feature.txt",+ /// "feature content",+ /// "Add feature file",+ /// );+ /// ```+ pub fn add_worktree_with_commit(+ &mut self,+ branch: &str,+ filename: &str,+ content: &str,+ message: &str,+ ) -> PathBuf {+ let worktree_path = self.add_worktree(branch);++ std::fs::write(worktree_path.join(filename), content).unwrap();++ let mut cmd = Command::new("git");+ self.configure_git_cmd(&mut cmd);+ cmd.args(["add", filename])+ .current_dir(&worktree_path)+ .output()+ .unwrap();++ let mut cmd = Command::new("git");+ self.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", message])+ .current_dir(&worktree_path)+ .output()+ .unwrap();++ worktree_path+ }++ /// Adds a commit to an existing worktree.+ ///+ /// This writes a file, stages it, and commits it in the specified worktree.+ /// Useful for tests that need multiple commits in the same worktree.+ ///+ /// # Arguments+ /// * `worktree_path` - Path to the existing worktree+ /// * `filename` - Name of the file to create/modify+ /// * `content` - Content to write to the file+ /// * `message` - Commit message+ ///+ /// # Example+ /// ```ignore+ /// let feature_wt = repo.add_worktree("feature");+ /// repo.commit_in_worktree(&feature_wt, "file1.txt", "content 1", "feat: add file 1");+ /// repo.commit_in_worktree(&feature_wt, "file2.txt", "content 2", "feat: add file 2");+ /// ```+ pub fn commit_in_worktree(+ &self,+ worktree_path: &Path,+ filename: &str,+ content: &str,+ message: &str,+ ) {+ std::fs::write(worktree_path.join(filename), content).unwrap();++ let mut cmd = Command::new("git");+ self.configure_git_cmd(&mut cmd);+ cmd.args(["add", filename])+ .current_dir(worktree_path)+ .output()+ .unwrap();++ let mut cmd = Command::new("git");+ self.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", message])+ .current_dir(worktree_path)+ .output()+ .unwrap();+ }++ /// Creates a branch without a worktree.+ ///+ /// This creates a local branch pointing to HEAD without checking it out.+ /// Useful for testing branch listing without creating worktrees.+ pub fn create_branch(&self, branch_name: &str) {+ let mut cmd = Command::new("git");+ self.configure_git_cmd(&mut cmd);+ cmd.args(["branch", branch_name])+ .current_dir(self.root_path())+ .output()+ .unwrap();+ }++ /// Pushes a branch to origin.+ ///+ /// Creates a remote tracking branch on origin. Requires `setup_remote()`+ /// to have been called first.+ pub fn push_branch(&self, branch_name: &str) {+ let mut cmd = Command::new("git");+ self.configure_git_cmd(&mut cmd);+ cmd.args(["push", "origin", branch_name])+ .current_dir(self.root_path())+ .output()+ .unwrap();+ }+/// Detach HEAD in the main repositorypub fn detach_head(&self) {self.detach_head_at(&self.root);diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rsindex fca08bd1c..f475dbb4a 100644--- a/tests/integration_tests/directives.rs+++ b/tests/integration_tests/directives.rs@@ -1,7 +1,7 @@-use crate::common::{TestRepo, setup_snapshot_settings, wt_command};+use crate::common::{TestRepo, repo, setup_snapshot_settings, wt_command};use insta::Settings;use insta_cmd::assert_cmd_snapshot;-use std::process::Command;+use rstest::rstest;// ============================================================================// PowerShell Directive Tests@@ -12,10 +12,8 @@ use std::process::Command;// - Proper single-quote escaping ('' instead of '\'' for embedded quotes)/// Test that switch with --internal=powershell outputs PowerShell Set-Location syntax-#[test]-fn test_switch_internal_powershell_directive() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+#[rstest]+fn test_switch_internal_powershell_directive(mut repo: TestRepo) {repo.setup_remote("main");let _feature_wt = repo.add_worktree("feature");@@ -38,38 +36,18 @@ fn test_switch_internal_powershell_directive() {}/// Test merge with --internal=powershell (switch back to main after merge)-#[test]-fn test_merge_internal_powershell_directive() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+#[rstest]+fn test_merge_internal_powershell_directive(mut repo: TestRepo) {repo.setup_remote("main");-- // Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commit- let feature_wt = repo.add_worktree("feature");- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );let mut settings = setup_snapshot_settings(&repo);// Normalize the PowerShell Set-Location path@@ -92,11 +70,9 @@ fn test_merge_internal_powershell_directive() {/// Note: Skipped on Windows due to platform differences in ANSI escape code handling/// (Unix doubles ESC[36m, Windows doesn't). The Set-Location syntax itself works correctly/// on both platforms - this is purely a test snapshot compatibility issue.-#[test]+#[rstest]#[cfg_attr(windows, ignore)]-fn test_remove_internal_powershell_directive() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+fn test_remove_internal_powershell_directive(mut repo: TestRepo) {repo.setup_remote("main");let feature_wt = repo.add_worktree("feature");@@ -120,10 +96,8 @@ fn test_remove_internal_powershell_directive() {// ============================================================================/// Test the directive protocol for switch command-#[test]-fn test_switch_internal_directive() {- let repo = TestRepo::new();-+#[rstest]+fn test_switch_internal_directive(repo: TestRepo) {let mut settings = Settings::clone_current();settings.set_snapshot_path("../snapshots");@@ -152,10 +126,8 @@ fn test_switch_internal_directive() {}/// Test switch without internal flag (should show help message)-#[test]-fn test_switch_without_internal() {- let repo = TestRepo::new();-+#[rstest]+fn test_switch_without_internal(repo: TestRepo) {let mut settings = Settings::clone_current();settings.set_snapshot_path("../snapshots");@@ -180,10 +152,8 @@ fn test_switch_without_internal() {}/// Test remove command with internal flag-#[test]-fn test_remove_internal_directive() {- let repo = TestRepo::new();-+#[rstest]+fn test_remove_internal_directive(repo: TestRepo) {let mut settings = Settings::clone_current();settings.set_snapshot_path("../snapshots");@@ -209,10 +179,8 @@ fn test_remove_internal_directive() {}/// Test remove without internal flag-#[test]-fn test_remove_without_internal() {- let repo = TestRepo::new();-+#[rstest]+fn test_remove_without_internal(repo: TestRepo) {let mut settings = Settings::clone_current();settings.set_snapshot_path("../snapshots");@@ -233,36 +201,17 @@ fn test_remove_without_internal() {}/// Test merge command with internal flag and --no-remove-#[test]-fn test_merge_internal_no_remove() {- let mut repo = TestRepo::new();-- // Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+#[rstest]+fn test_merge_internal_no_remove(mut repo: TestRepo) {+ repo.add_main_worktree();// Create a feature worktree and make a commit- let feature_wt = repo.add_worktree("feature");- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );let settings = setup_snapshot_settings(&repo);@@ -283,36 +232,17 @@ fn test_merge_internal_no_remove() {/// Test merge command with internal flag (removes worktree, emits cd shell script)/// This test verifies that the shell script output is correctly formatted-#[test]-fn test_merge_internal_remove() {- let mut repo = TestRepo::new();-- // Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+#[rstest]+fn test_merge_internal_remove(mut repo: TestRepo) {+ repo.add_main_worktree();// Create a feature worktree and make a commit- let feature_wt = repo.add_worktree("feature");- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );let mut settings = setup_snapshot_settings(&repo);settings.add_filter(r"cd '[^']+'", "cd '[PATH]'");diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rsindex 845fd2255..06ca177ec 100644--- a/tests/integration_tests/list.rs+++ b/tests/integration_tests/list.rs@@ -202,26 +202,6 @@ fn setup_timestamped_worktrees(repo: &mut TestRepo) -> std::path::PathBuf {current_path}-/// Helper to create a branch without a worktree-fn create_branch(repo: &TestRepo, branch_name: &str) {- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["branch", branch_name])- .current_dir(repo.root_path())- .output()- .unwrap();-}--/// Helper to push a branch to origin (creating a remote branch)-fn push_branch(repo: &TestRepo, branch_name: &str) {- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["push", "origin", branch_name])- .current_dir(repo.root_path())- .output()- .unwrap();-}-#[rstest]fn test_list_single_worktree(repo: TestRepo) {snapshot_list("single_worktree", &repo);@@ -407,9 +387,9 @@ fn test_list_json_tree_matches_main_after_merge(mut repo: TestRepo) {#[rstest]fn test_list_with_branches_flag(mut repo: TestRepo) {// Create some branches without worktrees- create_branch(&repo, "feature-without-worktree");- create_branch(&repo, "another-branch");- create_branch(&repo, "fix-bug");+ repo.create_branch("feature-without-worktree");+ repo.create_branch("another-branch");+ repo.create_branch("fix-bug");// Create one branch with a worktreerepo.add_worktree("feature-with-worktree");@@ -429,9 +409,9 @@ fn test_list_with_branches_flag_no_available(mut repo: TestRepo) {#[rstest]fn test_list_with_branches_flag_only_branches(repo: TestRepo) {// Create several branches without worktrees- create_branch(&repo, "branch-alpha");- create_branch(&repo, "branch-beta");- create_branch(&repo, "branch-gamma");+ repo.create_branch("branch-alpha");+ repo.create_branch("branch-beta");+ repo.create_branch("branch-gamma");snapshot_list_with_branches("with_branches_flag_only_branches", &repo);}@@ -439,10 +419,10 @@ fn test_list_with_branches_flag_only_branches(repo: TestRepo) {#[rstest]fn test_list_with_remotes_flag(#[from(repo_with_remote)] repo: TestRepo) {// Create feature branches in the main repo and push them- create_branch(&repo, "remote-feature-1");- create_branch(&repo, "remote-feature-2");- push_branch(&repo, "remote-feature-1");- push_branch(&repo, "remote-feature-2");+ repo.create_branch("remote-feature-1");+ repo.create_branch("remote-feature-2");+ repo.push_branch("remote-feature-1");+ repo.push_branch("remote-feature-2");// Delete the local branches - now they only exist as origin/remote-feature-*let mut cmd = Command::new("git");@@ -463,14 +443,14 @@ fn test_list_with_remotes_flag(#[from(repo_with_remote)] repo: TestRepo) {#[rstest]fn test_list_with_remotes_and_branches(#[from(repo_with_remote)] repo: TestRepo) {// Create local-only branches (not worktrees, not pushed)- create_branch(&repo, "local-only-1");- create_branch(&repo, "local-only-2");+ repo.create_branch("local-only-1");+ repo.create_branch("local-only-2");// Create branches, push them, then delete locally to make them remote-only- create_branch(&repo, "remote-only-1");- create_branch(&repo, "remote-only-2");- push_branch(&repo, "remote-only-1");- push_branch(&repo, "remote-only-2");+ repo.create_branch("remote-only-1");+ 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"])@@ -491,11 +471,11 @@ fn test_list_with_remotes_and_branches(#[from(repo_with_remote)] repo: TestRepo)fn test_list_with_remotes_filters_existing_worktrees(#[from(repo_with_remote)] mut repo: TestRepo) {// Create a worktree and push the branchrepo.add_worktree("feature-with-worktree");- push_branch(&repo, "feature-with-worktree");+ repo.push_branch("feature-with-worktree");// Create a branch, push it, delete it locally (remote-only)- create_branch(&repo, "remote-only");- push_branch(&repo, "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"])@@ -1854,8 +1834,8 @@ fn test_list_progressive_with_branches(mut repo: TestRepo) {repo.add_worktree("feature-a");// Create branches without worktrees- create_branch(&repo, "orphan-1");- create_branch(&repo, "orphan-2");+ repo.create_branch("orphan-1");+ repo.create_branch("orphan-2");// Critical: test that --branches works with --progressive// This ensures progressive mode supports the --branches flagdiff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex 296aebc2b..13324a78d 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -60,23 +60,13 @@ fn test_merge_when_primary_not_on_default_but_default_has_worktree(mut repo: Tes// Ensure main still has a worktree (secondary)let _main_wt = repo.add_main_worktree();- // Create a feature worktree and commit- let feature_wt = repo.add_worktree("feature");- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ // Create a feature worktree with a commit+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );snapshot_merge("merge_when_primary_not_on_default_but_default_has_worktree",@@ -141,22 +131,12 @@ fn test_merge_not_fast_forward(mut repo: TestRepo) {.unwrap();// Create a feature worktree branching from before the main commit- let feature_wt = repo.add_worktree("feature");- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Try to merge (should fail or require actual merge)snapshot_merge(@@ -259,13 +239,7 @@ fn test_merge_rebase_conflict(repo: TestRepo) {repo.commit("Add shared file");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Modify shared.txt in main branch (from the base commit)std::fs::write(repo.root_path().join("shared.txt"), "main version\n").unwrap();@@ -364,58 +338,13 @@ fn test_merge_error_detached_head(repo: TestRepo) {#[rstest]fn test_merge_squash_deterministic(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make multiple commitslet feature_wt = repo.add_worktree("feature");-- 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();-- 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", "fix: update logic"])- .current_dir(&feature_wt)- .output()- .unwrap();-- std::fs::write(feature_wt.join("file3.txt"), "content 3").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "file3.txt"])- .current_dir(&feature_wt)- .output()- .unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "docs: update readme"])- .current_dir(&feature_wt)- .output()- .unwrap();+ repo.commit_in_worktree(&feature_wt, "file1.txt", "content 1", "feat: add file 1");+ repo.commit_in_worktree(&feature_wt, "file2.txt", "content 2", "fix: update logic");+ repo.commit_in_worktree(&feature_wt, "file3.txt", "content 3", "docs: update readme");// Merge (squashing is now the default - no LLM configured, should use deterministic message)snapshot_merge(@@ -429,44 +358,22 @@ fn test_merge_squash_deterministic(mut repo: TestRepo) {#[rstest]fn test_merge_squash_with_llm(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make multiple commitslet feature_wt = repo.add_worktree("feature");-- std::fs::write(feature_wt.join("auth.txt"), "auth module").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "auth.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 authentication"])- .current_dir(&feature_wt)- .output()- .unwrap();-- std::fs::write(feature_wt.join("auth.txt"), "auth module updated").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "auth.txt"])- .current_dir(&feature_wt)- .output()- .unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "fix: handle edge case"])- .current_dir(&feature_wt)- .output()- .unwrap();+ repo.commit_in_worktree(+ &feature_wt,+ "auth.txt",+ "auth module",+ "feat: add authentication",+ );+ repo.commit_in_worktree(+ &feature_wt,+ "auth.txt",+ "auth module updated",+ "fix: handle edge case",+ );// Configure mock LLM command via config file// Use sh to consume stdin and return a fixed message@@ -484,44 +391,12 @@ args = ["-c", "cat >/dev/null && echo 'feat: implement user authentication syste#[rstest]fn test_merge_squash_llm_command_not_found(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make multiple commitslet feature_wt = repo.add_worktree("feature");-- 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: new feature"])- .current_dir(&feature_wt)- .output()- .unwrap();-- 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", "fix: bug fix"])- .current_dir(&feature_wt)- .output()- .unwrap();+ repo.commit_in_worktree(&feature_wt, "file1.txt", "content 1", "feat: new feature");+ repo.commit_in_worktree(&feature_wt, "file2.txt", "content 2", "fix: bug fix");// Configure LLM command that doesn't exist - should errorsnapshot_merge_with_env(@@ -541,44 +416,12 @@ fn test_merge_squash_llm_error(mut repo: TestRepo) {// Test that LLM command errors show proper gutter formatting with full command// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make commitslet feature_wt = repo.add_worktree("feature");-- 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: new feature"])- .current_dir(&feature_wt)- .output()- .unwrap();-- 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", "fix: bug fix"])- .current_dir(&feature_wt)- .output()- .unwrap();+ repo.commit_in_worktree(&feature_wt, "file1.txt", "content 1", "feat: new feature");+ repo.commit_in_worktree(&feature_wt, "file2.txt", "content 2", "fix: bug fix");// Configure LLM command via config file with command that will fail// This tests that:@@ -604,30 +447,11 @@ args = ["-c", "cat > /dev/null; echo 'Error: connection refused' >&2 && exit 1"]#[rstest]fn test_merge_squash_single_commit(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree with only one commit- let feature_wt = repo.add_worktree("feature");-- std::fs::write(feature_wt.join("file1.txt"), "content").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: single commit"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt =+ repo.add_worktree_with_commit("feature", "file1.txt", "content", "feat: single commit");// Merge (squashing is default) - should skip squashing since there's only one commitsnapshot_merge(@@ -654,13 +478,7 @@ fn test_merge_no_squash(merge_scenario_multi_commit: (TestRepo, PathBuf)) {#[rstest]fn test_merge_squash_empty_changes(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree with commits that result in no net changeslet feature_wt = repo.add_worktree("feature");@@ -670,49 +488,18 @@ fn test_merge_squash_empty_changes(mut repo: TestRepo) {let initial_content = std::fs::read_to_string(&file_path).unwrap();// Commit 1: Modify file.txt- std::fs::write(&file_path, "change1").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "file.txt"])- .current_dir(&feature_wt)- .output()- .unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Change 1"])- .current_dir(&feature_wt)- .output()- .unwrap();+ repo.commit_in_worktree(&feature_wt, "file.txt", "change1", "Change 1");// Commit 2: Modify file.txt again- std::fs::write(&file_path, "change2").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "file.txt"])- .current_dir(&feature_wt)- .output()- .unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Change 2"])- .current_dir(&feature_wt)- .output()- .unwrap();+ repo.commit_in_worktree(&feature_wt, "file.txt", "change2", "Change 2");// Commit 3: Revert to original content- std::fs::write(&file_path, initial_content).unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "file.txt"])- .current_dir(&feature_wt)- .output()- .unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Revert to initial"])- .current_dir(&feature_wt)- .output()- .unwrap();+ repo.commit_in_worktree(+ &feature_wt,+ "file.txt",+ &initial_content,+ "Revert to initial",+ );// Merge (squashing is default) - should succeed even when commits result in no net changessnapshot_merge(@@ -726,31 +513,15 @@ fn test_merge_squash_empty_changes(mut repo: TestRepo) {#[rstest]fn test_merge_auto_commit_deterministic(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree with a commit- let feature_wt = repo.add_worktree("feature");- std::fs::write(feature_wt.join("feature.txt"), "initial 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", "feat: initial feature"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "initial content",+ "feat: initial feature",+ );// Now add uncommitted tracked changesstd::fs::write(feature_wt.join("feature.txt"), "modified content").unwrap();@@ -767,31 +538,15 @@ fn test_merge_auto_commit_deterministic(mut repo: TestRepo) {#[rstest]fn test_merge_auto_commit_with_llm(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree with a commit- let feature_wt = repo.add_worktree("feature");- std::fs::write(feature_wt.join("auth.txt"), "initial auth").unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "auth.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 authentication"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "auth.txt",+ "initial auth",+ "feat: add authentication",+ );// Now add uncommitted tracked changesstd::fs::write(feature_wt.join("auth.txt"), "improved auth with validation").unwrap();@@ -842,13 +597,7 @@ args = ["-c", "cat >/dev/null && echo 'fix: update file 1 content'"]#[rstest]fn test_merge_with_untracked_files(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree with one commitlet feature_wt = repo.add_worktree("feature");@@ -895,13 +644,7 @@ fn test_merge_pre_merge_command_success(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commitlet feature_wt = repo.add_worktree("feature");@@ -942,13 +685,7 @@ fn test_merge_pre_merge_command_failure(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commitlet feature_wt = repo.add_worktree("feature");@@ -987,13 +724,7 @@ fn test_merge_pre_merge_command_no_hooks(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commitlet feature_wt = repo.add_worktree("feature");@@ -1043,13 +774,7 @@ test = "exit 0"repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commitlet feature_wt = repo.add_worktree("feature");@@ -1094,13 +819,7 @@ fn test_merge_post_merge_command_success(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commitlet feature_wt = repo.add_worktree("feature");@@ -1156,13 +875,7 @@ fn test_merge_post_merge_command_skipped_with_no_verify(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commitlet feature_wt = repo.add_worktree("feature");@@ -1210,13 +923,7 @@ fn test_merge_post_merge_command_failure(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commitlet feature_wt = repo.add_worktree("feature");@@ -1265,13 +972,7 @@ deploy = "echo 'Deploying branch {{ branch }}' > deploy.txt"repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commitlet feature_wt = repo.add_worktree("feature");@@ -1330,13 +1031,7 @@ fn test_merge_post_merge_runs_with_nothing_to_merge(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main (destination for post-merge commands)- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree with NO commits (already up-to-date with main)let feature_wt = repo.add_worktree("feature");@@ -1406,13 +1101,7 @@ fn test_merge_pre_commit_command_success(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a changelet feature_wt = repo.add_worktree("feature");@@ -1439,13 +1128,7 @@ fn test_merge_pre_commit_command_failure(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a changelet feature_wt = repo.add_worktree("feature");@@ -1476,13 +1159,7 @@ fn test_merge_pre_squash_command_success(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make commitslet feature_wt = repo.add_worktree("feature");@@ -1523,13 +1200,7 @@ fn test_merge_pre_squash_command_failure(mut repo: TestRepo) {repo.commit("Add config");// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make commitslet feature_wt = repo.add_worktree("feature");@@ -1755,13 +1426,7 @@ EOF.unwrap();// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make multiple commitslet feature_wt = repo.add_worktree("feature-auth");@@ -2077,13 +1742,7 @@ fi.unwrap();// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make multiple commitslet feature_wt = repo.add_worktree("feature-auth");@@ -2229,13 +1888,7 @@ command = "{}"#[rstest]fn test_merge_no_commit_with_clean_tree(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree with commits (clean tree)let feature_wt = repo.add_worktree("feature");@@ -2324,13 +1977,7 @@ fn test_merge_no_commit_with_dirty_tree(mut repo: TestRepo) {#[rstest]fn test_merge_no_commit_no_squash_no_remove_redundant(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree with commits (clean tree)let feature_wt = repo.add_worktree("feature");@@ -2592,13 +2239,7 @@ fn test_merge_primary_on_different_branch_dirty(mut repo: TestRepo) {#[rstest]fn test_merge_race_condition_commit_after_push(mut repo: TestRepo) {// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make a commitlet feature_wt = repo.add_worktree("feature");@@ -3280,13 +2921,7 @@ fn test_merge_error_uncommitted_changes_with_no_commit(mut repo: TestRepo) {// Tests the `uncommitted_changes()` error function when using --no-commit with dirty tree// Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktreelet feature_wt = repo.add_worktree("feature");@@ -3311,38 +2946,16 @@ fn test_merge_error_conflicting_changes_in_target(mut repo: TestRepo) {// Switch primary worktree off main so we can create a worktree for mainrepo.switch_primary_to("develop");- // Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- let output = cmd- .args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();- assert!(- output.status.success(),- "git worktree add failed: {}",- String::from_utf8_lossy(&output.stderr)- );+ // Create a worktree for main (succeeds because we switched primary off main)+ let main_wt = repo.add_main_worktree();// Create a feature worktree and commit a change to shared.txt- let feature_wt = repo.add_worktree("feature");- fs::write(feature_wt.join("shared.txt"), "feature content").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", "Add shared.txt on feature"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "shared.txt",+ "feature content",+ "Add shared.txt on feature",+ );// Now make uncommitted changes to shared.txt in main worktree// This creates a conflict - we're trying to push changes to shared.txtdiff --git a/tests/integration_tests/push.rs b/tests/integration_tests/push.rsindex e534302a9..4d722400e 100644--- a/tests/integration_tests/push.rs+++ b/tests/integration_tests/push.rs@@ -1,5 +1,6 @@-use crate::common::{TestRepo, make_snapshot_cmd, setup_snapshot_settings};+use crate::common::{TestRepo, make_snapshot_cmd, repo, setup_snapshot_settings};use insta_cmd::assert_cmd_snapshot;+use rstest::rstest;use std::process::Command;/// Helper to create snapshot with normalized paths@@ -14,140 +15,69 @@ fn snapshot_push(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&s});}-#[test]-fn test_push_fast_forward() {- let mut repo = TestRepo::new();-- // Create a worktree for main (checking out existing branch)- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+#[rstest]+fn test_push_fast_forward(mut repo: TestRepo) {+ // Create a worktree for main+ repo.add_main_worktree();// Make a commit in a feature worktree- let feature_wt = repo.add_worktree("feature");- std::fs::write(feature_wt.join("test.txt"), "test content").unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "test.txt"])- .current_dir(&feature_wt)- .output()- .unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Add test file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt =+ repo.add_worktree_with_commit("feature", "test.txt", "test content", "Add test file");// Push from feature to mainsnapshot_push("push_fast_forward", &repo, &["main"], Some(&feature_wt));}-#[test]-fn test_push_not_fast_forward() {- let mut repo = TestRepo::new();-+#[rstest]+fn test_push_not_fast_forward(mut repo: TestRepo) {// Create commits in both worktrees- // The repo root is already the main worktree- 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();-- let feature_wt = repo.add_worktree("feature");- 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();+ // Note: We use commit_in_worktree on root to match the original file layout+ // (file named main.txt instead of file.txt that repo.commit() creates)+ repo.commit_in_worktree(+ repo.root_path(),+ "main.txt",+ "main content",+ "Add main file",+ );- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Add feature file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ // Create a feature worktree branching from before the main commit+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Try to push from feature to main (should fail - not fast-forward)snapshot_push("push_not_fast_forward", &repo, &["main"], Some(&feature_wt));}-#[test]-fn test_push_to_default_branch() {- let mut repo = TestRepo::new();-- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();-- let feature_wt = repo.add_worktree("feature");- std::fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();+#[rstest]+fn test_push_to_default_branch(mut repo: TestRepo) {+ repo.add_main_worktree();- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Push without specifying target (should use default branch)snapshot_push("push_to_default", &repo, &[], Some(&feature_wt));}-#[test]-fn test_push_with_dirty_target() {- let mut repo = TestRepo::new();-+#[rstest]+fn test_push_with_dirty_target(mut repo: TestRepo) {// Make main worktree (repo root) dirty with a conflicting filestd::fs::write(repo.root_path().join("conflict.txt"), "old content").unwrap();- let feature_wt = repo.add_worktree("feature");- std::fs::write(feature_wt.join("conflict.txt"), "new content").unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "conflict.txt"])- .current_dir(&feature_wt)- .output()- .unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Add conflict file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "conflict.txt",+ "new content",+ "Add conflict file",+ );// Try to push (should fail due to conflicting changes)snapshot_push(@@ -175,29 +105,17 @@ fn test_push_with_dirty_target() {);}-#[test]-fn test_push_dirty_target_autostash() {- let mut repo = TestRepo::new();-+#[rstest]+fn test_push_dirty_target_autostash(mut repo: TestRepo) {// Make main worktree (repo root) dirty with a non-conflicting filestd::fs::write(repo.root_path().join("notes.txt"), "temporary notes").unwrap();- let feature_wt = repo.add_worktree("feature");- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Push should succeed by auto-stashing the non-conflicting target changessnapshot_push(@@ -226,53 +144,28 @@ fn test_push_dirty_target_autostash() {);}-#[test]-fn test_push_error_not_fast_forward() {- let mut repo = TestRepo::new();-+#[rstest]+fn test_push_error_not_fast_forward(mut repo: TestRepo) {// Create feature branch from initial commitlet feature_wt = repo.add_worktree("feature");// Make a commit in the main worktree (repo root) and push it- 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", "Main commit"])- .current_dir(repo.root_path())- .output()- .unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["push", "origin", "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ // Note: Must match original file layout for snapshot consistency+ repo.commit_in_worktree(+ repo.root_path(),+ "main-file.txt",+ "main content",+ "Main commit",+ );+ repo.push_branch("main");// Make a commit in feature (which doesn't have main's commit)- 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", "Feature commit"])- .current_dir(&feature_wt)- .output()- .unwrap();+ repo.commit_in_worktree(+ &feature_wt,+ "feature.txt",+ "feature content",+ "Feature commit",+ );// Try to push feature to main (should fail - main has commits not in feature)snapshot_push(@@ -283,27 +176,10 @@ fn test_push_error_not_fast_forward() {);}-#[test]-fn test_push_error_with_merge_commits() {- let mut repo = TestRepo::new();-- // Create feature branch- let feature_wt = repo.add_worktree("feature");- std::fs::write(feature_wt.join("file1.txt"), "content1").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", "Commit 1"])- .current_dir(&feature_wt)- .output()- .unwrap();+#[rstest]+fn test_push_error_with_merge_commits(mut repo: TestRepo) {+ // Create feature branch with initial commit+ let feature_wt = repo.add_worktree_with_commit("feature", "file1.txt", "content1", "Commit 1");// Create another branch for merginglet mut cmd = Command::new("git");@@ -313,21 +189,7 @@ fn test_push_error_with_merge_commits() {.output().unwrap();- std::fs::write(feature_wt.join("file2.txt"), "content2").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", "Commit 2"])- .current_dir(&feature_wt)- .output()- .unwrap();+ 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");@@ -353,27 +215,10 @@ fn test_push_error_with_merge_commits() {);}-#[test]-fn test_push_with_merge_commits_allowed() {- let mut repo = TestRepo::new();-- // Create feature branch- let feature_wt = repo.add_worktree("feature");- std::fs::write(feature_wt.join("file1.txt"), "content1").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", "Commit 1"])- .current_dir(&feature_wt)- .output()- .unwrap();+#[rstest]+fn test_push_with_merge_commits_allowed(mut repo: TestRepo) {+ // Create feature branch with initial commit+ let feature_wt = repo.add_worktree_with_commit("feature", "file1.txt", "content1", "Commit 1");// Create another branch for merginglet mut cmd = Command::new("git");@@ -383,21 +228,7 @@ fn test_push_with_merge_commits_allowed() {.output().unwrap();- std::fs::write(feature_wt.join("file2.txt"), "content2").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", "Commit 2"])- .current_dir(&feature_wt)- .output()- .unwrap();+ 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");@@ -423,28 +254,17 @@ fn test_push_with_merge_commits_allowed() {);}-#[test]-fn test_push_no_remote() {- let mut repo = TestRepo::new();- // Deliberately NOT calling setup_remote to test the error case+#[rstest]+fn test_push_no_remote(mut repo: TestRepo) {+ // Note: repo fixture doesn't call setup_remote(), so this tests the "no remote" error case// Create a feature worktree and make a commit- let feature_wt = repo.add_worktree("feature");- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Try to push without specifying target (should fail - no remote to get default branch)snapshot_push("push_no_remote", &repo, &[], Some(&feature_wt));diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rsindex 69af0a86e..7c3cc7775 100644--- a/tests/integration_tests/shell_wrapper.rs+++ b/tests/integration_tests/shell_wrapper.rs@@ -670,6 +670,7 @@ fn exec_through_wrapper_with_env(mod tests {use super::*;+ use crate::common::repo;use rstest::rstest;// ========================================================================@@ -1008,9 +1009,8 @@ approved-commands = [#[case("bash")]#[case("zsh")]// #[case("fish")] // TODO: Fish shell has non-deterministic PTY output ordering- fn test_wrapper_merge_with_pre_merge_success(#[case] shell: &str) {+ fn test_wrapper_merge_with_pre_merge_success(#[case] shell: &str, mut repo: TestRepo) {skip_if_shell_unavailable!(shell);- let mut repo = TestRepo::new();// Create project config with pre-merge validationlet config_dir = repo.root_path().join(".config");@@ -1026,33 +1026,15 @@ test = "echo '✓ All 47 tests passed in 2.3s'".unwrap();repo.commit("Add pre-merge validation");-- // Create a main worktree- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create feature worktree with a commit- let feature_wt = repo.add_worktree("feature");- 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"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature",+ );// Pre-approve commandsfs::write(@@ -1089,9 +1071,8 @@ approved-commands = [#[case("bash")]#[case("zsh")]// #[case("fish")] // TODO: Fish shell has non-deterministic PTY output ordering- fn test_wrapper_merge_with_pre_merge_failure(#[case] shell: &str) {+ fn test_wrapper_merge_with_pre_merge_failure(#[case] shell: &str, mut repo: TestRepo) {skip_if_shell_unavailable!(shell);- let mut repo = TestRepo::new();// Create project config with failing pre-merge validationlet config_dir = repo.root_path().join(".config");@@ -1106,33 +1087,15 @@ test = "echo '✗ Test suite failed: 3 tests failing' && exit 1".unwrap();repo.commit("Add failing pre-merge validation");-- // Create a main worktree- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create feature worktree with a commit- let feature_wt = repo.add_worktree("feature-fail");- 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"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature-fail",+ "feature.txt",+ "feature content",+ "Add feature",+ );// Pre-approve the commandsfs::write(@@ -1168,9 +1131,8 @@ approved-commands = [#[case("bash")]#[case("zsh")]// #[case("fish")] // TODO: Fish shell has non-deterministic PTY output ordering- fn test_wrapper_merge_with_mixed_stdout_stderr(#[case] shell: &str) {+ fn test_wrapper_merge_with_mixed_stdout_stderr(#[case] shell: &str, mut repo: TestRepo) {skip_if_shell_unavailable!(shell);- let mut repo = TestRepo::new();// Copy the fixture script to the test repo to avoid path issues with special characters// (CARGO_MANIFEST_DIR may contain single quotes like worktrunk.'∅' which break shell parsing)@@ -1202,33 +1164,15 @@ check2 = "{} check2 3".unwrap();repo.commit("Add pre-merge validation with mixed output");-- // Create a main worktree- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create feature worktree with a commit- let feature_wt = repo.add_worktree("feature");- 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"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature",+ );// Pre-approve commandsfs::write(@@ -2221,10 +2165,8 @@ approved-commands = ["echo 'cleanup test'"]/// - Pre-merge hooks (test, lint) running before merge////// Source: tests/snapshots/shell_wrapper__tests__readme_example_hooks_pre_merge.snap- #[test]- fn test_readme_example_hooks_pre_merge() {- let mut repo = TestRepo::new();-+ #[rstest]+ fn test_readme_example_hooks_pre_merge(mut repo: TestRepo) {// Create project config with pre-merge hookslet config_dir = repo.root_path().join(".config");fs::create_dir_all(&config_dir).unwrap();@@ -2325,14 +2267,7 @@ fi.output().unwrap();- // Create a worktree for main- let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])- .current_dir(repo.root_path())- .output()- .unwrap();+ repo.add_main_worktree();// Create a feature worktree and make multiple commitslet feature_wt = repo.add_worktree("feature-auth");diff --git a/tests/snapshots/integration__integration_tests__directives__merge_internal_powershell_directive.snap b/tests/snapshots/integration__integration_tests__directives__merge_internal_powershell_directive.snapindex d0392fde1..2dc2b651c 100644--- a/tests/snapshots/integration__integration_tests__directives__merge_internal_powershell_directive.snap+++ b/tests/snapshots/integration__integration_tests__directives__merge_internal_powershell_directive.snap@@ -7,6 +7,7 @@ info:- merge- mainenv:+ APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"COLUMNS: "150"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"@@ -14,10 +15,14 @@ info:GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"GIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""+ HOME: "[TEST_HOME]"LANG: CLC_ALL: C+ PATH: "[PATH]"SOURCE_DATE_EPOCH: "1735776000"+ USERPROFILE: "[TEST_HOME]"WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"---success: trueexit_code: 0@@ -25,8 +30,8 @@ exit_code: 0Set-Location '[PATH]'----- stderr ------🔄 [36mMerging 1 commit to [1mmain[22m @ [2ma3899aa[22m (no commit/squash/rebase needed)[39m-[107m [0m * [33ma3899aa[m Add feature file+🔄 [36mMerging 1 commit to [1mmain[22m @ [2m3cf9bf5[22m (no commit/squash/rebase needed)[39m+[107m [0m * [33m3cf9bf5[m Add feature file[107m [0m feature.txt | 1 [32m+[m[107m [0m 1 file changed, 1 insertion(+)✅ [32mMerged to [1mmain[22m [90m(1 commit, 1 file, [32m+1[39m[39m[90m)[39m[39m