Skip to content

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.rs
index 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 commit
if !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 message
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index 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 changes
snapshot_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.snap
index 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: C
LC_ALL: C
SOURCE_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 -----
πŸ”„ Squashing 3 commits into 1...
πŸ”„ Generating squash commit message...
@@ -31,8 +31,9 @@ exit_code: 1
  - Change 2
  - Revert to initial
+βšͺ No changes after squashing 3 commits (commits resulted in no net changes)
+βœ… Merged to main
+βœ… Returned to primary at [REPO]
+πŸ”„ Removing worktree & branch...
----- stderr -----
-❌ No changes to commit after squashing 3 commits
-
-πŸ’‘ The commits resulted in no net changes (e.g., changes were reverted or already in main)