Skip to content

fix(snapshot): respect gitignore for previously tracked files - #22171

Merged
thdxr merged 1 commit into
devfrom
fix/snapshot-gitignore-respect
Apr 12, 2026
Merged

fix(snapshot): respect gitignore for previously tracked files#22171
thdxr merged 1 commit into
devfrom
fix/snapshot-gitignore-respect

Conversation

@thdxr

@thdxr thdxr commented Apr 12, 2026

Copy link
Copy Markdown
Member

Summary

Files previously tracked in the snapshot that were later added to .gitignore were still being included in patches. This caused scenarios like 22,881 files from .android-sdk being snapshotted even after being added to .gitignore.

Root Cause

  1. diff-files returns tracked files regardless of gitignore status
  2. git add was re-adding all files including those now ignored
  3. patch() output wasn't filtering out gitignored files

The Fix

In add() function:

  • Use git check-ignore against the source project's git to identify newly-ignored files
  • Remove those files from the snapshot index with git rm --cached before adding new files

In patch() function:

  • After getting diff results, use git check-ignore to filter out any gitignored files from the patch output

Test Added

files tracked in snapshot but now gitignored are filtered out - Verifies that a file was tracked, then gitignored, and no longer appears in patches.

Verification

All 52 snapshot tests pass including the new test.

Files previously tracked in the snapshot that were later added to .gitignore
were still being included in patches. This happened because:

1. diff-files returns tracked files regardless of gitignore status
2. git add was re-adding all files including those now ignored
3. patch() output wasn't filtering out gitignored files

The fix:
- In add(): Use git check-ignore to identify newly-ignored files and
  remove them from the snapshot index with git rm --cached
- In patch(): Filter out gitignored files from the diff output

Added test: files tracked in snapshot but now gitignored are filtered out

Fixes issue where files like .android-sdk were re-added to snapshots
even after being added to .gitignore.

@greptile-apps greptile-apps Bot 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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@thdxr
thdxr enabled auto-merge (squash) April 12, 2026 17:41
@thdxr
thdxr disabled auto-merge April 12, 2026 17:41
@thdxr
thdxr merged commit 113304a into dev Apr 12, 2026
8 of 11 checks passed
@thdxr
thdxr deleted the fix/snapshot-gitignore-respect branch April 12, 2026 17:41
thdxr added a commit that referenced this pull request Apr 12, 2026
The previous fix (#22171) was incomplete. This adds the missing pieces:

1. --no-index flag to git check-ignore (critical for tracked files)
   Without --no-index, check-ignore returns exit code 1 for tracked files
   even if they match gitignore patterns

2. diffFull() filtering - filters gitignored files from diff results
   when gitignore changes between two track() calls

3. Complete test coverage:
   - files tracked in snapshot but now gitignored are filtered out
   - gitignore updated between track calls filters from diff

The fix now properly handles the case where a file was:
1. Already in git (committed)
2. Tracked in snapshot
3. Later added to .gitignore

Such files will no longer appear in patches or diffs.
alexyaroshuk pushed a commit to alexyaroshuk/opencode that referenced this pull request Apr 13, 2026
mrsimpson pushed a commit to mrsimpson/opencode that referenced this pull request Apr 14, 2026
sdeonvacation pushed a commit to sdeonvacation/opencode-x-old that referenced this pull request Apr 23, 2026
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
avion23 pushed a commit to avion23/opencode that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant