Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Show diff stats & commit hashes in output
Maximilian Roos7504c72a49e2
diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 7b67c067c..2e7fe4f28 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -3,8 +3,7 @@ use worktrunk::git::{GitError, GitResultExt, Repository};use worktrunk::styling::{AnstyleStyle, CYAN, CYAN_BOLD, HINT, HINT_EMOJI, format_with_gutter};use super::command_executor::{CommandContext, prepare_project_commands};-use super::worktree::handle_push;-use super::worktree::handle_remove;+use super::worktree::{handle_push, handle_remove, parse_diff_shortstat};use crate::output::execute_command_in_worktree;pub fn handle_merge(@@ -213,7 +212,20 @@ fn commit_with_generated_message() -> Result<(), GitError> {let repo = Repository::current();- crate::output::progress(format!("π {CYAN}{progress_msg}{CYAN:#}"))?;+ // Get diff stats for staged changes+ let diff_shortstat = repo+ .run_command(&["diff", "--staged", "--shortstat"])+ .unwrap_or_default();+ let stats = parse_diff_shortstat(&diff_shortstat);+ let stats_parts = stats.format_summary();++ // Format progress message with stats+ let full_progress_msg = match stats_parts.is_empty() {+ true => progress_msg.to_string(),+ false => format!("{} ({})", progress_msg, stats_parts.join(", ")),+ };++ crate::output::progress(format!("π {CYAN}{full_progress_msg}{CYAN:#}"))?;crate::output::progress(format!("π {CYAN}Generating commit message...{CYAN:#}"))?;let commit_message = crate::llm::generate_commit_message(commit_generation_config)?;@@ -223,8 +235,21 @@ fn commit_with_generated_message(repo.run_command(&["commit", "-m", &commit_message]).git_context("Failed to commit")?;+ // Get commit hash for display+ let commit_hash = repo+ .run_command(&["rev-parse", "--short", "HEAD"])?+ .trim()+ .to_string();+use worktrunk::styling::{GREEN, SUCCESS_EMOJI};- crate::output::success(format!("{SUCCESS_EMOJI} {GREEN}Committed changes{GREEN:#}"))?;+ let success_msg = match stats_parts.is_empty() {+ true => format!("{SUCCESS_EMOJI} {GREEN}Committed changes @ {commit_hash}{GREEN:#}"),+ false => format!(+ "{SUCCESS_EMOJI} {GREEN}Committed changes ({}) @ {commit_hash}{GREEN:#}",+ stats_parts.join(", ")+ ),+ };+ crate::output::success(success_msg)?;Ok(())}@@ -285,12 +310,24 @@ fn handle_squash(}// Either multiple commits OR single commit with staged changes - squash them- crate::output::progress(format!(- "π {CYAN}Squashing {commit_count} commits into one...{CYAN:#}"- ))?;+ // Get diff stats early for display in progress message+ let range = format!("{}..HEAD", merge_base);+ let diff_shortstat = repo+ .run_command(&["diff", "--shortstat", &format!("{}..HEAD", merge_base)])+ .unwrap_or_default();+ let stats = parse_diff_shortstat(&diff_shortstat);+ let stats_parts = stats.format_summary();++ let squash_progress = match stats_parts.is_empty() {+ true => format!("π {CYAN}Squashing {commit_count} commits into 1...{CYAN:#}"),+ false => format!(+ "π {CYAN}Squashing {commit_count} commits into 1 ({})...{CYAN:#}",+ stats_parts.join(", ")+ ),+ };+ crate::output::progress(squash_progress)?;// Get commit subjects for the squash message- let range = format!("{}..HEAD", merge_base);let subjects = repo.commit_subjects(&range)?;// Generate squash commit message@@ -327,11 +364,24 @@ fn handle_squash(repo.run_command(&["commit", "-m", &commit_message]).git_context("Failed to create squash commit")?;+ // Get commit hash for display+ let commit_hash = repo+ .run_command(&["rev-parse", "--short", "HEAD"])?+ .trim()+ .to_string();+// Show success immediately after completing the squashuse worktrunk::styling::{GREEN, SUCCESS_EMOJI};- crate::output::success(format!(- "{SUCCESS_EMOJI} {GREEN}Squashed {commit_count} commits into one{GREEN:#}"- ))?;+ let success_msg = match stats_parts.is_empty() {+ true => format!(+ "{SUCCESS_EMOJI} {GREEN}Squashed {commit_count} commits into 1 @ {commit_hash}{GREEN:#}"+ ),+ false => format!(+ "{SUCCESS_EMOJI} {GREEN}Squashed {commit_count} commits into 1 ({}) @ {commit_hash}{GREEN:#}",+ stats_parts.join(", ")+ ),+ };+ crate::output::success(success_msg)?;Ok(Some(commit_count))}diff --git a/src/commands/worktree.rs b/src/commands/worktree.rsindex c18ddfb67..93b7d0a7a 100644--- a/src/commands/worktree.rs+++ b/src/commands/worktree.rs@@ -670,7 +670,6 @@ pub fn handle_push(// Build success message with statisticsif commit_count > 0 {// Parse shortstat to extract files/insertions/deletions- // Example: " 3 files changed, 45 insertions(+), 12 deletions(-)"let stats = parse_diff_shortstat(&diff_shortstat);let mut summary_parts = vec![format!(@@ -678,20 +677,7 @@ pub fn handle_push(commit_count,if commit_count == 1 { "" } else { "s" })];-- if let Some(files) = stats.files {- summary_parts.push(format!(- "{} file{}",- files,- if files == 1 { "" } else { "s" }- ));- }- if let Some(insertions) = stats.insertions {- summary_parts.push(format!("{ADDITION}+{insertions}{ADDITION:#}"));- }- if let Some(deletions) = stats.deletions {- summary_parts.push(format!("{DELETION}-{deletions}{DELETION:#}"));- }+ summary_parts.extend(stats.format_summary());crate::output::progress(format!("{SUCCESS_EMOJI} {GREEN}{verb} {GREEN_BOLD}{target_branch}{GREEN_BOLD:#} ({}) {GREEN:#}",@@ -707,13 +693,36 @@ pub fn handle_push(}/// Parse git diff --shortstat output-struct DiffStats {- files: Option<usize>,- insertions: Option<usize>,- deletions: Option<usize>,+pub struct DiffStats {+ pub files: Option<usize>,+ pub insertions: Option<usize>,+ pub deletions: Option<usize>,+}++impl DiffStats {+ /// Format stats as a summary string (e.g., "3 files, +45, -12")+ pub fn format_summary(&self) -> Vec<String> {+ let mut parts = Vec::new();++ if let Some(files) = self.files {+ parts.push(format!(+ "{} file{}",+ files,+ if files == 1 { "" } else { "s" }+ ));+ }+ if let Some(insertions) = self.insertions {+ parts.push(format!("{ADDITION}+{insertions}{ADDITION:#}"));+ }+ if let Some(deletions) = self.deletions {+ parts.push(format!("{DELETION}-{deletions}{DELETION:#}"));+ }++ parts+ }}-fn parse_diff_shortstat(output: &str) -> DiffStats {+pub fn parse_diff_shortstat(output: &str) -> DiffStats {let mut stats = DiffStats {files: None,insertions: None,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 ee27c35f7..57dd647fa 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@@ -19,12 +19,12 @@ info:SOURCE_DATE_EPOCH: "1761609600"WORKTRUNK_COMMIT_GENERATION__ARGS: "fix: update file 1 content"WORKTRUNK_COMMIT_GENERATION__COMMAND: echo- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsxGIDb/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpo6rpX4/test-config.toml---success: trueexit_code: 0----- stdout ------π [36mSquashing 2 commits into one...[0m+π [36mSquashing 2 commits into 1 (2 files, [32m+2[0m)...[0mπ [36mGenerating squash commit message...[0m[40m [0m [1mSquash commits from main[0m[40m [0m@@ -32,7 +32,7 @@ exit_code: 0[40m [0m - feat: add file 1[40m [0m - feat: add file 2-β [32mSquashed 2 commits into one[0m+β [32mSquashed 2 commits into 1 (2 files, [32m+2[0m) @ [SHA][0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mMerging 1 commit to [1m[36mmain[0m @ [SHA][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 0e42a0b04..795b64b22 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@@ -16,16 +16,16 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpiaLGjq/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpJYa7yM/test-config.toml---success: trueexit_code: 0----- stdout ------π [36mCommitting uncommitted changes...[0m+π [36mCommitting uncommitted changes... (1 file, [32m+1[0m, [31m-1[0m)[0mπ [36mGenerating commit message...[0m[40m [0m [1mWIP: Auto-commit before merge[0m-β [32mCommitted changes[0m+β [32mCommitted changes (1 file, [32m+1[0m, [31m-1[0m) @ [SHA][0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mMerging 2 commits to [1m[36mmain[0m @ [SHA][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 750e1b68c..8a26a36c1 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@@ -18,16 +18,16 @@ info:SOURCE_DATE_EPOCH: "1761609600"WORKTRUNK_COMMIT_GENERATION__ARGS: "fix: improve auth validation logic"WORKTRUNK_COMMIT_GENERATION__COMMAND: echo- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpZDShBs/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpwSE8M5/test-config.toml---success: trueexit_code: 0----- stdout ------π [36mCommitting uncommitted changes...[0m+π [36mCommitting uncommitted changes... (1 file, [32m+1[0m, [31m-1[0m)[0mπ [36mGenerating commit message...[0m[40m [0m [1mWIP: Auto-commit before merge[0m-β [32mCommitted changes[0m+β [32mCommitted changes (1 file, [32m+1[0m, [31m-1[0m) @ [SHA][0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mMerging 2 commits to [1m[36mmain[0m @ [SHA][0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snapnew file mode 100644index 000000000..d639a386b--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snap@@ -0,0 +1,47 @@+---+source: tests/integration_tests/merge.rs+info:+ program: wt+ args:+ - merge+ - main+ - "-m"+ - Complete the user dashboard feature+ env:+ CLICOLOR_FORCE: "1"+ COLUMNS: "150"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: /dev/null+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ LANG: C+ LC_ALL: C+ SOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_COMMIT_GENERATION__ARGS: "feat: complete user dashboard"+ WORKTRUNK_COMMIT_GENERATION__COMMAND: echo+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpMMJ21f/test-config.toml+---+success: true+exit_code: 0+----- stdout -----+π [36mCommitting uncommitted changes... (1 file, [32m+1[0m, [31m-1[0m)[0m+π [36mGenerating commit message...[0m+[40m [0m [1mWIP: Auto-commit before merge[0m++β [32mCommitted changes (1 file, [32m+1[0m, [31m-1[0m) @ [SHA][0m+π [36mRebasing onto [1m[36mmain[0m...[0m+π [36mMerging 2 commits to [1m[36mmain[0m @ [SHA][0m++* [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m WIP: Auto-commit before merge+* [SHA] feat: start feature++ feature.txt | 1 [32m+[m+ 1 file changed, 1 insertion(+)++β [32mMerged to [1m[32mmain[0m (2 commits, 1 file, [32m+1[0m) [0m+π [36mCleaning up worktree...[0m++β [32mReturned to primary at [REPO][0m++----- stderr -----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 634695ea8..9fc6906f6 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@@ -16,16 +16,16 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsTqLxz/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpulyUF2/test-config.toml---success: trueexit_code: 0----- stdout ------π [36mCommitting uncommitted changes...[0m+π [36mCommitting uncommitted changes... (1 file, [32m+1[0m)[0mπ [36mGenerating commit message...[0m[40m [0m [1mWIP: Auto-commit before merge[0m-β [32mCommitted changes[0m+β [32mCommitted changes (1 file, [32m+1[0m) @ [SHA][0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mMerging 1 commit to [1m[36mmain[0m @ [SHA][0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snapindex 91449dff0..2f3e31235 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap@@ -17,12 +17,12 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpIyfZqM/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpkxZNqZ/test-config.toml---success: trueexit_code: 0----- stdout ------π [36mSquashing 3 commits into one...[0m+π [36mSquashing 3 commits into 1 (3 files, [32m+3[0m)...[0mπ [36mGenerating squash commit message...[0m[40m [0m [1mSquash commits from main[0m[40m [0m@@ -31,7 +31,7 @@ exit_code: 0[40m [0m - fix: update logic[40m [0m - docs: update readme-β [32mSquashed 3 commits into one[0m+β [32mSquashed 3 commits into 1 (3 files, [32m+3[0m) @ [SHA][0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mMerging 1 commit to [1m[36mmain[0m @ [SHA][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 e4bcf2de8..721282430 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@@ -18,12 +18,12 @@ info:LC_ALL: CSOURCE_DATE_EPOCH: "1761609600"WORKTRUNK_COMMIT_GENERATION__COMMAND: nonexistent-llm-command- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpRAZbu4/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpDTLZlD/test-config.toml---success: trueexit_code: 0----- stdout ------π [36mSquashing 2 commits into one...[0m+π [36mSquashing 2 commits into 1 (2 files, [32m+2[0m)...[0mπ [36mGenerating squash commit message...[0m[40m [0m [1mSquash commits from main[0m[40m [0m@@ -31,7 +31,7 @@ exit_code: 0[40m [0m - feat: new feature[40m [0m - fix: bug fix-β [32mSquashed 2 commits into one[0m+β [32mSquashed 2 commits into 1 (2 files, [32m+2[0m) @ [SHA][0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mMerging 1 commit to [1m[36mmain[0m @ [SHA][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 b3706af1b..518b878dc 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@@ -20,12 +20,12 @@ info:WORKTRUNK_COMMIT_GENERATION__ARGS__0: "-c"WORKTRUNK_COMMIT_GENERATION__ARGS__1: "cat >/dev/null && echo 'feat: implement user authentication system'"WORKTRUNK_COMMIT_GENERATION__COMMAND: sh- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpdEJOn8/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpT3OwtL/test-config.toml---success: trueexit_code: 0----- stdout ------π [36mSquashing 2 commits into one...[0m+π [36mSquashing 2 commits into 1 (1 file, [32m+1[0m)...[0mπ [36mGenerating squash commit message...[0m[40m [0m [1mSquash commits from main[0m[40m [0m@@ -33,7 +33,7 @@ exit_code: 0[40m [0m - feat: add authentication[40m [0m - fix: handle edge case-β [32mSquashed 2 commits into one[0m+β [32mSquashed 2 commits into 1 (1 file, [32m+1[0m) @ [SHA][0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mMerging 1 commit to [1m[36mmain[0m @ [SHA][0m