Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
test: Merge to non-default target branch
Maximilian Roos83584e655913
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex 7d4076a2c..3ad48d602 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -2216,3 +2216,126 @@ fn test_merge_race_condition_commit_after_push() {"Branch should still exist after failed deletion");}++#[test]+fn test_merge_to_non_default_target() {+ let mut repo = TestRepo::new();+ repo.commit("Initial commit");+ repo.setup_remote("main");++ // Switch back to main and add a commit there+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["switch", "main"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to switch to main");++ std::fs::write(repo.root_path().join("main-file.txt"), "main content")+ .expect("Failed to write main file");+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["add", "main-file.txt"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to add main file");+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", "Add main-specific file"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to commit to main");++ // Create a staging branch from BEFORE the main commit+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ let output = cmd+ .args(["rev-parse", "HEAD~1"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to get parent commit");+ let base_commit = String::from_utf8_lossy(&output.stdout).trim().to_string();++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["switch", "-c", "staging", &base_commit])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to create staging branch");++ // Add a commit to staging to make it different from main+ std::fs::write(repo.root_path().join("staging-file.txt"), "staging content")+ .expect("Failed to write staging file");+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["add", "staging-file.txt"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to add staging file");+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", "Add staging-specific file"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to commit to staging");++ // Create a worktree for staging+ let staging_wt = repo+ .root_path()+ .parent()+ .unwrap()+ .join("test-repo.staging-wt");+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["worktree", "add", staging_wt.to_str().unwrap(), "staging"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to add staging worktree");++ // Create a feature worktree from the base commit (before both main and staging diverged)+ let feature_wt = repo+ .root_path()+ .parent()+ .unwrap()+ .join("test-repo.feature-for-staging");+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args([+ "worktree",+ "add",+ feature_wt.to_str().unwrap(),+ "-b",+ "feature-for-staging",+ &base_commit,+ ])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to add feature worktree");++ std::fs::write(feature_wt.join("feature.txt"), "feature content")+ .expect("Failed to write feature file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["add", "feature.txt"])+ .current_dir(&feature_wt)+ .output()+ .expect("Failed to add feature file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", "Add feature for staging"])+ .current_dir(&feature_wt)+ .output()+ .expect("Failed to commit feature");++ // Merge to staging explicitly (NOT to main)+ // This should rebase onto staging (which has staging-file.txt)+ // NOT onto main (which has main-file.txt)+ snapshot_merge(+ "merge_to_non_default_target",+ &repo,+ &["staging"],+ Some(&feature_wt),+ );+}diff --git a/tests/snapshots/integration__integration_tests__merge__merge_to_non_default_target.snap b/tests/snapshots/integration__integration_tests__merge__merge_to_non_default_target.snapnew file mode 100644index 000000000..3147792f6--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_to_non_default_target.snap@@ -0,0 +1,35 @@+---+source: tests/integration_tests/merge.rs+info:+ program: wt+ args:+ - merge+ - staging+ env:+ CLICOLOR_FORCE: "1"+ COLUMNS: "150"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: /dev/null+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ LANG: C+ LC_ALL: C+ SOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpAyNQBG/test-config.toml+---+success: true+exit_code: 0+----- stdout -----+π [36mRebasing onto [1m[36mstaging[0m[36m...[0m+β [32mRebased onto [1m[32mstaging[0m[0m+π [36mMerging 1 commit to [1m[36mstaging[0m[36m @ [2m[SHA][0m (no commit/squash needed)++[40m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature-for-staging[m[33m)[m Add feature for staging+[40m [0m feature.txt | 1 [32m+[m+[40m [0m 1 file changed, 1 insertion(+)+β [32mMerged to [1m[32mstaging[0m[0m (1 commit, 1 file, [32m+1[0m)+β [32mReturned to primary at [1m[32m[REPO][0m[0m+π [36mRemoving worktree & branch...[0m++----- stderr -----