Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat: Show diffstat after commit/squash

Maximilian Roosc08b04002c83
diff --git a/src/commands/commit.rs b/src/commands/commit.rs
index 123bcf2ad..9c7460da2 100644
--- a/src/commands/commit.rs
+++ b/src/commands/commit.rs
@@ -117,6 +117,9 @@ impl<'a> CommitGenerator<'a> {
"{GREEN}Committed changes @ {green_dim}{commit_hash}{green_dim:#}{GREEN:#}"
))?;
+ // Show detailed diffstat of the commit
+ super::show_diffstat(&repo, "HEAD~1..HEAD")?;
+
Ok(())
}
}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index f7b78471b..3b6206005 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -51,3 +51,34 @@ pub fn format_command_label(command_type: &str, name: Option<&str>) -> String {
None => format!("Running {command_type}"),
}
}
+
+/// Show detailed diffstat for a given commit range.
+///
+/// Displays the diff statistics (file changes, insertions, deletions) in a gutter format.
+/// Used after commit/squash to show what was included in the commit.
+///
+/// # Arguments
+/// * `repo` - The repository to query
+/// * `range` - The commit range to diff (e.g., "HEAD~1..HEAD" or "main..HEAD")
+pub fn show_diffstat(repo: &worktrunk::git::Repository, range: &str) -> anyhow::Result<()> {
+ use worktrunk::styling::format_with_gutter;
+
+ let term_width = crate::display::get_terminal_width();
+ let stat_width = term_width.saturating_sub(worktrunk::styling::GUTTER_OVERHEAD);
+ let diff_stat = repo
+ .run_command(&[
+ "diff",
+ "--color=always",
+ "--stat",
+ &format!("--stat-width={}", stat_width),
+ range,
+ ])?
+ .trim_end()
+ .to_string();
+
+ if !diff_stat.is_empty() {
+ crate::output::gutter(format_with_gutter(&diff_stat, "", None))?;
+ }
+
+ Ok(())
+}
diff --git a/src/commands/standalone.rs b/src/commands/standalone.rs
index e479ebce0..945af2356 100644
--- a/src/commands/standalone.rs
+++ b/src/commands/standalone.rs
@@ -242,6 +242,9 @@ pub fn handle_squash(
"{GREEN}Squashed @ {green_dim}{commit_hash}{green_dim:#}{GREEN:#}"
))?;
+ // Show detailed diffstat of the squashed commit
+ super::show_diffstat(repo, "HEAD~1..HEAD")?;
+
Ok(true)
}
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index 43df2c425..bd848bd4c 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -608,20 +608,13 @@ pub fn handle_push(
])?;
crate::output::gutter(format_with_gutter(&log_output, "", None))?;
- // Show diff statistics with color (use terminal width minus gutter overhead)
- let term_width = crate::display::get_terminal_width();
- let stat_width = term_width.saturating_sub(worktrunk::styling::GUTTER_OVERHEAD);
- let diff_stat = repo.run_command(&[
- "diff",
- "--color=always",
- "--stat",
- &format!("--stat-width={}", stat_width),
- &format!("{}..HEAD", target_branch),
- ])?;
+ // Show diff statistics only if we didn't already show them after commit/squash
+ let already_showed_diffstat = operations
+ .map(|ops| ops.committed || ops.squashed)
+ .unwrap_or(false);
- let diff_stat = diff_stat.trim_end();
- if !diff_stat.is_empty() {
- crate::output::gutter(format_with_gutter(diff_stat, "", None))?;
+ if !already_showed_diffstat {
+ super::show_diffstat(&repo, &format!("{}..HEAD", target_branch))?;
}
}
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap
index 18d2b6032..b9737d6b6 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap
@@ -26,11 +26,11 @@ exit_code: 0
πŸ”„ Generating squash commit message...
  fix: update file 1 content
βœ… Squashed @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) fix: update file 1 content
  file1.txt | 1 +
  file2.txt | 1 +
  2 files changed, 2 insertions(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) fix: update file 1 content
βœ… Merged to main (1 commit, 2 files, +2)
πŸ”„ Removing feature worktree & branch in background
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap
index 078e2bf36..15f4a3f92 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap
@@ -30,10 +30,10 @@ exit_code: 0
  Combined commits:
  - feat: initial feature
βœ… Squashed @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) Squash commits from main
  feature.txt | 1 +
  1 file changed, 1 insertion(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) Squash commits from main
βœ… Merged to main (1 commit, 1 file, +1)
πŸ”„ Removing feature worktree & branch in background
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap
index dda8a541d..e27ef3016 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap
@@ -26,10 +26,10 @@ exit_code: 0
πŸ”„ Generating squash commit message...
  fix: improve auth validation logic
βœ… Squashed @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) fix: improve auth validation logic
  auth.txt | 1 +
  1 file changed, 1 insertion(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) fix: improve auth validation logic
βœ… Merged to main (1 commit, 1 file, +1)
πŸ”„ Removing feature worktree & branch in background
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.snap
index 791b4cfff..80d7bb0a2 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
@@ -27,10 +27,10 @@ exit_code: 0
πŸ’‘ Using fallback commit message. Run 'wt config --help' for LLM setup guide
  Changes to dirty.txt
βœ… Committed changes @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) Changes to dirty.txt
  dirty.txt | 1 +
  1 file changed, 1 insertion(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) Changes to dirty.txt
βœ… Merged to main (1 commit, 1 file, +1)
πŸ”„ Removing feature worktree & branch in background
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
index 7c8d9442b..2a9a88cd9 100644
--- 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
@@ -27,10 +27,10 @@ exit_code: 0
πŸ’‘ Using fallback commit message. Run 'wt config --help' for LLM setup guide
  Changes to newfile.txt
