Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Auto-commit dirty worktrees before merge
Maximilian Roosa22b05de176d
diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 191711e73..515e5b036 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -218,16 +218,10 @@ fn handle_commit_changes()).map_err(|e| GitError::CommandFailed(e.to_string()))?;- // Stage all tracked changes (excludes untracked files)- repo.run_command(&["add", "-u"])+ // Stage all changes including untracked files+ repo.run_command(&["add", "-A"]).map_err(|e| GitError::CommandFailed(format!("Failed to stage changes: {}", e)))?;- // Check if there are staged changes after staging- if !repo.has_staged_changes()? {- // No staged changes means only untracked files exist- return Err(GitError::UntrackedFiles);- }-// Generate commit messagecrate::output::progress(format!("π {CYAN}Generating commit message...{CYAN:#}")).map_err(|e| GitError::CommandFailed(e.to_string()))?;diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 802cd4ce8..d4d468631 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -380,6 +380,15 @@ pub fn setup_snapshot_settings(repo: &TestRepo) -> insta::Settings {let mut settings = insta::Settings::clone_current();settings.set_snapshot_path("../snapshots");+ // Normalize project root path (for test fixtures)+ // This must come before repo path filter to avoid partial matches+ let project_root = std::env::var("CARGO_MANIFEST_DIR")+ .ok()+ .and_then(|p| std::path::PathBuf::from(p).canonicalize().ok());+ if let Some(root) = project_root {+ settings.add_filter(root.to_str().unwrap(), "[PROJECT_ROOT]");+ }+// Normalize pathssettings.add_filter(repo.root_path().to_str().unwrap(), "[REPO]");for (name, path) in &repo.worktrees {diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex e2afba597..000de3053 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -142,46 +142,6 @@ fn test_merge_dirty_working_tree() {);}-#[test]-fn test_merge_dirty_working_tree_error_message() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");-- // Create a feature worktree with uncommitted changes (untracked file)- let feature_wt = repo.add_worktree("feature", "feature");- std::fs::write(feature_wt.join("untracked.txt"), "uncommitted content")- .expect("Failed to write file");-- // Run merge command and capture output- let mut cmd = make_snapshot_cmd(&repo, "merge", &["main"], Some(&feature_wt));- let output = cmd.output().expect("Failed to run command");-- // Should fail with exit code 1- assert!(!output.status.success(), "Command should fail");-- // Convert stderr to string- let stderr = String::from_utf8_lossy(&output.stderr);-- // CRITICAL: Error message must appear (styled with emoji/color)- // Before the fix, this would fail silently with no error message- // After the fix, structured errors are formatted in ONE canonical location (GitError::Display)- // and printed by main.rs (the only place that prints errors)- assert!(- stderr.contains("Working tree has untracked files"),- "Error output must contain the error message. Got stderr:\n{}",- stderr- );-- // Verify we see the error exactly once (not duplicated)- let error_count = stderr.matches("Working tree has untracked files").count();- assert_eq!(- error_count, 1,- "Should see error message exactly once from main.rs via GitError::Display. Got {} occurrences",- error_count- );-}-#[test]fn test_merge_not_fast_forward() {let mut repo = TestRepo::new();diff --git a/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap b/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snapindex bf72b98b5..ac6987708 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap@@ -15,14 +15,30 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpDd1Xdj/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp41DHCB/test-config.toml----success: false-exit_code: 1+success: true+exit_code: 0----- stdout -----π [36mCommitting uncommitted changes...[0m+π [36mGenerating commit message...[0m+[40m [0m [1mWIP: Auto-commit before merge[0m+β [32mCommitted changes[0m+π [36mRebasing onto [1m[36mmain[0m...[0m+π [36mPushing 1 commit to [1m[36mmain[0m @ [SHA][0m------ stderr ------β [31mWorking tree has untracked files[0m+* [33m25858bd[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m WIP: Auto-commit before merge++ dirty.txt | 1 [32m+[m+ 1 file changed, 1 insertion(+)++β [32mPushed to [1m[32mmain[0m (1 commit, 1 file, [32m+1[0m) [0m+π [36mCleaning up worktree...[0m+β [32mRemoved worktree, returned to primary at [REPO][0m-π‘ [2mAdd them with 'git add' and try again[0m+β [32mMerge complete++[2mMerged: [1mfeature[0m β [1mmain[0m[0m+[2mWorktree: Removed[0m[0m++----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_stdout_stderr_ordering.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_stdout_stderr_ordering.snapindex 573fb3d1d..15bdd3e44 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_stdout_stderr_ordering.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_stdout_stderr_ordering.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpzP1ywc/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpgf2x1t/test-config.toml---success: trueexit_code: 0@@ -32,7 +32,7 @@ exit_code: 0π [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 1 commit to [1m[36mmain[0m @ [SHA][0m-* [33m268abe9[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature file+* [33m061819f[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature filefeature.txt | 1 [32m+[m1 file changed, 1 insertion(+)@@ -48,14 +48,14 @@ exit_code: 0----- stderr -----π [36mRunning pre-merge check 'check1':[0m-[40m [0m /Users/maximilian/workspace/worktrunk.stderr-out/tests/fixtures/mixed-output.sh+[40m [0m [PROJECT_ROOT]/tests/fixtures/mixed-output.sh[40m [0m check1 3[check1] stderr line 1[check1] stderr line 2[check1] stderr line 3[check1] stderr completeπ [36mRunning pre-merge check 'check2':[0m-[40m [0m /Users/maximilian/workspace/worktrunk.stderr-out/tests/fixtures/mixed-output.sh+[40m [0m [PROJECT_ROOT]/tests/fixtures/mixed-output.sh[40m [0m check2 3[check2] stderr line 1[check2] stderr line 2