Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat(dev): Handle empty squash results gracefully
Maximilian Rooscfecb19af59a
diff --git a/src/commands/dev.rs b/src/commands/dev.rsindex 182f2c7fc..692252c8d 100644--- a/src/commands/dev.rs+++ b/src/commands/dev.rs@@ -1,7 +1,9 @@use worktrunk::HookType;use worktrunk::config::{ProjectConfig, WorktrunkConfig};use worktrunk::git::{GitError, GitResultExt, Repository};-use worktrunk::styling::{CYAN, CYAN_BOLD, HINT, HINT_EMOJI, eprintln, format_with_gutter};+use worktrunk::styling::{+ AnstyleStyle, CYAN, CYAN_BOLD, HINT, HINT_EMOJI, eprintln, format_with_gutter,+};use super::merge::{commit_staged_changes, execute_post_merge_commands, format_commit_message_for_display,@@ -281,11 +283,12 @@ pub fn handle_dev_squash(// Check if there are actually any changes to commitif !repo.has_staged_changes()? {- use worktrunk::styling::{ERROR, ERROR_EMOJI, HINT, HINT_EMOJI};- let hint_bold = HINT.bold();- return Err(GitError::CommandFailed(format!(- "{ERROR_EMOJI} {ERROR}No changes to commit after squashing {commit_count} commits{ERROR:#}\n\n{HINT_EMOJI} {HINT}The commits resulted in no net changes (e.g., changes were reverted or already in {hint_bold}{target_branch}{hint_bold:#}{HINT}){HINT:#}"- )));+ use worktrunk::styling::INFO_EMOJI;+ let dim = AnstyleStyle::new().dimmed();+ crate::output::progress(format!(+ "{INFO_EMOJI} {dim}No changes after squashing {commit_count} {commit_text} (commits resulted in no net changes){dim:#}"+ ))?;+ return Ok(false);}// Commit with the generated messagediff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex d1b374c66..6996c5a6b 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -702,7 +702,7 @@ fn test_merge_squash_empty_changes() {.output().expect("Failed to commit");- // Merge (squashing is default) - should fail with helpful error about no net changes+ // Merge (squashing is default) - should succeed even when commits result in no net changessnapshot_merge("merge_squash_empty_changes",&repo,diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_empty_changes.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_empty_changes.snapindex c5750324c..3634d0988 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_empty_changes.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_empty_changes.snap@@ -16,10 +16,10 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpn3l3q5/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpg2vDMU/test-config.toml----success: false-exit_code: 1+success: true+exit_code: 0----- stdout -----π [36mSquashing 3 commits into 1...[0mπ [36mGenerating squash commit message...[0m@@ -31,8 +31,9 @@ exit_code: 1[40m [0m - Change 2[40m [0m - Revert to initial+βͺ [2mNo changes after squashing 3 commits (commits resulted in no net changes)[0m+β [32mMerged to [1m[32mmain[0m[0m+β [32mReturned to primary at [1m[32m[REPO][0m[0m+π [36mRemoving worktree & branch...[0m----- stderr ------β [31mNo changes to commit after squashing 3 commits[0m--π‘ [2mThe commits resulted in no net changes (e.g., changes were reverted or already in [1m[2mmain[0m[2m)[0m