-
-
Notifications
You must be signed in to change notification settings - Fork 380
feat(indexing): respect root .gitignore patterns during indexing #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from codebase_rag.config import ( | ||
| CGRIGNORE_FILENAME, | ||
| GITIGNORE_FILENAME, | ||
| load_ignore_patterns, | ||
| ) | ||
|
|
||
|
|
||
| def test_gitignore_excludes_are_loaded(tmp_path: Path) -> None: | ||
| # (H) A gitignored path is a build artifact or generated output; indexing it | ||
| # (H) pollutes the graph and the dead-code report (evals/results fixtures on | ||
| # (H) cgr's own repo), so root .gitignore patterns must merge into excludes. | ||
| (tmp_path / GITIGNORE_FILENAME).write_text("results/\n*.gen.py\n", encoding="utf-8") | ||
|
|
||
| result = load_ignore_patterns(tmp_path) | ||
|
|
||
| assert "results/" in result.exclude | ||
| assert "*.gen.py" in result.exclude | ||
|
|
||
|
|
||
| def test_gitignore_exact_negation_cancels_its_exclude(tmp_path: Path) -> None: | ||
| # (H) An exact-match `!pattern` negation cancels the same-string exclude at | ||
| # (H) load time; the runtime skip check gives excludes precedence over | ||
| # (H) unignores, so leaving both in place would keep the path skipped. | ||
| (tmp_path / GITIGNORE_FILENAME).write_text( | ||
| "dist/\n!dist/\nbuild/\n", encoding="utf-8" | ||
| ) | ||
|
|
||
| result = load_ignore_patterns(tmp_path) | ||
|
|
||
| assert "dist/" not in result.exclude | ||
| assert "build/" in result.exclude | ||
|
|
||
|
|
||
| def test_gitignore_finer_negation_stays_an_unignore(tmp_path: Path) -> None: | ||
| # (H) A finer-grained negation (`!dist/keep.py` under an excluded `dist/`) | ||
| # (H) cannot cancel by string match; it flows to unignore, where it rescues | ||
| # (H) from built-in ignores only (documented ceiling in config.py). | ||
| (tmp_path / GITIGNORE_FILENAME).write_text( | ||
| "dist/\n!dist/keep.py\n", encoding="utf-8" | ||
| ) | ||
|
|
||
| result = load_ignore_patterns(tmp_path) | ||
|
|
||
| assert "dist/" in result.exclude | ||
| assert "dist/keep.py" in result.unignore | ||
|
|
||
|
|
||
| def test_cgrignore_unignore_overrides_gitignore_exclude(tmp_path: Path) -> None: | ||
| # (H) .cgrignore stays authoritative for cgr-specific choices; a `!pattern` | ||
| # (H) there re-includes something .gitignore excludes (the escape hatch for | ||
| # (H) indexing generated code on purpose). The cancellation must happen at | ||
| # (H) load time or the runtime exclude-first precedence keeps it skipped. | ||
| (tmp_path / GITIGNORE_FILENAME).write_text("generated/\n", encoding="utf-8") | ||
| (tmp_path / CGRIGNORE_FILENAME).write_text( | ||
| "vendor_src\n!generated/\n", encoding="utf-8" | ||
| ) | ||
|
|
||
| result = load_ignore_patterns(tmp_path) | ||
|
|
||
| assert "generated/" not in result.exclude | ||
| assert "vendor_src" in result.exclude | ||
|
|
||
|
|
||
| def test_cgrignore_exclude_wins_over_gitignore_negation(tmp_path: Path) -> None: | ||
| # (H) The override channel is one-directional: an explicit .cgrignore exclude | ||
| # (H) is authoritative and a .gitignore negation must not cancel it. | ||
| (tmp_path / GITIGNORE_FILENAME).write_text("!generated/\n", encoding="utf-8") | ||
| (tmp_path / CGRIGNORE_FILENAME).write_text("generated/\n", encoding="utf-8") | ||
|
|
||
| result = load_ignore_patterns(tmp_path) | ||
|
|
||
| assert "generated/" in result.exclude | ||
|
|
||
|
|
||
| def test_no_ignore_files_yields_empty(tmp_path: Path) -> None: | ||
| result = load_ignore_patterns(tmp_path) | ||
|
|
||
| assert result.exclude == frozenset() | ||
| assert result.unignore == frozenset() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load_ignore_patterns()collapses.gitignoreinto sets, sodist/\n!dist/\ndist/returnsdist/only inunignoreand indexesdist/, while Git's documented rule is that within one precedence level the last matching pattern decides the outcome. Repos that re-ignore after a negation will now include generated files that Git ignores; the loader needs to preserve pattern order or compile an orderedPathSpecfor.gitignoreinstead of subtracting all negations globally.Rule Used: ## Technical Requirements
Agentic Framework
-... (source)
Prompt To Fix With AI