Issue #363: Include untracked files in patch generation#417
Issue #363: Include untracked files in patch generation#417Brijeshthummar02 wants to merge 1 commit into
Conversation
|
@romani As you see |
|
problem with this apprach is that it changes git state that will be very unexpected by user, as some files created temporary and should not be added actually, but build add them and such files can be leacked as they are not desirable. we need somthing that does not change git state and just generate pathc file in form we need.. |
I focused on matching the expected patch output and verified that the approach works functionally, but I agree that modifying the git index during build execution is not ideal and can lead to unexpected side effects for users. I’ll try to find an approach that includes untracked files in the generated patch without changing git state or touching the index, including temporary/generated files handling. |
Issue #363
The patch generation was missing newly created untracked files, which meant Checkstyle never validated them. This allowed violations in new files to slip through undetected.
The issue occurred because
git diff HEAD~1 HEADonly compares two commits and doesn't see untracked files at all.What i did is added
git add -N .(intent-to-add) before generating patches, then changed togit diff HEAD~0to compare the working directory against HEAD. This will make new files visible to git diff without actually staging them for commit.Testing
I verified the fix by creating a test git repository with both tracked and untracked files, then compared the patch output before and after the fix. The old approach (
git diff HEAD~1 HEAD) missed the new untracked file completely, while the new approach (git add -N . && git diff HEAD~0) successfully included it. I also verified thatgit add -Ndoesn't actually stage the content, so there's no risk of accidental commits.Here's logs:
Setup
Test 1: Old approach (before fix)
$ git diff HEAD~1 HEAD > patch-old.txt $ cat patch-old.txtResult:
Only shows the committed changes.
NewUntrackedFile.javais completely missing.Test 2: New approach (after fix)
Result:
The new file now appears in the patch with full content. So Checkstyle can validate it.
Test 3: Verify repository safety
Result:
Files remain unstaged after running the command, so they are not included automatically in a normal commit unless explicitly added by the developer.