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.rsindex 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.snapindex 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: CLC_ALL: CSOURCE_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: trueexit_code: 0@@ -24,12 +24,12 @@ exit_code: 0π‘ [33mAuto-staging untracked files: dirty.txt[0mπ [36mCommitting with default message...[0m (1 file, [32m+1[0m)π‘ [2mUsing fallback commit message. Run 'wt config help' to configure LLM-generated messages[0m-[40m [0m [1mWIP: Auto-commit before merge[0m+[40m [0m [1mChanges to dirty.txt[0mβ [32mCommitted changes @ [2m[SHA][0mπ [36mMerging 1 commit to [1m[36mmain[0m @ [2m[SHA][0m (no squashing needed, no rebasing needed)-* [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m WIP: Auto-commit before merge+* [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Changes to dirty.txtdirty.txt | 1 [32m+[m1 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.snapindex 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: CLC_ALL: CSOURCE_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: trueexit_code: 0@@ -28,12 +28,12 @@ exit_code: 0π [36mCommitting with default message...[0m (1 file, [32m+1[0m)π‘ [2mUsing fallback commit message. Run 'wt config help' to configure LLM-generated messages[0m-[40m [0m [1mWIP: Auto-commit before merge[0m+[40m [0m [1mChanges to feature.txt[0mβ [32mCommitted changes @ [2m[SHA][0mπ [36mMerging 1 commit to [1m[36mmain[0m @ [2m[SHA][0m (no squashing needed, no rebasing needed)-* [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m WIP: Auto-commit before merge+* [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Changes to feature.txtfeature.txt | 1 [32m+[m1 file changed, 1 insertion(+)