Skip to content

Commit ffe93a5

Browse files
exzshaooz-agent
andauthored
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 <oz-agent@warp.dev>
1 parent c0feac2 commit ffe93a5

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

app/src/util/git.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,20 @@ pub async fn get_diff_for_commit_message(
643643
repo_path: &Path,
644644
include_unstaged: bool,
645645
) -> Result<String> {
646-
let args: &[&str] = if include_unstaged {
647-
&["diff", "HEAD"]
646+
let mut diff = if !include_unstaged {
647+
run_git_command(repo_path, &["diff", "--cached"]).await?
648+
} else if run_git_command(repo_path, &["rev-parse", "--verify", "HEAD"])
649+
.await
650+
.is_ok()
651+
{
652+
run_git_command(repo_path, &["diff", "HEAD"]).await?
648653
} else {
649-
&["diff", "--cached"]
654+
// No HEAD before the first commit. Include staged changes plus
655+
// unstaged edits to staged files; untracked files are added below.
656+
let mut diff = run_git_command(repo_path, &["diff", "--cached"]).await?;
657+
diff.push_str(&run_git_command(repo_path, &["diff"]).await?);
658+
diff
650659
};
651-
let mut diff = run_git_command(repo_path, args).await?;
652660

653661
// `git diff HEAD` only shows changes to already-tracked files. New files that
654662
// haven't been staged yet are invisible to it, so we synthesise diff hunks for

0 commit comments

Comments
 (0)