Skip to content

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

Add test fixtures and refactor test infrastructure

Maximilian Roos430a8aa33168
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index fa7c275a2..75efcb48a 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -213,6 +213,86 @@ pub fn repo_with_feature_worktree(mut repo_with_main_worktree: TestRepo) -> Test
repo_with_main_worktree
}
+/// Repo with remote, main worktree, and a feature branch with one commit.
+///
+/// Combines `repo_with_remote` with a main worktree and feature worktree setup.
+/// Access the feature worktree path via `repo.worktrees["feature"]`.
+///
+/// Use for tests that need remote tracking AND a feature branch ready to merge/push.
+/// ```ignore
+/// #[rstest]
+/// fn test_push(mut repo_with_remote_and_feature: TestRepo) {
+/// let repo = &mut repo_with_remote_and_feature;
+/// let feature_wt = &repo.worktrees["feature"];
+/// // Has remote, main worktree, and feature with one commit
+/// }
+/// ```
+#[rstest::fixture]
+pub fn repo_with_remote_and_feature(mut repo_with_remote: TestRepo) -> TestRepo {
+ repo_with_remote.add_main_worktree();
+ repo_with_remote.add_worktree_with_commit(
+ "feature",
+ "feature.txt",
+ "feature content",
+ "Add feature file",
+ );
+ repo_with_remote
+}
+
+/// Repo with primary worktree on a non-default branch and main in separate worktree.
+///
+/// Switches the primary worktree to "develop" branch, then creates a worktree
+/// for the default branch (main). This tests scenarios where the user's primary
+/// checkout is not on the default branch.
+///
+/// Use for merge/switch tests that need to verify behavior when primary != default.
+/// ```ignore
+/// #[rstest]
+/// fn test_merge_primary_not_default(mut repo_with_alternate_primary: TestRepo) {
+/// let repo = &mut repo_with_alternate_primary;
+/// // Primary is on "develop", main is in repo.main-wt
+/// let feature_wt = repo.add_worktree_with_commit("feature", ...);
+/// }
+/// ```
+#[rstest::fixture]
+pub fn repo_with_alternate_primary(repo: TestRepo) -> TestRepo {
+ repo.switch_primary_to("develop");
+ repo.add_main_worktree();
+ repo
+}
+
+/// Repo with main worktree and a feature branch with two commits.
+///
+/// Builds on `repo_with_main_worktree`, adding a "feature" worktree with two
+/// commits (file1.txt and file2.txt). Useful for testing squash merges.
+/// Access the feature worktree path via `repo.worktrees["feature"]`.
+///
+/// ```ignore
+/// #[rstest]
+/// fn test_squash(mut repo_with_multi_commit_feature: TestRepo) {
+/// let repo = &mut repo_with_multi_commit_feature;
+/// let feature_wt = &repo.worktrees["feature"];
+/// // feature has 2 commits, ready to squash-merge
+/// }
+/// ```
+#[rstest::fixture]
+pub fn repo_with_multi_commit_feature(mut repo_with_main_worktree: TestRepo) -> TestRepo {
+ let feature_wt = repo_with_main_worktree.add_worktree("feature");
+ repo_with_main_worktree.commit_in_worktree(
+ &feature_wt,
+ "file1.txt",
+ "content 1",
+ "feat: add file 1",
+ );
+ repo_with_main_worktree.commit_in_worktree(
+ &feature_wt,
+ "file2.txt",
+ "content 2",
+ "feat: add file 2",
+ );
+ repo_with_main_worktree
+}
+
/// Merge test setup with a single commit on feature branch.
///
/// Creates a repo with:
@@ -933,6 +1013,23 @@ impl TestRepo {
worktree_path
}
+ /// Shorthand: adds a "feature" worktree with a canonical commit.
+ ///
+ /// Equivalent to:
+ /// ```ignore
+ /// repo.add_worktree_with_commit("feature", "feature.txt", "feature content", "Add feature file")
+ /// ```
+ ///
+ /// Returns the path to the feature worktree.
+ pub fn add_feature(&mut self) -> PathBuf {
+ self.add_worktree_with_commit(
+ "feature",
+ "feature.txt",
+ "feature content",
+ "Add feature file",
+ )
+ }
+
/// Adds a commit to an existing worktree.
///
/// This writes a file, stages it, and commits it in the specified worktree.
diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rs
index b8e6c3814..d6eba4383 100644
--- a/tests/integration_tests/directives.rs
+++ b/tests/integration_tests/directives.rs
@@ -1,6 +1,6 @@
use crate::common::{
- TestRepo, repo, repo_with_feature_worktree, repo_with_remote, setup_snapshot_settings,
- wt_command,
+ TestRepo, repo, repo_with_feature_worktree, repo_with_remote, repo_with_remote_and_feature,
+ setup_snapshot_settings, wt_command,
};
use insta::Settings;
use insta_cmd::assert_cmd_snapshot;
@@ -39,18 +39,11 @@ fn test_switch_internal_powershell_directive(#[from(repo_with_remote)] mut repo:
/// Test merge with --internal=powershell (switch back to main after merge)
#[rstest]
-fn test_merge_internal_powershell_directive(#[from(repo_with_remote)] mut repo: TestRepo) {
- repo.add_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_powershell_directive(mut repo_with_remote_and_feature: TestRepo) {
+ let repo = &mut repo_with_remote_and_feature;
+ let feature_wt = &repo.worktrees["feature"];
- let mut settings = setup_snapshot_settings(&repo);
+ let mut settings = setup_snapshot_settings(repo);
// Normalize the PowerShell Set-Location path
settings.add_filter(r"Set-Location '[^']+'", "Set-Location '[PATH]'");
@@ -60,7 +53,7 @@ fn test_merge_internal_powershell_directive(#[from(repo_with_remote)] mut repo:
cmd.arg("--internal=powershell")
.arg("merge")
.arg("main")
- .current_dir(&feature_wt);
+ .current_dir(feature_wt);
assert_cmd_snapshot!(cmd);
});
diff --git a/tests/integration_tests/help.rs b/tests/integration_tests/help.rs
index f848043e2..1b37c9426 100644
--- a/tests/integration_tests/help.rs
+++ b/tests/integration_tests/help.rs
@@ -14,6 +14,7 @@
use crate::common::wt_command;
use insta::Settings;
use insta_cmd::assert_cmd_snapshot;
+use rstest::rstest;
fn snapshot_help(test_name: &str, args: &[&str]) {
let mut settings = Settings::clone_current();
@@ -28,149 +29,40 @@ fn snapshot_help(test_name: &str, args: &[&str]) {
});
}
-// =============================================================================
// Root command (wt)
-// =============================================================================
-
-#[test]
-fn help_root_short() {
- snapshot_help("help_root_short", &["-h"]);
-}
-
-#[test]
-fn help_root_long() {
- snapshot_help("help_root_long", &["--help"]);
-}
-
-#[test]
-fn help_no_args() {
- // Running `wt` with no args should show short help and exit 0
- snapshot_help("help_no_args", &[]);
-}
-
-// =============================================================================
+#[rstest]
+#[case("help_root_short", "-h")]
+#[case("help_root_long", "--help")]
+#[case("help_no_args", "")]
// Major commands - short and long variants
-// =============================================================================
-
-#[test]
-fn help_config_short() {
- snapshot_help("help_config_short", &["config", "-h"]);
-}
-
-#[test]
-fn help_config_long() {
- snapshot_help("help_config_long", &["config", "--help"]);
-}
-
-#[test]
-fn help_list_short() {
- snapshot_help("help_list_short", &["list", "-h"]);
-}
-
-#[test]
-fn help_list_long() {
- snapshot_help("help_list_long", &["list", "--help"]);
-}
-
-#[test]
-fn help_switch_short() {
- snapshot_help("help_switch_short", &["switch", "-h"]);
-}
-
-#[test]
-fn help_switch_long() {
- snapshot_help("help_switch_long", &["switch", "--help"]);
-}
-
-#[test]
-fn help_remove_short() {
- snapshot_help("help_remove_short", &["remove", "-h"]);
-}
-
-#[test]
-fn help_remove_long() {
- snapshot_help("help_remove_long", &["remove", "--help"]);
-}
-
-#[test]
-fn help_merge_short() {
- snapshot_help("help_merge_short", &["merge", "-h"]);
-}
-
-#[test]
-fn help_merge_long() {
- snapshot_help("help_merge_long", &["merge", "--help"]);
-}
-
-#[test]
-fn help_step_short() {
- snapshot_help("help_step_short", &["step", "-h"]);
-}
-
-#[test]
-fn help_step_long() {
- snapshot_help("help_step_long", &["step", "--help"]);
-}
-
-// =============================================================================
+#[case("help_config_short", "config -h")]
+#[case("help_config_long", "config --help")]
+#[case("help_list_short", "list -h")]
+#[case("help_list_long", "list --help")]
+#[case("help_switch_short", "switch -h")]
+#[case("help_switch_long", "switch --help")]
+#[case("help_remove_short", "remove -h")]
+#[case("help_remove_long", "remove --help")]
+#[case("help_merge_short", "merge -h")]
+#[case("help_merge_long", "merge --help")]
+#[case("help_step_short", "step -h")]
+#[case("help_step_long", "step --help")]
// Config subcommands (long help only - these are less frequently accessed)
-// =============================================================================
-
-#[test]
-fn help_config_shell() {
- snapshot_help("help_config_shell", &["config", "shell", "--help"]);
-}
-
-#[test]
-fn help_config_create() {
- snapshot_help("help_config_create", &["config", "create", "--help"]);
-}
-
-#[test]
-fn help_config_show() {
- snapshot_help("help_config_show", &["config", "show", "--help"]);
-}
-
-#[test]
-fn help_config_var() {
- snapshot_help("help_config_var", &["config", "var", "--help"]);
-}
-
-#[test]
-fn help_config_var_get() {
- snapshot_help("help_config_var_get", &["config", "var", "get", "--help"]);
-}
-
-#[test]
-fn help_config_var_set() {
- snapshot_help("help_config_var_set", &["config", "var", "set", "--help"]);
-}
-
-#[test]
-fn help_config_var_clear() {
- snapshot_help(
- "help_config_var_clear",
- &["config", "var", "clear", "--help"],
- );
-}
-
-#[test]
-fn help_hook_approvals() {
- snapshot_help("help_hook_approvals", &["hook", "approvals", "--help"]);
-}
-
-#[test]
-fn help_hook_approvals_add() {
- snapshot_help(
- "help_hook_approvals_add",
- &["hook", "approvals", "add", "--help"],
- );
-}
-
-#[test]
-fn help_hook_approvals_clear() {
- snapshot_help(
- "help_hook_approvals_clear",
- &["hook", "approvals", "clear", "--help"],
- );
+#[case("help_config_shell", "config shell --help")]
+#[case("help_config_create", "config create --help")]
+#[case("help_config_show", "config show --help")]
+#[case("help_config_var", "config var --help")]
+#[case("help_config_var_get", "config var get --help")]
+#[case("help_config_var_set", "config var set --help")]
+#[case("help_config_var_clear", "config var clear --help")]
+#[case("help_hook_approvals", "hook approvals --help")]
+#[case("help_hook_approvals_add", "hook approvals add --help")]
+#[case("help_hook_approvals_clear", "hook approvals clear --help")]
+fn test_help(#[case] test_name: &str, #[case] args_str: &str) {
+ let args: Vec<&str> = if args_str.is_empty() {
+ vec![]
+ } else {
+ args_str.split_whitespace().collect()
+ };
+ snapshot_help(test_name, &args);
}
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index 18a0a0c57..a8abb73d2 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -1,6 +1,7 @@
use crate::common::{
- TestRepo, make_snapshot_cmd, merge_scenario, merge_scenario_multi_commit, repo,
- repo_with_feature_worktree, repo_with_main_worktree, setup_snapshot_settings,
+ TestRepo, make_snapshot_cmd, merge_scenario, repo, repo_with_alternate_primary,
+ repo_with_feature_worktree, repo_with_main_worktree, repo_with_multi_commit_feature,
+ setup_snapshot_settings,
};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
@@ -53,24 +54,15 @@ fn test_merge_fast_forward(merge_scenario: (TestRepo, PathBuf)) {
}
#[rstest]
-fn test_merge_when_primary_not_on_default_but_default_has_worktree(mut repo: TestRepo) {
- // Move the primary worktree off main
- repo.switch_primary_to("develop");
-
- // Ensure main still has a worktree (secondary)
- let _main_wt = repo.add_main_worktree();
-
- // Create a feature worktree with a commit
- let feature_wt = repo.add_worktree_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature file",
- );
+fn test_merge_when_primary_not_on_default_but_default_has_worktree(
+ mut repo_with_alternate_primary: TestRepo,
+) {
+ let repo = &mut repo_with_alternate_primary;
+ let feature_wt = repo.add_feature();
snapshot_merge(
"merge_when_primary_not_on_default_but_default_has_worktree",
- &repo,
+ repo,
&["main"],
Some(&feature_wt),
);
@@ -131,12 +123,7 @@ 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_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature file",
- );
+ let feature_wt = repo.add_feature();
// Try to merge (should fail or require actual merge)
snapshot_merge(
@@ -448,15 +435,16 @@ fn test_merge_squash_single_commit(mut repo_with_main_worktree: TestRepo) {
}
#[rstest]
-fn test_merge_no_squash(merge_scenario_multi_commit: (TestRepo, PathBuf)) {
- let (repo, feature_wt) = merge_scenario_multi_commit;
+fn test_merge_no_squash(repo_with_multi_commit_feature: TestRepo) {
+ let repo = &repo_with_multi_commit_feature;
+ let feature_wt = &repo.worktrees["feature"];
// Merge with --no-squash - should NOT squash the commits
snapshot_merge(
"merge_no_squash",
- &repo,
+ repo,
&["main", "--no-squash"],
- Some(&feature_wt),
+ Some(feature_wt),
);
}
@@ -549,8 +537,9 @@ args = ["-c", "cat >/dev/null && echo 'fix: improve auth validation logic'"]
}
#[rstest]
-fn test_merge_auto_commit_and_squash(merge_scenario_multi_commit: (TestRepo, PathBuf)) {
- let (repo, feature_wt) = merge_scenario_multi_commit;
+fn test_merge_auto_commit_and_squash(repo_with_multi_commit_feature: TestRepo) {
+ let repo = &repo_with_multi_commit_feature;
+ let feature_wt = &repo.worktrees["feature"];
// Add uncommitted tracked changes
std::fs::write(feature_wt.join("file1.txt"), "updated content 1").unwrap();
@@ -567,9 +556,9 @@ args = ["-c", "cat >/dev/null && echo 'fix: update file 1 content'"]
// Merge (squashing is default) - should stage uncommitted changes, then squash all commits including the staged changes
snapshot_merge(
"merge_auto_commit_and_squash",
- &repo,
+ repo,
&["main"],
- Some(&feature_wt),
+ Some(feature_wt),
);
}
@@ -608,14 +597,7 @@ fn test_merge_pre_merge_command_success(mut repo: TestRepo) {
// Create a worktree for main
repo.add_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",
- );
+ let feature_wt = repo.add_feature();
// Merge with --force to skip approval prompts
snapshot_merge(
@@ -637,14 +619,7 @@ fn test_merge_pre_merge_command_failure(mut repo: TestRepo) {
// Create a worktree for main
repo.add_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",
- );
+ let feature_wt = repo.add_feature();
// Merge with --force - pre-merge command should fail and block merge
snapshot_merge(
@@ -666,14 +641,7 @@ fn test_merge_pre_merge_command_no_hooks(mut repo: TestRepo) {
// Create a worktree for main
repo.add_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",
- );
+ let feature_wt = repo.add_feature();
// Merge with --no-verify - should skip pre-merge commands and succeed
snapshot_merge(
@@ -704,14 +672,7 @@ test = "exit 0"
// Create a worktree for main
repo.add_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",
- );
+ let feature_wt = repo.add_feature();
// Merge with --force - all pre-merge commands should pass
snapshot_merge(
@@ -737,14 +698,7 @@ fn test_merge_post_merge_command_success(mut repo: TestRepo) {
// Create a worktree for main
repo.add_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",
- );
+ let feature_wt = repo.add_feature();
// Merge with --force
snapshot_merge(
@@ -783,14 +737,7 @@ fn test_merge_post_merge_command_skipped_with_no_verify(mut repo: TestRepo) {
// Create a worktree for main
repo.add_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",
- );
+ let feature_wt = repo.add_feature();
// Merge with --no-verify - hook should be skipped entirely
snapshot_merge(
@@ -819,14 +766,7 @@ fn test_merge_post_merge_command_failure(mut repo: TestRepo) {
// Create a worktree for main
repo.add_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",
- );
+ let feature_wt = repo.add_feature();
// Merge with --force - post-merge command should fail but merge should complete
snapshot_merge(
@@ -856,14 +796,7 @@ deploy = "echo 'Deploying branch {{ branch }}' > deploy.txt"
// Create a worktree for main
repo.add_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",
- );
+ let feature_wt = repo.add_feature();
// Merge with --force
snapshot_merge(
@@ -1025,12 +958,7 @@ 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_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature file",
- );
+ let feature_wt = repo.add_feature();
// Merge with --force (squashing is now the default)
snapshot_merge(
@@ -1052,14 +980,7 @@ fn test_merge_pre_squash_command_failure(mut repo: TestRepo) {
// Create a worktree for main
repo.add_main_worktree();
-
- // Create a feature worktree and make commits
- let feature_wt = repo.add_worktree_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature file",
- );
+ let feature_wt = repo.add_feature();
// Merge with --force (squashing is default) - pre-commit command should fail and block merge
snapshot_merge(
@@ -1071,19 +992,12 @@ fn test_merge_pre_squash_command_failure(mut repo: TestRepo) {
}
#[rstest]
-fn test_merge_no_remote(mut repo: TestRepo) {
+fn test_merge_no_remote(#[from(repo_with_feature_worktree)] 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_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature file",
- );
+ let feature_wt = repo.worktree_path("feature");
// Try to merge without specifying target (should fail - no remote to get default branch)
- snapshot_merge("merge_no_remote", &repo, &[], Some(&feature_wt));
+ snapshot_merge("merge_no_remote", &repo, &[], Some(feature_wt));
}
// README EXAMPLE GENERATION TESTS
@@ -2658,15 +2572,10 @@ fn test_merge_error_uncommitted_changes_with_no_commit(mut repo_with_main_worktr
}
#[rstest]
-fn test_merge_error_conflicting_changes_in_target(mut repo: TestRepo) {
+fn test_merge_error_conflicting_changes_in_target(mut repo_with_alternate_primary: TestRepo) {
// Tests the `conflicting_changes()` error function when target worktree has
// uncommitted changes that overlap with files being pushed
-
- // Switch primary worktree off main so we can create a worktree for main
- repo.switch_primary_to("develop");
-
- // Create a worktree for main (succeeds because we switched primary off main)
- let main_wt = repo.add_main_worktree();
+ let repo = &mut repo_with_alternate_primary;
// Create a feature worktree and commit a change to shared.txt
let feature_wt = repo.add_worktree_with_commit(
@@ -2676,6 +2585,9 @@ fn test_merge_error_conflicting_changes_in_target(mut repo: TestRepo) {
"Add shared.txt on feature",
);
+ // Get the main worktree path (created by repo_with_alternate_primary)
+ let main_wt = repo.root_path().parent().unwrap().join("repo.main-wt");
+
// Now make uncommitted changes to shared.txt in main worktree
// This creates a conflict - we're trying to push changes to shared.txt
// but main has uncommitted changes to the same file
@@ -2688,7 +2600,7 @@ fn test_merge_error_conflicting_changes_in_target(mut repo: TestRepo) {
// Try to merge - should fail because of conflicting uncommitted changes
snapshot_merge(
"merge_error_conflicting_changes",
- &repo,
+ repo,
&["main"],
Some(&feature_wt),
);
diff --git a/tests/integration_tests/push.rs b/tests/integration_tests/push.rs
index 4d722400e..8ef7e30d4 100644
--- a/tests/integration_tests/push.rs
+++ b/tests/integration_tests/push.rs
@@ -1,4 +1,6 @@
-use crate::common::{TestRepo, make_snapshot_cmd, repo, setup_snapshot_settings};
+use crate::common::{
+ TestRepo, make_snapshot_cmd, repo, repo_with_feature_worktree, setup_snapshot_settings,
+};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
use std::process::Command;
@@ -41,30 +43,18 @@ fn test_push_not_fast_forward(mut repo: TestRepo) {
);
// 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",
- );
+ let feature_wt = repo.add_feature();
// Try to push from feature to main (should fail - not fast-forward)
snapshot_push("push_not_fast_forward", &repo, &["main"], Some(&feature_wt));
}
#[rstest]
-fn test_push_to_default_branch(mut repo: TestRepo) {
- repo.add_main_worktree();
-
- let feature_wt = repo.add_worktree_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature file",
- );
+fn test_push_to_default_branch(#[from(repo_with_feature_worktree)] repo: TestRepo) {
+ let feature_wt = repo.worktree_path("feature");
// Push without specifying target (should use default branch)
- snapshot_push("push_to_default", &repo, &[], Some(&feature_wt));
+ snapshot_push("push_to_default", &repo, &[], Some(feature_wt));
}
#[rstest]
@@ -110,12 +100,7 @@ fn test_push_dirty_target_autostash(mut repo: TestRepo) {
// Make main worktree (repo root) dirty with a non-conflicting file
std::fs::write(repo.root_path().join("notes.txt"), "temporary notes").unwrap();
- let feature_wt = repo.add_worktree_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature file",
- );
+ let feature_wt = repo.add_feature();
// Push should succeed by auto-stashing the non-conflicting target changes
snapshot_push(
@@ -255,17 +240,10 @@ fn test_push_with_merge_commits_allowed(mut repo: TestRepo) {
}
#[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_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature file",
- );
+fn test_push_no_remote(#[from(repo_with_feature_worktree)] repo: TestRepo) {
+ // Note: repo_with_feature_worktree doesn't call setup_remote(), so this tests the "no remote" error case
+ let feature_wt = repo.worktree_path("feature");
// Try to push without specifying target (should fail - no remote to get default branch)
- snapshot_push("push_no_remote", &repo, &[], Some(&feature_wt));
+ snapshot_push("push_no_remote", &repo, &[], Some(feature_wt));
}
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index 82474a5d5..3ada99151 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -1019,14 +1019,7 @@ test = "echo 'βœ“ All 47 tests passed in 2.3s'"
repo.commit("Add pre-merge validation");
repo.add_main_worktree();
-
- // Create feature worktree with a commit
- let feature_wt = repo.add_worktree_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature",
- );
+ let feature_wt = repo.add_feature();
// Pre-approve commands
fs::write(
@@ -1157,14 +1150,7 @@ check2 = "{} check2 3"
repo.commit("Add pre-merge validation with mixed output");
repo.add_main_worktree();
-
- // Create feature worktree with a commit
- let feature_wt = repo.add_worktree_with_commit(
- "feature",
- "feature.txt",
- "feature content",
- "Add feature",
- );
+ let feature_wt = repo.add_feature();
// Pre-approve commands
fs::write(
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap
index d21e56223..ffd1e11ee 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap
@@ -23,7 +23,7 @@ expression: output.normalized()
[check2] stdout complete
[check2] stderr complete
πŸ”„ Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
-  * [HASH] Add feature
+  * [HASH] Add feature file
  feature.txt | 1 +
  1 file changed, 1 insertion(+)
βœ… Merged to main (1 commit, 1 file, +1)
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap
index d21e56223..ffd1e11ee 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap
@@ -23,7 +23,7 @@ expression: output.normalized()
[check2] stdout complete
[check2] stderr complete
πŸ”„ Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
-  * [HASH] Add feature
+  * [HASH] Add feature file
  feature.txt | 1 +
  1 file changed, 1 insertion(+)
βœ… Merged to main (1 commit, 1 file, +1)
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap
index c3aaf3781..9996d929d 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap
@@ -12,7 +12,7 @@ expression: output.normalized()
  echo 'βœ“ All 47 tests passed in 2.3s'
βœ“ All 47 tests passed in 2.3s
πŸ”„ Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
-  * [HASH] Add feature
+  * [HASH] Add feature file
  feature.txt | 1 +
  1 file changed, 1 insertion(+)
βœ… Merged to main (1 commit, 1 file, +1)
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap
index c3aaf3781..9996d929d 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap
@@ -12,7 +12,7 @@ expression: output.normalized()
  echo 'βœ“ All 47 tests passed in 2.3s'
βœ“ All 47 tests passed in 2.3s
πŸ”„ Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
-  * [HASH] Add feature
+  * [HASH] Add feature file
  feature.txt | 1 +
  1 file changed, 1 insertion(+)
βœ… Merged to main (1 commit, 1 file, +1)
diff --git a/tests/integration_tests/user_hooks.rs b/tests/integration_tests/user_hooks.rs
index 70ca498cb..b8145b8c1 100644
--- a/tests/integration_tests/user_hooks.rs
+++ b/tests/integration_tests/user_hooks.rs
@@ -7,8 +7,8 @@
//! - Skipped together with project hooks via --no-verify
use crate::common::{
- TestRepo, make_snapshot_cmd, repo, setup_snapshot_settings, wait_for_file,
- wait_for_file_content,
+ TestRepo, make_snapshot_cmd, repo, repo_with_feature_worktree, setup_snapshot_settings,
+ wait_for_file, wait_for_file_content,
};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
@@ -251,10 +251,8 @@ fn snapshot_merge(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&
}
#[rstest]
-fn test_user_pre_merge_hook_executes(mut repo: TestRepo) {
- // Create feature worktree with a commit
- let feature_wt =
- repo.add_worktree_with_commit("feature", "feature.txt", "feature content", "Add feature");
+fn test_user_pre_merge_hook_executes(#[from(repo_with_feature_worktree)] repo: TestRepo) {
+ let feature_wt = repo.worktree_path("feature");
// Write user config with pre-merge hook
repo.write_test_config(
@@ -269,7 +267,7 @@ check = "echo 'USER_PRE_MERGE_RAN' > user_premerge.txt"
"user_pre_merge_executes",
&repo,
&["main", "--force", "--no-remove"],
- Some(&feature_wt),
+ Some(feature_wt),
);
// Verify user hook ran
@@ -278,10 +276,10 @@ 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_with_commit("feature", "feature.txt", "feature content", "Add feature");
+fn test_user_pre_merge_hook_failure_blocks_merge(
+ #[from(repo_with_feature_worktree)] repo: TestRepo,
+) {
+ let feature_wt = repo.worktree_path("feature");
// Write user config with failing pre-merge hook
repo.write_test_config(
@@ -297,15 +295,13 @@ check = "exit 1"
"user_pre_merge_failure",
&repo,
&["main", "--force", "--no-remove"],
- Some(&feature_wt),
+ Some(feature_wt),
);
}
#[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_with_commit("feature", "feature.txt", "feature content", "Add feature");
+fn test_user_pre_merge_skipped_with_no_verify(#[from(repo_with_feature_worktree)] repo: TestRepo) {
+ let feature_wt = repo.worktree_path("feature");
// Write user config with pre-merge hook that creates a marker
repo.write_test_config(
@@ -320,7 +316,7 @@ check = "echo 'USER_PRE_MERGE' > user_premerge_marker.txt"
"user_pre_merge_skipped_no_verify",
&repo,
&["main", "--force", "--no-remove", "--no-verify"],
- Some(&feature_wt),
+ Some(feature_wt),
);
// User hook should NOT have run (--no-verify skips all hooks)
@@ -392,10 +388,8 @@ long = "sh -c 'echo start >> hook.log; sleep 30; echo done >> hook.log'"
// ============================================================================
#[rstest]
-fn test_user_post_merge_hook_executes(mut repo: TestRepo) {
- // Create feature worktree with a commit
- let feature_wt =
- repo.add_worktree_with_commit("feature", "feature.txt", "feature content", "Add feature");
+fn test_user_post_merge_hook_executes(#[from(repo_with_feature_worktree)] repo: TestRepo) {
+ let feature_wt = repo.worktree_path("feature");
// Write user config with post-merge hook
repo.write_test_config(
@@ -410,7 +404,7 @@ notify = "echo 'USER_POST_MERGE_RAN' > user_postmerge.txt"
"user_post_merge_executes",
&repo,
&["main", "--force", "--no-remove"],
- Some(&feature_wt),
+ Some(feature_wt),
);
// Post-merge runs in the destination (main) worktree
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_post_merge_executes.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_post_merge_executes.snap
index 79c079339..a1f8cf843 100644
--- a/tests/snapshots/integration__integration_tests__user_hooks__user_post_merge_executes.snap
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_post_merge_executes.snap
@@ -8,6 +8,7 @@ info:
- "--force"
- "--no-remove"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -15,18 +16,22 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
----- stdout -----
----- stderr -----
-πŸ”„ Merging 1 commit to main @ 90f2330 (no commit/squash/rebase needed)
-  * 90f2330 Add feature
+πŸ”„ Merging 1 commit to main @ 3cf9bf5 (no commit/squash/rebase needed)
+  * 3cf9bf5 Add feature file
  feature.txt | 1 +
  1 file changed, 1 insertion(+)
βœ… Merged to main (1 commit, 1 file, +1)
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_executes.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_executes.snap
index 6c11ae3fe..28388cab9 100644
--- a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_executes.snap
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_executes.snap
@@ -8,6 +8,7 @@ info:
- "--force"
- "--no-remove"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -15,10 +16,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
@@ -27,8 +32,8 @@ exit_code: 0
----- stderr -----
πŸ”„ Running user pre-merge check:
  echo 'USER_PRE_MERGE_RAN' > user_premerge.txt
-πŸ”„ Merging 1 commit to main @ 90f2330 (no commit/squash/rebase needed)
-  * 90f2330 Add feature
+πŸ”„ Merging 1 commit to main @ 3cf9bf5 (no commit/squash/rebase needed)
+  * 3cf9bf5 Add feature file
  feature.txt | 1 +
  1 file changed, 1 insertion(+)
βœ… Merged to main (1 commit, 1 file, +1)
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped_no_verify.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped_no_verify.snap
index afe988af3..b930ca272 100644
--- a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped_no_verify.snap
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped_no_verify.snap
@@ -9,6 +9,7 @@ info:
- "--no-remove"
- "--no-verify"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -16,18 +17,22 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
----- stdout -----
----- stderr -----
-πŸ”„ Merging 1 commit to main @ 90f2330 (no commit/squash/rebase needed)
-  * 90f2330 Add feature
+πŸ”„ Merging 1 commit to main @ 3cf9bf5 (no commit/squash/rebase needed)
+  * 3cf9bf5 Add feature file
  feature.txt | 1 +
  1 file changed, 1 insertion(+)
βœ… Merged to main (1 commit, 1 file, +1)