Repository navigation
fix(diff): keep tracked gitignored files in workspace review - #1837
Conversation
Git does not ignore a tracked path, so workspace mode reviews every change from git diff HEAD. Commit and range mode still apply .gitignore. Fixes alibaba#1824
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 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
left a comment
There was a problem hiding this comment.
I think this is right, and I say that as the author of the PR it collides with — so the useful part of this review is probably the collision rather than the approval.
First, the part of your reasoning I checked rather than took on trust. The change is only safe if untracked ignored files are filtered somewhere else, and they are, twice over: untrackedFilesList runs git ls-files --others --exclude-standard, which applies git's own full ignore stack (root and nested .gitignore, .git/info/exclude, the global file), and then filters the result through isPathExcluded again. So dropping the filter in partitionDiffs only changes the tracked side, where git itself never ignores. Worth noting that git's stack is wider than OCR's simplified root-only matching, which is an argument for your direction rather than against it.
The collision. #1805 rewrites the same block in partitionDiffs, so this does not merge cleanly — internal/diff/git.go and internal/diff/git_test.go both conflict, and TestGetDiffSetWalksChangesetOrderAcrossGitignoreDrop is edited by both of us.
The conflict is textual and easy. The part that is not textual is that we disagreed about one scenario. I resolved the merge locally to what I think the composition should be:
switch {
case isProviderDirExcluded(path):
exclude(d, model.ExcludeProviderDirectory)
case honorGitignore && p.isPathExcluded(path, patterns):
exclude(d, model.ExcludeGitignore)
default:
result.Included = append(result.Included, d)
}and then ran my own test against it. It failed:
counts = excluded:0 reviewable:1, want excluded:1 reviewable:0
My TestPreviewReportsGitignoredTrackedFile asserted that a tracked, gitignored, modified file is excluded with a reason in workspace mode. Your PR says that exact file should be reviewed. Same file, opposite expectations.
Having looked at it, I think you are right and my test was wrong. #1804, which #1805 fixes, is reported against delegate preview on a commit and range — not workspace. My fix is about a gitignored path landing in neither the reviewable nor the excluded list, so nothing names it; your change is about which files workspace mode should look at in the first place. Those are different questions, and I had stated mine in the one mode where it stepped on yours.
So I have moved my test to commit mode (8b82b48 on my branch). With that, the two compose: in commit mode a gitignore match is reported as excluded with a reason, in workspace mode it is reviewed. I re-ran it on the merged tree and it passes, and it still fails with my own production change reverted, so it has not gone slack in the move.
Nothing for you to do about #1805 — whichever lands first, I will rebase. Only flagging it so a maintainer merging this does not hit the conflict cold, and so the behavioural difference is on the record rather than being resolved silently by merge order.
One small thing on the PR itself: the description says commit and range mode leave a match "out of both slices", which is true on main today but is the bug #1805 fixes. If #1805 lands first that sentence stops being accurate — might be worth softening it to "unchanged from current behaviour" so it does not read as an intended invariant.
LGTM.
Claude assisted with this review; the merge, the failing run and the untracked-path check are from my own machine.
|
Thanks @abhisheksharma2411 for the careful review and the merge suggestion! I've updated the description to say the commit/range behaviour is "unchanged from current behaviour". Noted on the overlap with #1805 — happy for whichever lands first. |
No text conflicts and no silent breaks. Upstream added no new calls to the helpers the branch moved into internal/model and left the filter algorithms untouched. The internal/diff fixes reach the core commands through the shared code: `ocr core relocate` calls diff.ResolveComment, so it gains the blank-line-free new-side retry (alibaba#1777), and `ocr core diff` goes through GetDiff, so it keeps tracked gitignored files in workspace mode (alibaba#1837) and splits bare "diff --git" headers (alibaba#1691). New file types (.jsonc, HAML/Slim/ERB, EJS/Liquid/Nunjucks) and Scala rules are shared rule data. The branch delta against v1.13.5 is unchanged. Build, vet, make check and the full -race test suite pass; coverage is 91.2%.
Description
Workspace mode reviews currently drop modified tracked files that match
.gitignore(for example a force-addedbin/review_helper.py). Git never ignores a tracked path, so those edits should stay in the review input.This PR makes
partitionDiffsskip the.gitignorefilter in workspace mode. Commit and range mode are unchanged from current behaviour for a path matching.gitignore. Provider directory exclusions still apply in every mode.Type of Change
How Has This Been Tested?
make testpasses locallyinternal/diff/git_test.gocover a tracked file matching.gitignorestaying inIncludedunder workspace mode, and commit/range mode still dropping itGOTOOLCHAIN=go1.26.9, matching.github/workflows/ci.yml):go test(incl. race + coverage ≥90%) / build / smoke / cross-compile (5 targets) / commit-policyGO-2026-6809(crypto/x509in Go 1.26.9 stdlib) on HEAD579c04aand merge-base375f64c; unrelated to this diff; fix is go1.26.10Checklist
go fmt,go vet)AI disclosure: I drafted and reviewed this change with AI assistance (Grok Build CLI, model grok-4.7). I have reviewed the diff myself. The commit carries no AI attribution.
Related Issues
Fixes #1824