Skip to content

fix(diff): keep tracked gitignored files in workspace review - #1837

Merged
lizhengfeng101 merged 4 commits into
alibaba:mainfrom
Frank-zhu2000:fix/1824-tracked-ignored-files
Nov 3, 2026
Merged

lizhengfeng101 merged 4 commits into
alibaba:mainfrom
Frank-zhu2000:fix/1824-tracked-ignored-files

Conversation

@Frank-zhu2000

@Frank-zhu2000 Frank-zhu2000 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Workspace mode reviews currently drop modified tracked files that match .gitignore (for example a force-added bin/review_helper.py). Git never ignores a tracked path, so those edits should stay in the review input.

This PR makes partitionDiffs skip the .gitignore filter 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

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

  • make test passes locally
  • New / updated tests in internal/diff/git_test.go cover a tracked file matching .gitignore staying in Included under workspace mode, and commit/range mode still dropping it
  • Full local CI equivalent (pinned GOTOOLCHAIN=go1.26.9, matching .github/workflows/ci.yml):
Step Result
toolchain / provider-gen / license / action-pins / english / gofmt / line-endings / tidy / vet PASS
go test (incl. race + coverage ≥90%) / build / smoke / cross-compile (5 targets) / commit-policy PASS
govulncheck FAIL — baseline only: same GO-2026-6809 (crypto/x509 in Go 1.26.9 stdlib) on HEAD 579c04a and merge-base 375f64c; unrelated to this diff; fix is go1.26.10

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

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
@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

abhisheksharma2411 added a commit to abhisheksharma2411/open-code-review that referenced this pull request Oct 28, 2026
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 abhisheksharma2411 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@Frank-zhu2000

Copy link
Copy Markdown
Contributor Author

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.

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread internal/diff/git.go Resolved

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 8f9c8b7 into alibaba:main Nov 3, 2026
12 checks passed
kall added a commit to kall/open-code-review that referenced this pull request Nov 3, 2026
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%.
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.

Workspace review silently omits modified tracked files matched by .gitignore

4 participants