Skip to content

Fix git diff to compare against HEAD instead of working directory#1422

Merged
adboio merged 1 commit intomainfrom
posthog-code/distinguish-staged-and-unstaged-file-changes
Apr 2, 2026
Merged

Fix git diff to compare against HEAD instead of working directory#1422
adboio merged 1 commit intomainfrom
posthog-code/distinguish-staged-and-unstaged-file-changes

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented Apr 1, 2026

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.

@adboio adboio requested a review from a team April 1, 2026 20:25
@adboio adboio marked this pull request as ready for review April 1, 2026 20:25
@adboio adboio merged commit 2bfd289 into main Apr 2, 2026
16 checks passed
@adboio adboio deleted the posthog-code/distinguish-staged-and-unstaged-file-changes branch April 2, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants