Skip to content

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.rs
index 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 message
fn 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, ""));
+
// Commit
repo.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.snap
index 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: 29
info:
program: wt
args:
@@ -16,16 +15,26 @@ info:
GIT_EDITOR: ""
LANG: C
LC_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: true
exit_code: 0
----- stdout -----
πŸ”„ Committing uncommitted changes...
+πŸ”„ Generating commit message...
+  WIP: Auto-commit before merge
βœ… Committed changes
πŸ”„ Squashing 3 commits into one...
+πŸ”„ Generating squash commit message...
+  Squash commits from main
+ 
+  Combined commits:
+  - feat: add file 1
+  - feat: add file 2
+  - WIP: Auto-commit before merge
βœ… Squashed 3 commits into one
πŸ”„ Rebasing onto main...
πŸ”„ Pushing 1 commit to main @ [SHA]
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 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: 11
info:
program: wt
args:
@@ -15,12 +14,15 @@ info:
GIT_EDITOR: ""
LANG: C
LC_ALL: C
- SOURCE_DATE_EPOCH: "1704067200"
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpIMSvd2/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
πŸ”„ Committing uncommitted changes...
+πŸ”„ Generating commit message...
+  WIP: Auto-commit before merge
βœ… Committed changes
πŸ”„ Rebasing onto main...
πŸ”„ Pushing 2 commits to main @ [SHA]
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 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: 29
info:
program: wt
args:
@@ -15,14 +14,17 @@ info:
GIT_EDITOR: ""
LANG: C
LC_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: true
exit_code: 0
----- stdout -----
πŸ”„ Committing uncommitted changes...
+πŸ”„ Generating commit message...
+  WIP: Auto-commit before merge
βœ… Committed changes
πŸ”„ Rebasing onto main...
πŸ”„ Pushing 2 commits to main @ [SHA]
diff --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.snap
index 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: 29
info:
program: wt
args:
@@ -17,14 +16,17 @@ info:
GIT_EDITOR: ""
LANG: C
LC_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: true
exit_code: 0
----- stdout -----
πŸ”„ Committing uncommitted changes...
+πŸ”„ Generating commit message...
+  WIP: Auto-commit before merge
βœ… Committed changes
πŸ”„ Rebasing onto main...
πŸ”„ Pushing 2 commits to main @ [SHA]
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 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: 11
info:
program: wt
args:
@@ -16,12 +15,20 @@ info:
GIT_EDITOR: ""
LANG: C
LC_ALL: C
- SOURCE_DATE_EPOCH: "1704067200"
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsZKkrc/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
πŸ”„ Squashing 3 commits into one...
+πŸ”„ Generating squash commit message...
+  Squash commits from main
+ 
+  Combined commits:
+  - feat: add file 1
+  - fix: update logic
+  - docs: update readme
βœ… Squashed 3 commits into one
πŸ”„ Rebasing onto main...
πŸ”„ Pushing 1 commit to main @ [SHA]
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 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: 29
info:
program: wt
args:
@@ -16,13 +15,20 @@ info:
GIT_EDITOR: ""
LANG: C
LC_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: true
exit_code: 0
----- stdout -----
πŸ”„ Squashing 2 commits into one...
+πŸ”„ Generating squash commit message...
+  Squash commits from main
+ 
+  Combined commits:
+  - feat: new feature
+  - fix: bug fix
βœ… Squashed 2 commits into one
πŸ”„ Rebasing onto main...
πŸ”„ Pushing 1 commit to main @ [SHA]
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 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: 29
info:
program: wt
args:
@@ -16,15 +15,22 @@ info:
GIT_EDITOR: ""
LANG: C
LC_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: true
exit_code: 0
----- stdout -----
πŸ”„ Squashing 2 commits into one...
+πŸ”„ Generating squash commit message...
+  Squash commits from main
+ 
+  Combined commits:
+  - feat: add authentication
+  - fix: handle edge case
βœ… Squashed 2 commits into one
πŸ”„ Rebasing onto main...
πŸ”„ Pushing 1 commit to main @ [SHA]