Skip to content

fix(diff): preserve staged ignored files in workspace - #1126

Open
Parikalp-Bhardwaj wants to merge 1 commit into
alibaba:mainfrom
Parikalp-Bhardwaj:fix/workspace-staged-additions
Open

Parikalp-Bhardwaj wants to merge 1 commit into
alibaba:mainfrom
Parikalp-Bhardwaj:fix/workspace-staged-additions

Conversation

@Parikalp-Bhardwaj

Copy link
Copy Markdown
Contributor

Summary

Fixes workspace reviews dropping staged files that match .gitignore patterns.

Changes

  • Stop reapplying .gitignore rules to diffs already collected by Git.
  • Continue excluding ignored untracked files.
  • Preserve existing internal directory exclusions.
  • Add a regression test covering tracked, staged, and ignored untracked files together.

Related #1121

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Thanks for the fix @Parikalp-Bhardwaj — the underlying bug is still present on main, so this is still worth landing. But the branch can't be merged as-is: it's branched from an old base and the filterDiffs function it edits no longer exists.

What changed on main: filterDiffs was refactored and renamed to partitionDiffs in #1223 / #1242, which split diffs into Included / Excluded. That refactor only moved the code — it did not fix this bug. partitionDiffs still reapplies .gitignore to already-collected diffs, and worse, gitignore-matched staged files now fall through to neither Included nor Excluded (silently dropped). I confirmed this by running your regression test against current main — it fails:

staged new file matching .gitignore was dropped; got map[src/app.go:true]

Could you please:

  1. Rebase onto latest main.
  2. Move the fix into partitionDiffs (internal/diff/git.go): drop the isPathExcluded gitignore check so a force-added ignored file lands in Included, while keeping the isProviderDirExcluded handling intact.
  3. Re-target your regression test to the rebased code.

The test you added already covers the right cases, so it should transfer directly.

@Parikalp-Bhardwaj
Parikalp-Bhardwaj force-pushed the fix/workspace-staged-additions branch from b604823 to ab64915 Compare September 22, 2026 08:39
@Parikalp-Bhardwaj

Copy link
Copy Markdown
Contributor Author

Thanks for the guidance @lizhengfeng101

Rebased #1126 onto the latest main and moved the fix into partitionDiffs.

It now keeps force-added staged files that match .gitignore, while ordinary ignored untracked files are still filtered earlier.

Provider-directory handling and ordering are unchanged.

I also updated the #1300 ordering test, since it expected a tracked ignored file to be dropped. With this fix, tracked files matching .gitignore stay included.

Let me know if you want this behavior limited only to force-added staged files.

@Parikalp-Bhardwaj

Copy link
Copy Markdown
Contributor Author

@lizhengfeng101 since partitionDiffs is shared by workspace, range, and commit modes, this also means the current working tree's .gitignore will no longer filter diffs that Git already returned in range/commit mode.

That overlaps a bit with #1487, but I haven't marked it as fixed because that, issue also discusses whether the reviewed ref's ignore rules should be used.

#1510/#1511 look complementary here — they add the separate frozen --staged mode, while this PR fixes the existing diff partitioning behavior.

@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 both changed files, the surrounding diff collection/untracked filtering, #1121 and the existing discussion. I also inspected #1511's actual partitionDiffs change: its ignore bypass is restricted to the new frozen staged mode, whereas this patch corrects the existing shared partitioning path. It does not supersede this fix.

Removing the second .gitignore pass keeps paths that Git already selected, while untrackedFilesList still uses --others --exclude-standard and its existing filtering. Built-in provider-directory exclusions and the Included/Excluded order bookkeeping remain intact. The updated ordering regression correctly retains the tracked ignored file, and the new workspace fixture distinguishes a force-added file from an ordinary ignored untracked sibling. I found no blocking defect in this focused change.

I independently checked that Git boundary in a temporary repository: git diff HEAD included the modified tracked file and the force-added ignored helper; ls-files --others --exclude-standard omitted the ignored generated sibling. This was a Git-selection fixture, not execution of OCR's regression suite.

Scope remains important: provider-directory exclusions still apply, including vendor, so this does not promise to admit every path mentioned in #1121. The shared change also stops the live working-tree .gitignore from hiding Git-returned commit/range diffs, as the author already disclosed. GitHub currently reports a merge conflict; resolve/rebase it and rerun the relevant tests before merging. This approval concerns the reviewed patch, not merge readiness or an independently verified full-suite result.

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.

3 participants