Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add repo_with_feature_worktree fixture
Maximilian Roosb661a8e69b5a
diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 5aaf55103..fa7c275a2 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -188,6 +188,31 @@ pub fn repo_with_main_worktree(repo: TestRepo) -> TestRepo {repo}+/// Repo with main worktree and a feature branch with one commit.+///+/// Builds on `repo_with_main_worktree`, adding a "feature" worktree with a+/// single commit. Access the feature worktree path via `repo.worktrees["feature"]`.+///+/// Use directly or with `#[from(repo_with_feature_worktree)]` in rstest:+/// ```ignore+/// #[rstest]+/// fn test_merge(mut repo_with_feature_worktree: TestRepo) {+/// let repo = &mut repo_with_feature_worktree;+/// let feature_wt = &repo.worktrees["feature"];+/// // feature has one commit, ready to merge+/// }+/// ```+#[rstest::fixture]+pub fn repo_with_feature_worktree(mut repo_with_main_worktree: TestRepo) -> TestRepo {+ repo_with_main_worktree.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );+ repo_with_main_worktree+}+/// Merge test setup with a single commit on feature branch.////// Creates a repo with:diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rsindex f00160b40..b8e6c3814 100644--- a/tests/integration_tests/directives.rs+++ b/tests/integration_tests/directives.rs@@ -1,5 +1,6 @@use crate::common::{- TestRepo, repo, repo_with_main_worktree, repo_with_remote, setup_snapshot_settings, wt_command,+ TestRepo, repo, repo_with_feature_worktree, repo_with_remote, setup_snapshot_settings,+ wt_command,};use insta::Settings;use insta_cmd::assert_cmd_snapshot;@@ -201,15 +202,9 @@ fn test_remove_without_internal(repo: TestRepo) {/// Test merge command with internal flag and --no-remove#[rstest]-fn test_merge_internal_no_remove(mut repo_with_main_worktree: TestRepo) {- let repo = &mut repo_with_main_worktree;- // Create a feature worktree and make a commit- let feature_wt = repo.add_worktree_with_commit(- "feature",- "feature.txt",- "feature content",- "Add feature file",- );+fn test_merge_internal_no_remove(mut repo_with_feature_worktree: TestRepo) {+ let repo = &mut repo_with_feature_worktree;+ let feature_wt = &repo.worktrees["feature"];let settings = setup_snapshot_settings(repo);@@ -220,7 +215,7 @@ fn test_merge_internal_no_remove(mut repo_with_main_worktree: TestRepo) {.arg("merge").arg("main").arg("--no-remove")- .current_dir(&feature_wt);+ .current_dir(feature_wt);// Note: Using file snapshot instead of inline because multiline inline snapshots// don't work well with NUL bytes (\0) in the output@@ -231,15 +226,9 @@ fn test_merge_internal_no_remove(mut repo_with_main_worktree: TestRepo) {/// Test merge command with internal flag (removes worktree, emits cd shell script)/// This test verifies that the shell script output is correctly formatted#[rstest]-fn test_merge_internal_remove(mut repo_with_main_worktree: TestRepo) {- let repo = &mut repo_with_main_worktree;- // Create a feature worktree and make a commit- let feature_wt = repo.add_worktree_with_commit(- "feature",- "feature.txt",- "feature content",- "Add feature file",- );+fn test_merge_internal_remove(mut repo_with_feature_worktree: TestRepo) {+ let repo = &mut repo_with_feature_worktree;+ let feature_wt = &repo.worktrees["feature"];let mut settings = setup_snapshot_settings(repo);settings.add_filter(r"cd '[^']+'", "cd '[PATH]'");@@ -250,7 +239,7 @@ fn test_merge_internal_remove(mut repo_with_main_worktree: TestRepo) {cmd.arg("--internal").arg("merge").arg("main")- .current_dir(&feature_wt);+ .current_dir(feature_wt);assert_cmd_snapshot!(cmd);});diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rsindex f6cc51554..d0fe01c4e 100644--- a/tests/integration_tests/list.rs+++ b/tests/integration_tests/list.rs@@ -339,22 +339,12 @@ fn test_list_json_with_metadata(mut repo: TestRepo) {#[rstest]fn test_list_json_tree_matches_main_after_merge(mut repo: TestRepo) {// Create feature branch with a worktree- let feature_path = repo.add_worktree("feature-merged");-- // Make 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", "."])- .current_dir(&feature_path)- .output()- .unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Feature commit"])- .current_dir(&feature_path)- .output()- .unwrap();+ let feature_path = repo.add_worktree_with_commit(+ "feature-merged",+ "feature.txt",+ "feature content",+ "Feature commit",+ );// Make the same commit on main (so trees will match after merge)std::fs::write(repo.root_path().join("feature.txt"), "feature content").unwrap();@@ -704,20 +694,12 @@ fn test_list_with_user_marker(mut repo: TestRepo) {repo.commit_with_age("Initial commit", DAY);// Branch ahead of main with commits and user marker 🤖- let feature_wt = repo.add_worktree("feature-api");- std::fs::write(feature_wt.join("api.rs"), "// API implementation").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "."])- .current_dir(&feature_wt)- .output()- .unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Add REST API endpoints"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let _feature_wt = repo.add_worktree_with_commit(+ "feature-api",+ "api.rs",+ "// API implementation",+ "Add REST API endpoints",+ );// Set user markerlet mut cmd = Command::new("git");repo.configure_git_cmd(&mut cmd);@@ -727,20 +709,12 @@ fn test_list_with_user_marker(mut repo: TestRepo) {.unwrap();// Branch with uncommitted changes and user marker 💬- let review_wt = repo.add_worktree("review-ui");- std::fs::write(review_wt.join("component.tsx"), "// UI component").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "."])- .current_dir(&review_wt)- .output()- .unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Add dashboard component"])- .current_dir(&review_wt)- .output()- .unwrap();+ let review_wt = repo.add_worktree_with_commit(+ "review-ui",+ "component.tsx",+ "// UI component",+ "Add dashboard component",+ );// Add uncommitted changesstd::fs::write(review_wt.join("styles.css"), "/* pending styles */").unwrap();// Set user marker@@ -792,26 +766,12 @@ fn test_list_json_with_git_operation(mut repo: TestRepo) {repo.commit("Initial commit");// Create feature worktree- let feature = repo.add_worktree("feature");-- // Feature makes changes to the file- std::fs::write(- feature.join("conflict.txt"),+ let feature = repo.add_worktree_with_commit(+ "feature",+ "conflict.txt","feature line 1\nfeature line 2\n",- )- .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();+ "Feature changes",+ );// Main makes conflicting changesstd::fs::write(@@ -1861,20 +1821,7 @@ fn test_list_task_dag_full_with_diffs(mut repo: TestRepo) {std::fs::write(feature_a.join("new.txt"), "content").unwrap();// Create another worktree with commits- let feature_b = repo.add_worktree("feature-b");- std::fs::write(feature_b.join("file.txt"), "test").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "."])- .current_dir(&feature_b)- .output()- .unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Test commit"])- .current_dir(&feature_b)- .output()- .unwrap();+ let _feature_b = repo.add_worktree_with_commit("feature-b", "file.txt", "test", "Test commit");snapshot_list_progressive_full("task_dag_full_with_diffs", &repo);}diff --git a/tests/integration_tests/list_column_alignment.rs b/tests/integration_tests/list_column_alignment.rsindex 99eea70ce..6d8019585 100644--- a/tests/integration_tests/list_column_alignment.rs+++ b/tests/integration_tests/list_column_alignment.rs@@ -11,20 +11,7 @@ use rstest::rstest;#[rstest]fn test_status_column_alignment_with_header(mut repo: TestRepo) {// Create worktree with status symbols- let wt = repo.add_worktree("test");- std::fs::write(wt.join("file.txt"), "content").unwrap();-- let mut cmd = std::process::Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "file.txt"])- .current_dir(&wt)- .output()- .unwrap();- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Test"])- .current_dir(&wt)- .output()- .unwrap();+ let wt = repo.add_worktree_with_commit("test", "file.txt", "content", "Test");// Add working tree changes for Status symbolsstd::fs::write(wt.join("untracked.txt"), "new").unwrap();@@ -41,38 +28,14 @@ fn test_status_column_alignment_with_header(mut repo: TestRepo) {#[rstest]fn test_status_column_width_consistency(mut repo: TestRepo) {// Create multiple worktrees with different status symbol combinations- let wt1 = repo.add_worktree("simple");- std::fs::write(wt1.join("file.txt"), "content").unwrap();-- let mut cmd = std::process::Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "file.txt"])- .current_dir(&wt1)- .output()- .unwrap();- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Simple"])- .current_dir(&wt1)- .output()- .unwrap();-- let wt2 = repo.add_worktree("complex");- std::fs::write(wt2.join("file.txt"), "content").unwrap();- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "file.txt"])- .current_dir(&wt2)- .output()- .unwrap();- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Complex"])- .current_dir(&wt2)- .output()- .unwrap();+ let wt1 = repo.add_worktree_with_commit("simple", "file.txt", "content", "Simple");+ let wt2 = repo.add_worktree_with_commit("complex", "file.txt", "content", "Complex");// Add different working tree changesstd::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)diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex 32b3c07a9..4b57d6786 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -1,6 +1,6 @@use crate::common::{TestRepo, make_snapshot_cmd, merge_scenario, merge_scenario_multi_commit, repo,- repo_with_main_worktree, setup_snapshot_settings,+ repo_with_feature_worktree, repo_with_main_worktree, setup_snapshot_settings,};use insta_cmd::assert_cmd_snapshot;use rstest::rstest;@@ -577,20 +577,8 @@ args = ["-c", "cat >/dev/null && echo 'fix: update file 1 content'"]fn test_merge_with_untracked_files(mut repo_with_main_worktree: TestRepo) {let repo = &mut repo_with_main_worktree;// Create a feature worktree with one commit- let 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();+ let feature_wt =+ repo.add_worktree_with_commit("feature", "file1.txt", "content 1", "feat: add file 1");// Add untracked filesstd::fs::write(feature_wt.join("untracked1.txt"), "untracked content 1").unwrap();@@ -622,22 +610,12 @@ fn test_merge_pre_merge_command_success(mut repo: TestRepo) {repo.add_main_worktree();// Create a feature worktree and make 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --force to skip approval promptssnapshot_merge(@@ -661,22 +639,12 @@ fn test_merge_pre_merge_command_failure(mut repo: TestRepo) {repo.add_main_worktree();// Create a feature worktree and make 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --force - pre-merge command should fail and block mergesnapshot_merge(@@ -700,22 +668,12 @@ fn test_merge_pre_merge_command_no_hooks(mut repo: TestRepo) {repo.add_main_worktree();// Create a feature worktree and make 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --no-verify - should skip pre-merge commands and succeedsnapshot_merge(@@ -748,22 +706,12 @@ test = "exit 0"repo.add_main_worktree();// Create a feature worktree and make 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --force - all pre-merge commands should passsnapshot_merge(@@ -793,22 +741,12 @@ fn test_merge_post_merge_command_success(mut repo: TestRepo) {repo.add_main_worktree();// Create a feature worktree and make 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --forcesnapshot_merge(@@ -849,22 +787,12 @@ fn test_merge_post_merge_command_skipped_with_no_verify(mut repo: TestRepo) {repo.add_main_worktree();// Create a feature worktree and make 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --no-verify - hook should be skipped entirelysnapshot_merge(@@ -895,22 +823,12 @@ fn test_merge_post_merge_command_failure(mut repo: TestRepo) {repo.add_main_worktree();// Create a feature worktree and make 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --force - post-merge command should fail but merge should completesnapshot_merge(@@ -944,22 +862,12 @@ deploy = "echo 'Deploying branch {{ branch }}' > deploy.txt"repo.add_main_worktree();// Create a feature worktree and make 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --forcesnapshot_merge(@@ -1129,22 +1037,12 @@ fn test_merge_pre_squash_command_success(mut repo: TestRepo) {repo.add_main_worktree();// Create a feature worktree and make commits- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --force (squashing is now the default)snapshot_merge(@@ -1168,22 +1066,12 @@ fn test_merge_pre_squash_command_failure(mut repo: TestRepo) {repo.add_main_worktree();// Create a feature worktree and make commits- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Merge with --force (squashing is default) - pre-commit command should fail and block mergesnapshot_merge(@@ -1199,22 +1087,12 @@ fn test_merge_no_remote(mut repo: TestRepo) {// Deliberately NOT calling setup_remote to test the error case// Create a feature worktree and make 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 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 without specifying target (should fail - no remote to get default branch)snapshot_merge("merge_no_remote", &repo, &[], Some(&feature_wt));@@ -1851,26 +1729,9 @@ command = "{}"}#[rstest]-fn test_merge_no_commit_with_clean_tree(mut repo_with_main_worktree: TestRepo) {- let repo = &mut repo_with_main_worktree;-- // Create a feature worktree with commits (clean tree)- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+fn test_merge_no_commit_with_clean_tree(mut repo_with_feature_worktree: TestRepo) {+ let repo = &mut repo_with_feature_worktree;+ let feature_wt = &repo.worktrees["feature"];// Merge with --no-commit (should succeed - clean tree)let settings = setup_snapshot_settings(repo);@@ -1879,7 +1740,7 @@ fn test_merge_no_commit_with_clean_tree(mut repo_with_main_worktree: TestRepo) {repo,"merge",&["main", "--no-commit", "--no-remove"],- Some(&feature_wt),+ Some(feature_wt),);assert_cmd_snapshot!(cmd, @r"success: true@@ -1900,22 +1761,12 @@ fn test_merge_no_commit_with_clean_tree(mut repo_with_main_worktree: TestRepo) {#[rstest]fn test_merge_no_commit_with_dirty_tree(mut repo: TestRepo) {// Create a feature worktree with a commit- let feature_wt = repo.add_worktree("feature");- fs::write(feature_wt.join("committed.txt"), "committed content").unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "committed.txt"])- .current_dir(&feature_wt)- .output()- .unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Add committed file"])- .current_dir(&feature_wt)- .output()- .unwrap();+ let feature_wt = repo.add_worktree_with_commit(+ "feature",+ "committed.txt",+ "committed content",+ "Add committed file",+ );// Add uncommitted changesfs::write(feature_wt.join("uncommitted.txt"), "uncommitted content").unwrap();@@ -1939,26 +1790,9 @@ fn test_merge_no_commit_with_dirty_tree(mut repo: TestRepo) {}#[rstest]-fn test_merge_no_commit_no_squash_no_remove_redundant(mut repo_with_main_worktree: TestRepo) {- let repo = &mut repo_with_main_worktree;-- // Create a feature worktree with commits (clean tree)- 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+fn test_merge_no_commit_no_squash_no_remove_redundant(mut repo_with_feature_worktree: TestRepo) {+ let repo = &mut repo_with_feature_worktree;+ let feature_wt = &repo.worktrees["feature"];// Merge with --no-commit --no-squash --no-remove (redundant but valid - should succeed)let settings = setup_snapshot_settings(repo);@@ -1967,7 +1801,7 @@ fn test_merge_no_commit_no_squash_no_remove_redundant(mut repo_with_main_worktrerepo,"merge",&["main", "--no-commit", "--no-squash", "--no-remove"],- Some(&feature_wt),+ Some(feature_wt),);assert_cmd_snapshot!(cmd, @r"success: true@@ -2053,22 +1887,12 @@ fn test_merge_rebase_true_rebase(mut repo: TestRepo) {// Should show "Rebasing onto main..." progress message// Create a feature worktree with a commit- let feature_wt = repo.add_worktree("true-rebase-test");- 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(+ "true-rebase-test",+ "feature.txt",+ "feature content",+ "Add feature",+ );// 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();@@ -2102,22 +1926,12 @@ fn test_merge_primary_on_different_branch(mut repo: TestRepo) {assert_eq!(repo.current_branch(), "develop");// Create a feature worktree and make a commit- let feature_wt = repo.add_worktree("feature-from-develop");- 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-from-develop",+ "feature.txt",+ "feature content",+ "Add feature file",+ );snapshot_merge("merge_primary_on_different_branch",@@ -2171,22 +1985,12 @@ fn test_merge_primary_on_different_branch_dirty(mut repo: TestRepo) {fs::write(repo.root_path().join("file.txt"), "develop local changes").unwrap();// Create a feature worktree and make a commit- let feature_wt = repo.add_worktree("feature-dirty-primary");- 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-dirty-primary",+ "feature.txt",+ "feature content",+ "Add feature file",+ );// Try to merge to main - should fail because primary has uncommitted changes that conflictsnapshot_merge(@@ -2198,26 +2002,9 @@ fn test_merge_primary_on_different_branch_dirty(mut repo: TestRepo) {}#[rstest]-fn test_merge_race_condition_commit_after_push(mut repo_with_main_worktree: TestRepo) {- let repo = &mut repo_with_main_worktree;-- // Create a feature worktree and make 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 file"])- .current_dir(&feature_wt)- .output()- .unwrap();+fn test_merge_race_condition_commit_after_push(mut repo_with_feature_worktree: TestRepo) {+ let repo = &mut repo_with_feature_worktree;+ let feature_wt = repo.worktrees["feature"].clone();// Merge to main (this pushes the branch to main)snapshot_merge(@@ -2750,21 +2537,8 @@ fn test_step_squash_single_commit(mut repo: TestRepo) {// Test "nothing to squash; already a single commit" message// Create a feature worktree with exactly one commit- 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: single commit"])- .current_dir(&feature_wt)- .output()- .expect("Failed to commit");+ let feature_wt =+ repo.add_worktree_with_commit("feature", "file1.txt", "content 1", "feat: single commit");snapshot_step_squash_with_env("step_squash_single_commit",diff --git a/tests/integration_tests/user_hooks.rs b/tests/integration_tests/user_hooks.rsindex e096ed329..7a2ee4433 100644--- a/tests/integration_tests/user_hooks.rs+++ b/tests/integration_tests/user_hooks.rs@@ -13,7 +13,6 @@ use crate::common::{use insta_cmd::assert_cmd_snapshot;use rstest::rstest;use std::fs;-use std::process::Command;use std::thread;use std::time::Duration;@@ -264,22 +263,8 @@ fn snapshot_merge(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&#[cfg_attr(windows, ignore)]fn test_user_pre_merge_hook_executes(mut repo: TestRepo) {// 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.current_dir(&feature_wt)- .args(["add", "."])- .output()- .unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.current_dir(&feature_wt)- .args(["commit", "-m", "Add feature"])- .output()- .unwrap();+ let feature_wt =+ repo.add_worktree_with_commit("feature", "feature.txt", "feature content", "Add feature");// Write user config with pre-merge hookrepo.write_test_config(@@ -305,22 +290,8 @@ check = "echo 'USER_PRE_MERGE_RAN' > user_premerge.txt"#[rstest]fn test_user_pre_merge_hook_failure_blocks_merge(mut repo: TestRepo) {// 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.current_dir(&feature_wt)- .args(["add", "."])- .output()- .unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.current_dir(&feature_wt)- .args(["commit", "-m", "Add feature"])- .output()- .unwrap();+ let feature_wt =+ repo.add_worktree_with_commit("feature", "feature.txt", "feature content", "Add feature");// Write user config with failing pre-merge hookrepo.write_test_config(@@ -343,22 +314,8 @@ check = "exit 1"#[rstest]fn test_user_pre_merge_skipped_with_no_verify(mut repo: TestRepo) {// 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.current_dir(&feature_wt)- .args(["add", "."])- .output()- .unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.current_dir(&feature_wt)- .args(["commit", "-m", "Add feature"])- .output()- .unwrap();+ let feature_wt =+ repo.add_worktree_with_commit("feature", "feature.txt", "feature content", "Add feature");// Write user config with pre-merge hook that creates a markerrepo.write_test_config(@@ -449,22 +406,8 @@ long = "sh -c 'echo start >> hook.log; sleep 30; echo done >> hook.log'"#[cfg_attr(windows, ignore)]fn test_user_post_merge_hook_executes(mut repo: TestRepo) {// 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.current_dir(&feature_wt)- .args(["add", "."])- .output()- .unwrap();-- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.current_dir(&feature_wt)- .args(["commit", "-m", "Add feature"])- .output()- .unwrap();+ let feature_wt =+ repo.add_worktree_with_commit("feature", "feature.txt", "feature content", "Add feature");// Write user config with post-merge hookrepo.write_test_config(diff --git a/tests/snapshots/integration__integration_tests__list_column_alignment__status_column_alignment_check.snap b/tests/snapshots/integration__integration_tests__list_column_alignment__status_column_alignment_check.snapindex 74b8689e3..07c35bbf6 100644--- a/tests/snapshots/integration__integration_tests__list_column_alignment__status_column_alignment_check.snap+++ b/tests/snapshots/integration__integration_tests__list_column_alignment__status_column_alignment_check.snap@@ -5,6 +5,7 @@ info:args:- listenv:+ APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"COLUMNS: "150"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"@@ -12,10 +13,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@@ -24,6 +29,6 @@ exit_code: 0----- stderr -----[1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mPath[0m [1mRemote⇅[0m [1mCommit[0m [1mAge[0m [1mMessage@ [1mmain[0m [2m^[22m [1m./repo[0m [2m23e5a150[0m [2m1d[0m [2mInitial commit-+ test [36m+[39m[36m![39m[36m?[39m [32m+1[0m [31m-1[0m ./repo.test [2m23e5a150[0m [2m1d[0m [2mInitial commit++ test [36m![39m[36m?[39m [2m↑[22m [32m+1[0m [31m-1[0m [32m↑1[0m ./repo.test [2m34f7b918[0m [2m1d[0m [2mTest-⚪ [2mShowing 2 worktrees, 1 with changes+⚪ [2mShowing 2 worktrees, 1 with changes, 1 aheaddiff --git a/tests/snapshots/integration__integration_tests__list_column_alignment__status_column_width_consistency.snap b/tests/snapshots/integration__integration_tests__list_column_alignment__status_column_width_consistency.snapindex 8967093d8..b3744bf13 100644--- a/tests/snapshots/integration__integration_tests__list_column_alignment__status_column_width_consistency.snap+++ b/tests/snapshots/integration__integration_tests__list_column_alignment__status_column_width_consistency.snap@@ -5,6 +5,7 @@ info:args:- listenv:+ APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"COLUMNS: "150"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"@@ -12,10 +13,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@@ -24,7 +29,7 @@ exit_code: 0----- stderr -----[1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mPath[0m [1mRemote⇅[0m [1mCommit[0m [1mAge[0m [1mMessage@ [1mmain[0m [2m^[22m [1m./repo[0m [2m23e5a150[0m [2m1d[0m [2mInitial commit-+ complex [36m![39m[36m?[39m [32m+1[0m [31m-1[0m ./repo.complex [2m23e5a150[0m [2m1d[0m [2mInitial commit-+ simple [36m+[39m [36m?[39m [32m+1[0m [31m-1[0m ./repo.simple [2m23e5a150[0m [2m1d[0m [2mInitial commit++ complex [36m+[39m [36m?[39m [2m↑[22m [32m+1[0m [31m-1[0m [32m↑1[0m ./repo.complex [2ma9d67c29[0m [2m1d[0m [2mComplex++ simple [36m?[39m [2m↑[22m [32m↑1[0m ./repo.simple [2m9ce20ca0[0m [2m1d[0m [2mSimple-⚪ [2mShowing 3 worktrees, 2 with changes+⚪ [2mShowing 3 worktrees, 1 with changes, 2 ahead