Skip to content

fix(diff): report gitignored files as excluded instead of dropping them - #1805

Open
abhisheksharma2411 wants to merge 4 commits into
alibaba:mainfrom
abhisheksharma2411:fix/1804-report-gitignore-exclusions
Open

abhisheksharma2411 wants to merge 4 commits into
alibaba:mainfrom
abhisheksharma2411:fix/1804-report-gitignore-exclusions

Conversation

@abhisheksharma2411

Copy link
Copy Markdown
Contributor

Description

ocr delegate preview can report total_files: 0, reviewable_count: 0, excluded_count: 0 for 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 into DiffSet.Excluded so preview can still account for it, but a .gitignore match falls into the implicit else and is appended to neither slice. From there it is invisible: not reviewed, and not counted or named anywhere in the output. There was no ExcludeReason value for it either, so there was nothing to report it as.

The part that seems worth fixing is that 0 / 0 / 0 is 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 against git show by hand because of it.

So this adds the reason gitignore and sends those diffs to Excluded carrying it. ForEachInOrder hands its callback the reason instead of a providerExcluded bool, so preview can tell the two kinds apart rather than labelling everything provider_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 touches partitionDiffs or the reason vocabulary, so this should sit alongside either one.

Before and after, on the reporter's shape (.gitignore containing /*/):

before:  total=0  reviewable=0  excluded=0
after:   total=2  reviewable=0  excluded=2
           src/main/java/example/Example.java      -> gitignore
           src/test/java/example/ExampleTest.java  -> gitignore

One behaviour change worth flagging

total_files now 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

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally
  • Manual testing (describe below)

New test TestPreviewReportsGitignoredTrackedFile builds a repo where the .gitignore is written after the file is committed, since git applies ignore rules only to untracked paths — the file stays tracked, git diff still 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:

  • making the gitignore case a no-op again (so it still compiles) → 7 failures
  • reporting the file as provider_directory instead of gitignore → both tests fail

TestGetDiffSetWalksChangesetOrderAcrossGitignoreDrop needed updating. Its purpose is the excludedAt bookkeeping, 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

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ 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.
@lizhengfeng101

Copy link
Copy Markdown
Contributor

@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]>
@abhisheksharma2411

Copy link
Copy Markdown
Contributor Author

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 NanaseInori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
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.

delegate preview returns zero files for changed Java commit and range

3 participants