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>
This commit is contained in:
+12
-4
@@ -643,12 +643,20 @@ pub async fn get_diff_for_commit_message(
|
||||
repo_path: &Path,
|
||||
include_unstaged: bool,
|
||||
) -> Result<String> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user