Skip to content

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.rs
index 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.snap
index 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 -----
-πŸ”„ Generating commit message and committing changes...
-  feat: this should fail
-❌ Failed to commit
-  On branch main
-  nothing to commit, working tree clean
+❌ Nothing to commit