Skip to content

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

Improve fallback commit message when LLM not configured

Maximilian Roos226d892b6f1a
diff --git a/src/llm.rs b/src/llm.rs
index 102a76b09..11c60e952 100644
--- a/src/llm.rs
+++ b/src/llm.rs
@@ -1,4 +1,5 @@
use std::io::Write;
+use std::path::Path;
use std::process::{self, Stdio};
use worktrunk::config::CommitGenerationConfig;
use worktrunk::git::{GitError, Repository};
@@ -218,8 +219,33 @@ pub fn generate_commit_message(
});
}
- // Fallback: simple deterministic commit message (only when not configured)
- Ok("WIP: Auto-commit before merge".to_string())
+ // Fallback: generate a descriptive commit message based on changed files
+ let repo = Repository::current();
+ let file_list = repo.run_command(&["diff", "--staged", "--name-only"])?;
+ let staged_files = file_list
+ .lines()
+ .map(|line| line.trim())
+ .filter(|line| !line.is_empty())
+ .map(|path| {
+ Path::new(path)
+ .file_name()
+ .and_then(|n| n.to_str())
+ .unwrap_or(path)
+ })
+ .collect::<Vec<_>>();
+
+ let message = match staged_files.len() {
+ 0 => "WIP: Changes".to_string(),
+ 1 => format!("Changes to {}", staged_files[0]),
+ 2 => format!("Changes to {} & {}", staged_files[0], staged_files[1]),
+ 3 => format!(
+ "Changes to {}, {} & {}",
+ staged_files[0], staged_files[1], staged_files[2]
+ ),
+ n => format!("Changes to {} files", n),
+ };
+
+ Ok(message)
}
fn try_generate_commit_message(
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 bba880917..d95bdf6d9 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,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp93y4Df/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpIjUcUr/test-config.toml
---
success: true
exit_code: 0
@@ -24,12 +24,12 @@ exit_code: 0
🟑 Auto-staging untracked files: dirty.txt
πŸ”„ Committing with default message... (1 file, +1)
πŸ’‘ Using fallback commit message. Run 'wt config help' to configure LLM-generated messages
-  WIP: Auto-commit before merge
+  Changes to dirty.txt
βœ… Committed changes @ [SHA]
πŸ”„ Merging 1 commit to main @ [SHA] (no squashing needed, no rebasing needed)
-* [SHA] (HEAD -> feature) WIP: Auto-commit before merge
+* [SHA] (HEAD -> feature) Changes to dirty.txt
dirty.txt | 1 +
1 file changed, 1 insertion(+)
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 20cd7a4d5..91a361d51 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
@@ -17,7 +17,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpQpTGwv/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpKhD1De/test-config.toml
---
success: true
exit_code: 0
@@ -28,12 +28,12 @@ exit_code: 0
πŸ”„ Committing with default message... (1 file, +1)
πŸ’‘ Using fallback commit message. Run 'wt config help' to configure LLM-generated messages
-  WIP: Auto-commit before merge
+  Changes to feature.txt
βœ… Committed changes @ [SHA]
πŸ”„ Merging 1 commit to main @ [SHA] (no squashing needed, no rebasing needed)
-* [SHA] (HEAD -> feature) WIP: Auto-commit before merge
+* [SHA] (HEAD -> feature) Changes to feature.txt
feature.txt | 1 +
1 file changed, 1 insertion(+)