Skip to content

fix(indexer): root-anchor .cgcignore patterns containing a slash (#1513) - #1614

Merged
Shashankss1205 merged 1 commit into
mainfrom
fix/1513-cgcignore-anchoring
Aug 13, 2026
Merged

Shashankss1205 merged 1 commit into
mainfrom
fix/1513-cgcignore-anchoring

Conversation

@Shashankss1205

Copy link
Copy Markdown
Collaborator

Fixes #1513.

.cgcignore is documented as using .gitignore syntax, but only a leading slash anchored. Every other pattern got the match-at-any-depth prefix, so a multi-segment pattern over-matched:

pattern: src/generated
  src/generated/a.py           ignored=True
  vendor/src/generated/a.py    ignored=True   <- should be False

Under gitignore semantics a slash anywhere except the trailing position anchors the pattern to the ignore root. So copying a line out of .gitignore — the workflow the docs encourage, and the point of #729 — silently dropped real source from the index with no warning.

The fix

One condition: after the leading / and trailing / have already been stripped, if a slash remains, anchor.

The trailing-slash case is what makes this safe: build/ has its slash removed as is_dir_only before the check, so directory patterns keep matching at any depth, exactly as gitignore does. Similarly **/dist stays depth-independent because the leading ** compiles to (?:.*/)?, which absorbs the anchor.

Verification against real git

Every expectation was cross-checked against git check-ignore in a scratch repo — 7 patterns × 17 paths, output identical:

pattern path ignored
src/generated src/generated/a.py yes
src/generated vendor/src/generated/a.py no
build/ build/a.py, sub/build/a.py yes
build/ layout/a.py no
/foo foo/a.py yes
/foo bar/foo/a.py no
node_modules node_modules/x.js, web/node_modules/x.js yes
**/dist dist/a.js, web/dist/a.js yes
docs/** docs/a.md yes
docs/** vendor/docs/a.md, docstring.py no
a/**/b a/b/f.py, a/x/y/b/f.py yes
a/**/b z/a/b/f.py no

Tests

16 parametrized cases added to test_cgcignore_patterns.py. Verified the three over-ignoring cases fail on main and all 16 pass with the fix.

tests/unit/         1194 passed, 7 skipped
tests/integration/    44 passed

Under gitignore semantics a slash anywhere except the trailing position
anchors a pattern to the ignore root, so `src/generated` matches only
<root>/src/generated. Here only a *leading* slash anchored; every other
pattern got the match-at-any-depth prefix, so `src/generated` also ignored
vendor/src/generated.

Copying a line from .gitignore into .cgcignore -- the workflow the docs
encourage -- therefore over-ignored, dropping real source from the index
with no warning.

A trailing slash is not an internal slash: `build/` has it stripped as
is_dir_only before the check, so directory patterns keep matching at any
depth, as gitignore does.

All 16 new expectations were cross-checked against `git check-ignore`
across 7 patterns.

Fixes #1513.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@vercel

vercel Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
code-graph-context-pack Ready Ready Preview Aug 13, 2026 7:25pm

@github-actions

Copy link
Copy Markdown
Contributor

Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

@github-actions

Copy link
Copy Markdown
Contributor

🔍 PR Code Graph Analysis

fix(indexer): root-anchor .cgcignore patterns containing a slash (#1513) (#1614)

📊 Interactive Visualization

View the blast radius graph: PR Reviewer Dashboard

📦 Artifacts

The graph JSON has been uploaded as a build artifact: pr-code-graph-1614


Generated by CodeGraphContext using FalkorDB Lite

@Shashankss1205
Shashankss1205 merged commit 23b3a31 into main Aug 13, 2026
20 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog tasks to Done in CGC Progress Board Aug 13, 2026

This branch was successfully deployed

1 active deployment
Preview — 05c2ed6a Deployed Aug 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(indexer): .cgcignore patterns with internal slashes are not root-anchored, so src/generated also ignores vendor/src/generated

1 participant