Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Add snapshot tests for merge with no commits
Maximilian Roosdf5f8be76183
diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 110c632b6..74c1bfac4 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -273,6 +273,22 @@ impl TestRepo {canonical_path}+ /// Creates a worktree for the main branch (required for merge operations)+ ///+ /// This is a convenience method that creates a worktree for the main branch+ /// in the standard location expected by merge tests. Returns the path to the+ /// created worktree.+ pub fn add_main_worktree(&self) -> PathBuf {+ let main_wt = self.root_path().parent().unwrap().join("test-repo.main-wt");+ let mut cmd = Command::new("git");+ self.configure_git_cmd(&mut cmd);+ cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])+ .current_dir(self.root_path())+ .output()+ .expect("Failed to add worktree");+ main_wt+ }+/// Detach HEAD in the repositorypub fn detach_head(&self) {// Get current commit SHAdiff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex 409fb8083..5d1191fd1 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -2089,3 +2089,41 @@ fn test_merge_no_commit_no_squash_no_remove_redundant() {");});}++#[test]+fn test_merge_no_commits() {+ let mut repo = TestRepo::new();+ repo.commit("Initial commit");+ repo.setup_remote("main");++ // Create a worktree for main+ repo.add_main_worktree();++ // Create a feature worktree with NO commits (just branched from main)+ let feature_wt = repo.add_worktree("no-commits", "no-commits");++ // Merge without any commits - should skip both squashing and rebasing+ snapshot_merge("merge_no_commits", &repo, &["main"], Some(&feature_wt));+}++#[test]+fn test_merge_no_commits_with_changes() {+ let mut repo = TestRepo::new();+ repo.commit("Initial commit");+ repo.setup_remote("main");++ // Create a worktree for main+ repo.add_main_worktree();++ // Create a feature worktree with NO commits but WITH uncommitted changes+ let feature_wt = repo.add_worktree("no-commits-dirty", "no-commits-dirty");+ fs::write(feature_wt.join("newfile.txt"), "new content").expect("Failed to write file");++ // Merge - should commit the changes, skip squashing (only 1 commit), and skip rebasing (at merge base)+ snapshot_merge(+ "merge_no_commits_with_changes",+ &repo,+ &["main"],+ Some(&feature_wt),+ );+}diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_commits.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_commits.snapnew file mode 100644index 000000000..697ff9862--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_commits.snap@@ -0,0 +1,29 @@+---+source: tests/integration_tests/merge.rs+info:+ program: wt+ args:+ - merge+ - main+ 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/.tmpK27W9C/test-config.toml+---+success: true+exit_code: 0+----- stdout -----+[2mNo commits to squash - already at merge base[0m+β [32mMerged to [1m[32mmain[0m[0m+π [36mCleaning up worktree...[0m+β [32mReturned to primary at [1m[32m[REPO][0m[0m++----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_commits_with_changes.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_commits_with_changes.snapnew file mode 100644index 000000000..33642f1d5--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_commits_with_changes.snap@@ -0,0 +1,41 @@+---+source: tests/integration_tests/merge.rs+info:+ program: wt+ args:+ - merge+ - main+ 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/.tmpilqDa4/test-config.toml+---+success: true+exit_code: 0+----- stdout -----+π‘ [33mAuto-staging untracked files: newfile.txt[0m+π [36mCommitting with default message...[0m (1 file, [32m+1[0m)+π‘ [2mUsing fallback commit message. Run 'wt config help' to configure LLM-generated messages[0m+[40m [0m [1mChanges to newfile.txt[0m++β [32mCommitted changes @ [2m[SHA][0m+π [36mMerging 1 commit to [1m[36mmain[0m @ [2m[SHA][0m (no squashing needed, no rebasing needed)++* [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mno-commits-dirty[m[33m)[m Changes to newfile.txt++ newfile.txt | 1 [32m+[m+ 1 file changed, 1 insertion(+)++β [32mMerged to [1m[32mmain[0m (1 commit, 1 file, [32m+1[0m) [0m+π [36mCleaning up worktree...[0m+β [32mReturned to primary at [1m[32m[REPO][0m[0m++----- stderr -----