From ffe93a5e6d6f519e428127a0540954bf56e3e295 Mon Sep 17 00:00:00 2001 From: Edward Shao <92406694+exzshao@users.noreply.github.com> Date: Tue, 28 Apr 2026 19:19:25 -0400 Subject: [PATCH] Fix git diff for first commit in commit message autogen (#9291) ## Description What: Fix AI commit message diff generation for brand-new repositories before the first commit. Why: `git diff HEAD` fails when HEAD does not exist yet, which prevented commit message autogen from seeing the changes that would be committed. How: Use the normal `git diff HEAD` path when HEAD exists. Before the first commit, combine staged changes with unstaged edits to staged files, then rely on the existing untracked-file synthesis for files that have not been staged. fixes [APP-4264](https://linear.app/warpdotdev/issue/APP-4264/commit-message-is-not-getting-auto-generated-for-the-first-commit-in-a) ## Server API dependencies None. ## Agent Mode - [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode Co-Authored-By: Oz --- app/src/util/git.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/util/git.rs b/app/src/util/git.rs index 079c9d91..889eccfa 100644 --- a/app/src/util/git.rs +++ b/app/src/util/git.rs @@ -643,12 +643,20 @@ pub async fn get_diff_for_commit_message( repo_path: &Path, include_unstaged: bool, ) -> Result { - let args: &[&str] = if include_unstaged { - &["diff", "HEAD"] + let mut diff = if !include_unstaged { + run_git_command(repo_path, &["diff", "--cached"]).await? + } else if run_git_command(repo_path, &["rev-parse", "--verify", "HEAD"]) + .await + .is_ok() + { + run_git_command(repo_path, &["diff", "HEAD"]).await? } else { - &["diff", "--cached"] + // No HEAD before the first commit. Include staged changes plus + // unstaged edits to staged files; untracked files are added below. + let mut diff = run_git_command(repo_path, &["diff", "--cached"]).await?; + diff.push_str(&run_git_command(repo_path, &["diff"]).await?); + diff }; - let mut diff = run_git_command(repo_path, args).await?; // `git diff HEAD` only shows changes to already-tracked files. New files that // haven't been staged yet are invisible to it, so we synthesise diff hunks for