Skip to content

fix(snapshot): complete gitignore respect for previously tracked files#22172

Merged
thdxr merged 2 commits intodevfrom
fix/snapshot-gitignore-complete
Apr 12, 2026
Merged

fix(snapshot): complete gitignore respect for previously tracked files#22172
thdxr merged 2 commits intodevfrom
fix/snapshot-gitignore-complete

Conversation

@thdxr
Copy link
Copy Markdown
Member

@thdxr thdxr commented Apr 12, 2026

Summary

The previous fix (#22171) was incomplete. This PR adds the missing critical pieces.

What was missing in #22171

  1. Missing --no-index flag in git check-ignore commands

    • Without --no-index, check-ignore returns exit code 1 for tracked files
    • This means files already in git (like a.txt) wouldn't be filtered even if added to .gitignore
  2. Missing diffFull() filtering

    • When gitignore changes between two track() calls, diffFull(from, to) would still show gitignored files

The Complete Fix

In add() function:

  • Uses git check-ignore --no-index to identify newly-ignored files
  • Removes them from snapshot index with git rm --cached

In patch() function:

  • Filters gitignored files from diff output using --no-index

In diffFull() function:

  • Filters gitignored files from diff results (NEW in this PR)

Test Coverage

  1. files tracked in snapshot but now gitignored are filtered out

    • Uses a.txt from bootstrap (already committed to git)
    • Verifies the fix works for files that were in git before being gitignored
  2. gitignore updated between track calls filters from diff (NEW)

    • Tests that gitignore changes between two track() calls
    • Properly filters from diffFull() results

Why --no-index is critical

# Without --no-index: Returns exit code 1 for tracked files
$ git check-ignore a.txt  # a.txt is tracked → exit 1, not filtered

# With --no-index: Purely checks against patterns
$ git check-ignore --no-index a.txt  # Returns a.txt if in .gitignore

Verification

All 53 snapshot tests pass including 2 new tests.

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.
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

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 merged commit 264418c into dev Apr 12, 2026
6 of 8 checks passed
@thdxr thdxr deleted the fix/snapshot-gitignore-complete branch April 12, 2026 18:05
alexyaroshuk pushed a commit to alexyaroshuk/opencode that referenced this pull request Apr 13, 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