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.rsindex 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.rsindex 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.rsindex 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.rsindex 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.snapindex 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π [36mGenerating squash commit message...[0m[107m [0m [1mfix: update file 1 content[0mβ [32mSquashed @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m fix: update file 1 content[107m [0m file1.txt | 1 [32m+[m[107m [0m file2.txt | 1 [32m+[m[107m [0m 2 files changed, 2 insertions(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m fix: update file 1 contentβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 2 files, [32m+2[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snapindex 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[107m [0m Combined commits:[107m [0m - feat: initial featureβ [32mSquashed @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from main[107m [0m feature.txt | 1 [32m+[m[107m [0m 1 file changed, 1 insertion(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from mainβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 1 file, [32m+1[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --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.snapindex 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π [36mGenerating squash commit message...[0m[107m [0m [1mfix: improve auth validation logic[0mβ [32mSquashed @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m fix: improve auth validation logic[107m [0m auth.txt | 1 [32m+[m[107m [0m 1 file changed, 1 insertion(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m fix: improve auth validation logicβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 1 file, [32m+1[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --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 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π‘ [2mUsing fallback commit message. Run 'wt config --help' for LLM setup guide[0m[107m [0m [1mChanges to dirty.txt[0mβ [32mCommitted changes @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Changes to dirty.txt[107m [0m dirty.txt | 1 [32m+[m[107m [0m 1 file changed, 1 insertion(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Changes to dirty.txtβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 1 file, [32m+1[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --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.snapindex 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π‘ [2mUsing fallback commit message. Run 'wt config --help' for LLM setup guide[0m[107m [0m [1mChanges to newfile.txt[0mβ [32mCommitted changes @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mno-commits-dirty[m[33m)[m Changes to newfile.txt[107m [0m newfile.txt | 1 [32m+[m[107m [0m 1 file changed, 1 insertion(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mno-commits-dirty[m[33m)[m Changes to newfile.txtβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 1 file, [32m+1[0m)π [36mRemoving [1m[36mno-commits-dirty[0m[36m worktree & branch in background[0mdiff --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.snapindex 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π‘ [2mUsing fallback commit message. Run 'wt config --help' for LLM setup guide[0m[107m [0m [1mChanges to feature.txt[0mβ [32mCommitted changes @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Changes to feature.txt[107m [0m feature.txt | 1 [32m+[m[107m [0m 1 file changed, 1 insertion(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Changes to feature.txtβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 1 file, [32m+1[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snapindex 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[107m [0m - fix: update logic[107m [0m - docs: update readmeβ [32mSquashed @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from main[107m [0m file1.txt | 1 [32m+[m[107m [0m file2.txt | 1 [32m+[m[107m [0m file3.txt | 1 [32m+[m[107m [0m 3 files changed, 3 insertions(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from mainβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 3 files, [32m+3[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snapindex 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[107m [0m - feat: new feature[107m [0m - fix: bug fixβ [32mSquashed @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from main[107m [0m file1.txt | 1 [32m+[m[107m [0m file2.txt | 1 [32m+[m[107m [0m 2 files changed, 2 insertions(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from mainβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 2 files, [32m+2[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snapindex 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π [36mGenerating squash commit message...[0m[107m [0m [1mfeat: implement user authentication system[0mβ [32mSquashed @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m feat: implement user authentication system[107m [0m auth.txt | 1 [32m+[m[107m [0m 1 file changed, 1 insertion(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m feat: implement user authentication systemβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 1 file, [32m+1[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --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.snapindex 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[107m [0m - feat: add file 1[107m [0m - feat: add file 2β [32mSquashed @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from main[107m [0m file1.txt | 1 [32m+[m[107m [0m file2.txt | 1 [32m+[m[107m [0m 2 files changed, 2 insertions(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from mainβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 2 files, [32m+2[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snap b/tests/snapshots/integration__integration_tests__merge__merge_with_untracked_files.snapindex 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[107m [0m Combined commits:[107m [0m - feat: add file 1β [32mSquashed @ [2m[SHA][0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)-[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from main[107m [0m file1.txt | 1 [32m+[m[107m [0m untracked1.txt | 1 [32m+[m[107m [0m untracked2.txt | 1 [32m+[m[107m [0m 3 files changed, 3 insertions(+)+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Squash commits from mainβ [32mMerged to [1m[32mmain[0m[0m (1 commit, 3 files, [32m+3[0m)π [36mRemoving [1m[36mfeature[0m[36m worktree & branch in background[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap b/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snapindex 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[107m [0m - Add JWT encoding/decoding with signature verification[107m [0m - Create test suite covering all authentication flowsβ [32mSquashed @ [2m[SHA][0m+[107m [0m auth.rs | 8 [32m++++++++[m+[107m [0m auth_test.rs | 17 [32m+++++++++++++++++[m+[107m [0m jwt.rs | 8 [32m++++++++[m+[107m [0m 3 files changed, 33 insertions(+)π [36mRunning pre-merge [1mtest[0m:[0m[107m [0m [1m[34mcargo[0m test[0mπ [36mRunning pre-merge [1mlint[0m:[0m[107m [0m [1m[34mcargo[0m clippy[0mπ [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature-auth[m[33m)[m feat(auth): Implement JWT authentication system-[107m [0m auth.rs | 8 [32m++++++++[m-[107m [0m auth_test.rs | 17 [32m+++++++++++++++++[m-[107m [0m jwt.rs | 8 [32m++++++++[m-[107m [0m 3 files changed, 33 insertions(+)β [32mMerged to [1m[32mmain[0m[0m (1 commit, 3 files, [32m+33[0m)π [36mRemoving [1m[36mfeature-auth[0m[36m worktree & branch in background[0mπ [36mRunning post-merge [1minstall[0m:[0mdiff --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.snapindex 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[107m [0m Implement login and token refresh endpoints with JWT validation.[107m [0m Includes comprehensive test coverage and input validation.β [32mSquashed @ [2m[SHA][0m+[107m [0m api/auth.py | 31 [32m+++++++++++++++++++++++++++++++[m+[107m [0m tests/test_auth.py | 14 [32m++++++++++++++[m+[107m [0m 2 files changed, 45 insertions(+)π [36mRunning pre-merge [1mtest[0m:[0m[107m [0m [1m[34muv[0m run pytest[0mπ [36mRunning pre-merge [1mlint[0m:[0m[107m [0m [1m[34muv[0m run ruff check[0mπ [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no rebase needed)[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature-auth[m[33m)[m feat(api): Add user authentication endpoints-[107m [0m api/auth.py | 31 [32m+++++++++++++++++++++++++++++++[m-[107m [0m tests/test_auth.py | 14 [32m++++++++++++++[m-[107m [0m 2 files changed, 45 insertions(+)β [32mMerged to [1m[32mmain[0m[0m (1 commit, 2 files, [32m+45[0m)π [36mRemoving [1m[36mfeature-auth[0m[36m worktree & branch in background[0m