Repository navigation
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
Qiyuanqiii
left a comment
There was a problem hiding this comment.
Reviewed ecad46b.
The history-mode behavior now matches the input being reviewed. Range mode reads .gitignore from the target ref, commit mode reads it from the reviewed commit, and workspace mode continues to use the working tree.
This also removes the previous dependency on unrelated local or uncommitted .gitignore state when reviewing historical refs. The new tests cover range, commit, and workspace behavior with real repositories.
I don't see another blocker. Approving.
There was a problem hiding this comment.
@ydflow Thanks — the fix itself is correct and well-scoped. I verified it independently in both directions: a .gitignore committed in the reviewed ref still filters tracked files, and a working tree missing the .gitignore that the ref carries now drops the file as it should. internal/diff, internal/agent, internal/scan, internal/session and cmd/... all pass; no conflict with current main. Leaving LoadGitignorePatterns and the internal/scan / file_find callers alone is the right call.
A few things to address before merging — the first is the one that matters.
1. The tests don't pin the positive half of the new behavior.
Replacing the pattern load with nil, i.e. doing no .gitignore filtering at all in history modes, still passes all three new tests:
if ref != "" {
return p.partitionDiffsWithPatterns(diffs, nil), nil
}TestWorkspaceModeStillHonorsWorkingTreeGitignore guards the workspace side, but nothing guards "the reviewed ref's own rules still apply". Please add a test where the ref carries a committed .gitignore that ignores a tracked file (git add -f), asserting the file is still filtered out. The implementation already passes this — it's purely a missing test.
2. gitOutput duplicates gitOut and its doc comment is wrong.
git_resolve_test.go already has gitOut(t, dir, args...) in this same package with an identical body, except that it trims. The new helper's comment says "returns its trimmed stdout" but returns string(out) untrimmed, so the call site wraps it in strings.TrimSpace. Suggest deleting gitOutput and using gitOut.
3. Unreachable branch. The if ref == "" { return nil } in loadGitignorePatternsAtRef can't be hit — the only caller already checks ref != "". Worth dropping given the 90% coverage threshold.
4. Errors are swallowed wholesale, including cancellation. Fail-open is the right direction here (over-reviewing beats silently dropping), but ctx.Err() goes down the same path, so a cancelled or timed-out run degrades to "no ignore rules" and keeps going. The rest of GetDiffSet propagates, and runGitSplit has an explicit cancellation guard. Suggest propagating ctx.Err() and noting in the comment that fail-open on other errors is deliberate.
5. Minor: if ref != "" re-derives the mode from a value the switch p.mode just above computed. Folding the pattern load into that switch, or testing p.mode != ModeWorkspace, states the intent more directly.
One note for the release notes: this is user-visible. Anyone who relied on a local .gitignore to keep generated-but-tracked files out of range/commit reviews will now see those files reviewed — which is the point, but it will read as a regression otherwise. --preview changes the same way, via internal/agent/preview.go.
|
Thanks for the detailed review — all five addressed in c2f1a35, pushed on top of the merge of upstream main. 1. Positive half now pinned. Two new tests: Confirmed they pin real behavior: substituting 2. 3. Unreachable branch dropped. 4. New test 5. Intent stated directly. Verification (Windows, go1.27.0, git 2.33.1): Release note: agreed, and worth stating precisely — a range/commit review no longer honors a |
|
The current head is |
…modes Range and commit modes reviewed history, but filtered their changed files with the working tree's .gitignore. A rule that exists only locally — an uncommitted .gitignore, or one on the checked-out branch but not on the reviewed one — silently dropped files out of the review while the run still exited 0. Reported with a `feature` branch adding gen.go and no .gitignore, plus a local uncommitted .gitignore ignoring it: `ocr review --from base --to feature` reviewed nothing. A range review answers "what did this ref change", so the ignore rules that apply are the ones the ref carries. Read them with `git show REF:.gitignore` instead; a ref without one yields no patterns, which is what its history says. Workspace mode keeps reading the working tree, because there the working tree is the thing under review. The exported LoadGitignorePatterns and the workspace paths in scan and file_find are untouched: those callers were always working-tree semantics.
- Pin the positive half: the reviewed ref's own .gitignore still filters tracked files in range and commit modes. Without this, replacing the pattern load with nil passed all three existing tests. - Propagate ctx.Err() from the ref read instead of swallowing it into "no ignore rules". Fail-open on other errors stays deliberate and is now stated in the comment. - Drop the unreachable ref == "" branch (the only caller already checks the mode) and key the history-mode branch on p.mode instead of ref. - Replace the duplicated gitOutput test helper with gitOut.
c2f1a35 to
17e60e7
Compare
|
Rebased onto The rebase needed one real decision:
So Verified at
|
Description
Range and commit modes reviewed history, but filtered their changed files with the working tree's
.gitignore.An ignore rule that exists only locally — an uncommitted
.gitignore, or one that exists on the checked-out branch but not on the reviewed one — silently dropped files out of the review, while the run still exited 0. A file the user explicitly asked about was never looked at, and nothing said so.Reproduction from the issue: a
featurebranch addsgen.goand has no.gitignore; with a local uncommitted.gitignorecontaininggen.go,ocr review --from base --to featurereviews nothing.Why this is the right rule
A range review answers "what did this ref change", so the ignore rules that apply are the ones the ref itself carries. Read them from
REF:.gitignoreinstead of the checkout. A ref without a.gitignoreyields no patterns, which is exactly what its history says — not a reason to fall back to the working tree, because that is the bug.Workspace mode keeps reading the working tree, because there the working tree is the thing under review.
LoadGitignorePatterns(exported) and its callers ininternal/scanandinternal/tool/file_findare untouched: those were always working-tree semantics and still are.Type of Change
How Has This Been Tested?
Three tests in
internal/diff/git_test.go, all driving real git repositories:TestRangeModeIgnoresWorkingTreeGitignore— the regression. Base commit with no.gitignore, afeaturecommit addinggen.go, then an uncommitted local.gitignoreignoringgen.go. Asserts the range review still selectsgen.go.TestCommitModeIgnoresWorkingTreeGitignore— same rule for--commit, which diffs against the commit's first parent.TestWorkspaceModeStillHonorsWorkingTreeGitignore— the guard against over-correcting: workspace mode must still honor the working tree's rules (it reviews the working tree), sogen.gostays excluded there.Confirmed the tests pin real behavior rather than an incidental pass: reverting only the
GetDiffSetchange makes both history-mode tests fail withselected []— the exact silent-drop symptom from the issue — and restoring it makes them pass.Local runs (Windows, go1.27.0):
go test ./internal/diff/... ./internal/agent/... ./internal/scan/... ./internal/session/...— allokgofmt -s -l internal/diff/— cleango vet ./internal/diff/— cleanbash scripts/verify-license.sh— all source files have valid license headersgo build ./cmd/opencodereview— exit 0Not run:
internal/tool, whose GitGrep tests fail on this machine for a pre-existing environment reason (the installed git is 2.33.1 and the code needs--max-countfrom 2.45+). Verified unrelated by checking out the base commit and re-running: the same 21 failures. No files in that package are touched by this PR.Checklist
go fmt,go vet)AI/LLM disclosure: used Claude (Anthropic) as a coding assistant for navigating the codebase and drafting. Every line was read and verified by me: the root cause was confirmed by a failing test before any fix, and the fix was re-verified by reverting it to watch those tests go red again. The test results above are from commands I ran locally. Commits carry no AI attribution.
Related Issues
closes #1487
Scope note
The issue asks whether range/commit modes should read ignore rules from the reviewed ref, or whether the working-tree behavior is intended — so a maintainer may prefer the "document it instead" route. This PR implements the ref-based reading because the current behavior is silent data loss rather than a documented choice, and the issue reports it as a bug. Happy to switch to a docs-only change if that is the preferred direction.
One thing this does not address: nested
.gitignorefiles in subdirectories are still not read (only the repository root's, matching the pre-existing behavior). That is a separate gap and out of scope here.