Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Fail early if nothing is staged before generating commit message
Maximilian Roosb9522bc617d0
diff --git a/src/commands/commit.rs b/src/commands/commit.rsindex 01aef77f7..b133b03a7 100644--- a/src/commands/commit.rs+++ b/src/commands/commit.rs@@ -80,6 +80,11 @@ impl<'a> CommitGenerator<'a> {) -> anyhow::Result<()> {let repo = Repository::current();+ // Fail early if nothing is staged (avoids confusing LLM prompt with empty diff)+ if !repo.has_staged_changes()? {+ anyhow::bail!("Nothing to commit");+ }+let stats_parts = repo.diff_stats_summary(&["diff", "--staged", "--shortstat"]);let changes_type = match stage_mode {diff --git a/tests/snapshots/integration__integration_tests__merge__step_commit_nothing_to_commit.snap b/tests/snapshots/integration__integration_tests__merge__step_commit_nothing_to_commit.snapindex a4fc641e1..800dc9422 100644--- a/tests/snapshots/integration__integration_tests__merge__step_commit_nothing_to_commit.snap+++ b/tests/snapshots/integration__integration_tests__merge__step_commit_nothing_to_commit.snap@@ -26,8 +26,4 @@ exit_code: 1----- stdout ---------- stderr ------π [36mGenerating commit message and committing changes...[39m-[107m [0m [1mfeat: this should fail[22m-β [31mFailed to commit[39m-[107m [0m On branch main-[107m [0m nothing to commit, working tree clean+β [31mNothing to commit[39m