Skip to content

Commit 2bfd289

Browse files
authored
Fix git diff to compare against HEAD instead of working directory (#1422)
## TL;DR Changed git diff operations to compare against HEAD instead of the working directory, ensuring we correctly identify staged vs unstaged file changes. ## What changed? - Modified `getChangedFilesDetailed` function in `packages/git/src/queries.ts` to use `git.diff(["HEAD", "--", file])` instead of `git.diff([file])` - Added checks to skip files when the diff against HEAD is empty (indicating no changes relative to HEAD) - Applied this change to both the unstaged changes section and deleted files section of the diff logic - Wrapped the HEAD diff check in a try-catch block for the deleted files case to handle potential errors gracefully ## How did you test this? Unable to verify testing details from the provided information.
1 parent 17f783b commit 2bfd289

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/git/src/queries.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,9 @@ export async function getChangedFilesDetailed(
499499
continue;
500500
}
501501
try {
502-
const unstaged = await git.diff([file]);
503-
const lines = unstaged.split("\n");
502+
const headDiff = await git.diff(["HEAD", "--", file]);
503+
if (!headDiff.trim()) continue;
504+
const lines = headDiff.split("\n");
504505
const linesAdded = lines.filter(
505506
(l) => l.startsWith("+") && !l.startsWith("+++"),
506507
).length;
@@ -525,6 +526,10 @@ export async function getChangedFilesDetailed(
525526
) {
526527
continue;
527528
}
529+
try {
530+
const headDiff = await git.diff(["HEAD", "--", file]);
531+
if (!headDiff.trim()) continue;
532+
} catch {}
528533
files.push({
529534
path: file,
530535
status: "deleted",

0 commit comments

Comments
 (0)