βœ… Committed changes @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> no-commits-dirty) Changes to newfile.txt
  newfile.txt | 1 +
  1 file changed, 1 insertion(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> no-commits-dirty) Changes to newfile.txt
βœ… Merged to main (1 commit, 1 file, +1)
πŸ”„ Removing no-commits-dirty worktree & branch in background
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_success.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_success.snap
index 10889322a..ebe9f8ee1 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_success.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_success.snap
@@ -30,10 +30,10 @@ exit_code: 0
πŸ’‘ Using fallback commit message. Run 'wt config --help' for LLM setup guide
  Changes to feature.txt
βœ… Committed changes @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) Changes to feature.txt
  feature.txt | 1 +
  1 file changed, 1 insertion(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) Changes to feature.txt
βœ… Merged to main (1 commit, 1 file, +1)
πŸ”„ Removing feature worktree & branch in background
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap
index 7dd8dea86..0fa6505ca 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap
@@ -31,12 +31,12 @@ exit_code: 0
  - fix: update logic
  - docs: update readme
βœ… Squashed @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) Squash commits from main
  file1.txt | 1 +
  file2.txt | 1 +
  file3.txt | 1 +
  3 files changed, 3 insertions(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) Squash commits from main
βœ… Merged to main (1 commit, 3 files, +3)
πŸ”„ Removing feature worktree & branch in background
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap
index 510f4622f..18b4d932c 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap
@@ -31,11 +31,11 @@ exit_code: 0
  - feat: new feature
  - fix: bug fix
βœ… Squashed @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) Squash commits from main
  file1.txt | 1 +
  file2.txt | 1 +
  2 files changed, 2 insertions(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) Squash commits from main
βœ… Merged to main (1 commit, 2 files, +2)
πŸ”„ Removing feature worktree & branch in background
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap
index cbeba5529..3f0fd00dd 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap
@@ -25,10 +25,10 @@ exit_code: 0
πŸ”„ Generating squash commit message...
  feat: implement user authentication system
βœ… Squashed @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) feat: implement user authentication system
  auth.txt | 1 +
  1 file changed, 1 insertion(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) feat: implement user authentication system
βœ… Merged to main (1 commit, 1 file, +1)
πŸ”„ Removing feature worktree & branch in background
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_working_tree_creates_backup.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_working_tree_creates_backup.snap
index b0ffdd7e4..3a09d99a3 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_working_tree_creates_backup.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_working_tree_creates_backup.snap
@@ -33,11 +33,11 @@ exit_code: 0
  - feat: add file 1
  - feat: add file 2
βœ… Squashed @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) Squash commits from main
  file1.txt | 1 +
  file2.txt | 1 +
  2 files changed, 2 insertions(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) Squash commits from main
βœ… Merged to main (1 commit, 2 files, +2)
πŸ”„ Removing feature worktree & branch in background
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snap b/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snap
index aef2f1cb6..36a3fcedb 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snap
@@ -35,12 +35,12 @@ exit_code: 0
  Combined commits:
  - feat: add file 1
βœ… Squashed @ [SHA]
-πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
-  * [SHA] (HEAD -> feature) Squash commits from main
  file1.txt | 1 +
  untracked1.txt | 1 +
  untracked2.txt | 1 +
  3 files changed, 3 insertions(+)
+πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
+  * [SHA] (HEAD -> feature) Squash commits from main
βœ… Merged to main (1 commit, 3 files, +3)
πŸ”„ Removing feature worktree & branch in background
diff --git a/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap b/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap
index 32f6c77e4..d2c22d54b 100644
--- a/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap
+++ b/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap
@@ -35,16 +35,16 @@ exit_code: 0
  - Add JWT encoding/decoding with signature verification
  - Create test suite covering all authentication flows
βœ… Squashed @ [SHA]
+  auth.rs | 8 ++++++++
+  auth_test.rs | 17 +++++++++++++++++
+  jwt.rs | 8 ++++++++
+  3 files changed, 33 insertions(+)
πŸ”„ Running pre-merge test:
  cargo test
πŸ”„ Running pre-merge lint:
  cargo clippy
πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
  * [SHA] (HEAD -> feature-auth) feat(auth): Implement JWT authentication system
-  auth.rs | 8 ++++++++
-  auth_test.rs | 17 +++++++++++++++++
-  jwt.rs | 8 ++++++++
-  3 files changed, 33 insertions(+)
βœ… Merged to main (1 commit, 3 files, +33)
πŸ”„ Removing feature-auth worktree & branch in background
πŸ”„ Running post-merge install:
diff --git a/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_pre_merge.snap b/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_pre_merge.snap
index ba0b7de04..54fa752c7 100644
--- a/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_pre_merge.snap
+++ b/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_pre_merge.snap
@@ -30,15 +30,15 @@ exit_code: 0
  Implement login and token refresh endpoints with JWT validation.
  Includes comprehensive test coverage and input validation.
βœ… Squashed @ [SHA]
+  api/auth.py | 31 +++++++++++++++++++++++++++++++
+  tests/test_auth.py | 14 ++++++++++++++
+  2 files changed, 45 insertions(+)
πŸ”„ Running pre-merge test:
  uv run pytest
πŸ”„ Running pre-merge lint:
  uv run ruff check
πŸ”„ Merging 1 commit to main @ [SHA] (no rebase needed)
  * [SHA] (HEAD -> feature-auth) feat(api): Add user authentication endpoints
-  api/auth.py | 31 +++++++++++++++++++++++++++++++
-  tests/test_auth.py | 14 ++++++++++++++
-  2 files changed, 45 insertions(+)
βœ… Merged to main (1 commit, 2 files, +45)
πŸ”„ Removing feature-auth worktree & branch in background