Repository navigation
fix(diff): report gitignored files as excluded instead of dropping them - #1805
abhisheksharma2411 wants to merge 4 commits into
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s). |
alibaba#1804 is reported against commit and range, and alibaba#1837 argues workspace mode should not apply .gitignore at all. Asserting this in workspace mode put the two in conflict over a file that is really about reporting, not about which files workspace mode reviews.
|
@abhisheksharma2411 please resolve conflicts |
main added honorGitignore, which stops .gitignore being consulted at all in workspace mode. That is a different question from this PR's: once the mode has decided a path is ignored, main still sends it nowhere -- the else-if has no else, so the diff lands in neither Included nor Excluded and the preview reports a commit that changed nothing. So the two are kept together: honorGitignore still decides whether to match, and the switch decides where the path goes once it has. Verified by dropping the Excluded branch again, which fails TestGetDiffSetWalksChangesetOrderAcrossGitignoreDrop. Also corrected a comment main left behind saying the match is 'still omitted'; it is reported now. Signed-off-by: Abhishek Sharma <[email protected]>
|
rebased on main, sorted out the merge conflicts, and the checks should be green now! Quick heads-up on something to check while you're looking at this code: main's honorGitignore controls whether .gitignore even gets checked, which correctly gets disabled in workspace mode. But that's a separate thing from this PR. Once the mode decides a path is ignored, the else if chain didn't have a final else, so the diff fell through and ended up in neither Included nor Excluded. That made the preview report total_files 0, reviewable 0, excluded 0—basically looking like a totally empty commit. So I kept both fixes. honorGitignore still handles whether we match against .gitignore at all, and the switch statement handles where the path goes once it matches. I actually tested it to make sure it fails for the right reason instead of just guessing—if you drop the Excluded branch again, TestGetDiffSetWalksChangesetOrderAcrossGitignoreDrop breaks. Also cleaned up an old stale comment left in the test that said the match was "still omitted"—since it actually gets reported now, that line needed updating. |
NanaseInori
left a comment
There was a problem hiding this comment.
Reviewed all ten changed-file patches, the ForEachInOrder call sites, #1804 and the current discussion. The issue-number search found no other relevant implementation of this reporting fix. The requirement is concrete: a provider-filtered tracked change should remain visible in preview accounting instead of disappearing from both slices.
The new exclusion branch preserves the Included membership policy, carries the distinct gitignore reason, and records the mixed-stream index and reason together. Preview consumes the supplied reason without advancing its Included-only decision cursor for exclusions. The adjacent mixed-exclusion test and tracked-file commit fixture cover the important accounting boundaries. The current honorGitignore workspace exception is retained. No blocking code defect found.
Minor documentation follow-up: qualify the new FAQ sentence about tracked files being excluded as applying to commit/range modes. The code deliberately does not apply these rules to tracked workspace changes; the general wording could otherwise suggest that users must edit .gitignore even in that mode.
This approval is based on source/test inspection. I did not independently run the reported mutation checks, repository suite, or end-to-end delegate commands; it is not an endorsement of the existing ignore-pattern matching semantics.
This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.
Description
ocr delegate previewcan reporttotal_files: 0, reviewable_count: 0, excluded_count: 0for a commit that git plainly shows as changing files (#1804).The cause is in
partitionDiffs(internal/diff/git.go). A provider-directory exclusion is routed intoDiffSet.Excludedso preview can still account for it, but a.gitignorematch falls into the implicitelseand is appended to neither slice. From there it is invisible: not reviewed, and not counted or named anywhere in the output. There was noExcludeReasonvalue for it either, so there was nothing to report it as.The part that seems worth fixing is that
0 / 0 / 0is also exactly what a commit that changed nothing prints. That's the reading that lets an empty review look like a complete one — the reporter says they now compare OCR's file list againstgit showby hand because of it.So this adds the reason
gitignoreand sends those diffs toExcludedcarrying it.ForEachInOrderhands its callback the reason instead of aproviderExcludedbool, so preview can tell the two kinds apart rather than labelling everythingprovider_directory.This doesn't change which files are gitignored. Whether
!/src/ought to re-include a directory is #1793, and #1794 / #1795 are both on that; neither touchespartitionDiffsor the reason vocabulary, so this should sit alongside either one.Before and after, on the reporter's shape (
.gitignorecontaining/*/):One behaviour change worth flagging
total_filesnow counts gitignored files, so a repository with tracked-but-ignored files will see that number go up. That is the intent — it makes the count agree with what git reports as changed — but it is a visible change to the JSON for anyone asserting on it.Type of Change
How Has This Been Tested?
make testpasses locallyNew test
TestPreviewReportsGitignoredTrackedFilebuilds a repo where the.gitignoreis written after the file is committed, since git applies ignore rules only to untracked paths — the file stays tracked,git diffstill emits it, and OCR is the only layer dropping it.I checked both tests actually fail without the fix rather than just passing alongside it:
provider_directoryinstead ofgitignore→ both tests failTestGetDiffSetWalksChangesetOrderAcrossGitignoreDropneeded updating. Its purpose is theexcludedAtbookkeeping, and the gitignore drop was incidental to that; it now walks two adjacent exclusions of different kinds and asserts the reason for each, which I think makes it a bit stronger than it was.Also ran it end to end against a fixture reproducing the issue, and checked
GOOS=windows go vet,-race, and coverage (91.5% total, above the 90% gate).Checklist
go fmt,go vet)AI/LLM disclosure: I used Claude Code (Claude Opus 5) while working on this. I read and verified every line, ran the mutation checks above to confirm the tests have teeth, and will answer review comments myself.
The FAQ row was added in all five languages to match how docs changes land here. The four translations were drafted with that same tool — happy to take corrections from native speakers on any of them.
Related Issues
closes #1804