Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Enhance display of generated commit messages
Maximilian Roos3c17e0d9a6a2
diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex b30b4d259..9c67de23b 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -2,7 +2,7 @@ use worktrunk::config::{ProjectConfig, WorktrunkConfig};use worktrunk::git::{GitError, Repository};use worktrunk::styling::{AnstyleStyle, CYAN, CYAN_BOLD, ERROR, ERROR_EMOJI, GREEN, GREEN_BOLD, HINT, HINT_EMOJI,- eprintln, println,+ eprintln, format_with_gutter, println,};use super::command_executor::{CommandContext, prepare_project_commands};@@ -180,6 +180,29 @@ fn handle_merge_summary_output(Ok(())}+/// Format a commit message with the first line in bold, ready for gutter display+fn format_commit_message_for_display(message: &str) -> String {+ let bold = AnstyleStyle::new().bold();+ let lines: Vec<&str> = message.lines().collect();++ if lines.is_empty() {+ return String::new();+ }++ // Format first line in bold+ let mut result = format!("{bold}{}{bold:#}", lines[0]);++ // Add remaining lines without bold+ if lines.len() > 1 {+ for line in &lines[1..] {+ result.push('\n');+ result.push_str(line);+ }+ }++ result+}+/// Commit uncommitted changes with LLM-generated messagefn handle_commit_changes(custom_instruction: Option<&str>,@@ -203,9 +226,16 @@ fn handle_commit_changes(}// Generate commit message+ crate::output::progress(format!("π {CYAN}Generating commit message...{CYAN:#}"))+ .map_err(|e| GitError::CommandFailed(e.to_string()))?;+let commit_message =crate::llm::generate_commit_message(custom_instruction, commit_generation_config)?;+ // Display the generated commit message+ let formatted_message = format_commit_message_for_display(&commit_message);+ print!("{}", format_with_gutter(&formatted_message, ""));+// Commitrepo.run_command(&["commit", "-m", &commit_message]).map_err(|e| GitError::CommandFailed(format!("Failed to commit: {}", e)))?;@@ -267,6 +297,11 @@ fn handle_squash(target_branch: &str) -> Result<Option<usize>, GitError> {let subjects = repo.commit_subjects(&range)?;// Load config and generate commit message+ crate::output::progress(format!(+ "π {CYAN}Generating squash commit message...{CYAN:#}"+ ))+ .map_err(|e| GitError::CommandFailed(e.to_string()))?;+let config = WorktrunkConfig::load().map_err(|e| GitError::CommandFailed(format!("Failed to load config: {}", e)))?;let commit_message =@@ -275,6 +310,10 @@ fn handle_squash(target_branch: &str) -> Result<Option<usize>, GitError> {GitError::CommandFailed(format!("Failed to generate commit message: {}", e))})?;+ // Display the generated commit message+ let formatted_message = format_commit_message_for_display(&commit_message);+ print!("{}", format_with_gutter(&formatted_message, ""));+// Reset to merge base (soft reset stages all changes)repo.run_command(&["reset", "--soft", &merge_base]).map_err(|e| GitError::CommandFailed(format!("Failed to reset to merge base: {}", e)))?;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 5778cc8aa..54013636a 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@@ -1,6 +1,5 @@---source: tests/integration_tests/merge.rs-assertion_line: 29info:program: wtargs:@@ -16,16 +15,26 @@ info:GIT_EDITOR: ""LANG: CLC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"+ 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/.tmpACtZUm/test-config.toml---success: trueexit_code: 0----- stdout -----π [36mCommitting uncommitted changes...[0m+π [36mGenerating commit message...[0m+[40m [0m [1mWIP: Auto-commit before merge[0mβ [32mCommitted changes[0mπ [36mSquashing 3 commits into one...[0m+π [36mGenerating squash commit message...[0m+[40m [0m [1mSquash commits from main[0m+[40m [0m+[40m [0m Combined commits:+[40m [0m - feat: add file 1+[40m [0m - feat: add file 2+[40m [0m - WIP: Auto-commit before mergeβ [32mSquashed 3 commits into one[0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 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 25d769f5f..d1fad736b 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@@ -1,6 +1,5 @@---source: tests/integration_tests/merge.rs-assertion_line: 11info:program: wtargs:@@ -15,12 +14,15 @@ info:GIT_EDITOR: ""LANG: CLC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"+ SOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpIMSvd2/test-config.toml---success: trueexit_code: 0----- stdout -----π [36mCommitting uncommitted changes...[0m+π [36mGenerating commit message...[0m+[40m [0m [1mWIP: Auto-commit before merge[0mβ [32mCommitted changes[0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 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 473229f4f..c86a5ca94 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@@ -1,6 +1,5 @@---source: tests/integration_tests/merge.rs-assertion_line: 29info:program: wtargs:@@ -15,14 +14,17 @@ info:GIT_EDITOR: ""LANG: CLC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"+ 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/.tmp2ejS0J/test-config.toml---success: trueexit_code: 0----- stdout -----π [36mCommitting uncommitted changes...[0m+π [36mGenerating commit message...[0m+[40m [0m [1mWIP: Auto-commit before merge[0mβ [32mCommitted changes[0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 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.snapindex dd54e895b..5298e7711 100644--- 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.snap@@ -1,6 +1,5 @@---source: tests/integration_tests/merge.rs-assertion_line: 29info:program: wtargs:@@ -17,14 +16,17 @@ info:GIT_EDITOR: ""LANG: CLC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"+ 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/.tmpPijZbQ/test-config.toml---success: trueexit_code: 0----- stdout -----π [36mCommitting uncommitted changes...[0m+π [36mGenerating commit message...[0m+[40m [0m [1mWIP: Auto-commit before merge[0mβ [32mCommitted changes[0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 2 commits 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 67a82d595..38e817906 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap@@ -1,6 +1,5 @@---source: tests/integration_tests/merge.rs-assertion_line: 11info:program: wtargs:@@ -16,12 +15,20 @@ info:GIT_EDITOR: ""LANG: CLC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"+ SOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsZKkrc/test-config.toml---success: trueexit_code: 0----- stdout -----π [36mSquashing 3 commits into one...[0m+π [36mGenerating squash commit message...[0m+[40m [0m [1mSquash commits from main[0m+[40m [0m+[40m [0m Combined commits:+[40m [0m - feat: add file 1+[40m [0m - fix: update logic+[40m [0m - docs: update readmeβ [32mSquashed 3 commits into one[0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 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 9eccbc98d..6043f0f29 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@@ -1,6 +1,5 @@---source: tests/integration_tests/merge.rs-assertion_line: 29info:program: wtargs:@@ -16,13 +15,20 @@ info:GIT_EDITOR: ""LANG: CLC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"+ SOURCE_DATE_EPOCH: "1761609600"WORKTRUNK_COMMIT_GENERATION__COMMAND: nonexistent-llm-command+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpfuanLT/test-config.toml---success: trueexit_code: 0----- stdout -----π [36mSquashing 2 commits into one...[0m+π [36mGenerating squash commit message...[0m+[40m [0m [1mSquash commits from main[0m+[40m [0m+[40m [0m Combined commits:+[40m [0m - feat: new feature+[40m [0m - fix: bug fixβ [32mSquashed 2 commits into one[0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 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 c0a584c2a..8fbd6533d 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@@ -1,6 +1,5 @@---source: tests/integration_tests/merge.rs-assertion_line: 29info:program: wtargs:@@ -16,15 +15,22 @@ info:GIT_EDITOR: ""LANG: CLC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"+ SOURCE_DATE_EPOCH: "1761609600"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/.tmpxmoIBS/test-config.toml---success: trueexit_code: 0----- stdout -----π [36mSquashing 2 commits into one...[0m+π [36mGenerating squash commit message...[0m+[40m [0m [1mSquash commits from main[0m+[40m [0m+[40m [0m Combined commits:+[40m [0m - feat: add authentication+[40m [0m - fix: handle edge caseβ [32mSquashed 2 commits into one[0mπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 1 commit to [1m[36mmain[0m @ [SHA][0m