Skip to content

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.rs
index 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 repository
pub fn detach_head(&self) {
// Get current commit SHA
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index 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.snap
new file mode 100644
index 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 -----
+No commits to squash - already at merge base
+βœ… Merged to main
+πŸ”„ Cleaning up worktree...
+βœ… Returned to primary at [REPO]
+
+----- 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.snap
new file mode 100644
index 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 -----
+🟑 Auto-staging untracked files: newfile.txt
+πŸ”„ Committing with default message... (1 file, +1)
+πŸ’‘ Using fallback commit message. Run 'wt config help' to configure LLM-generated messages
+  Changes to newfile.txt
+
+βœ… Committed changes @ [SHA]
+πŸ”„ Merging 1 commit to main @ [SHA] (no squashing needed, no rebasing needed)
+
+* [SHA] (HEAD -> no-commits-dirty) Changes to newfile.txt
+
+ newfile.txt | 1 +
+ 1 file changed, 1 insertion(+)
+
+βœ… Merged to main (1 commit, 1 file, +1) 
+πŸ”„ Cleaning up worktree...
+βœ… Returned to primary at [REPO]
+
+----- stderr -----