Repository navigation
Exclude .git when a directory has no .gitignore - #48
Merged
Merged
Conversation
The built-in exclusions (.git, .jekyll-cache, .ruff_cache, .DS_Store) were appended to the patterns read from .gitignore, so a directory without one got no filter at all and the contents of .git were scanned. panopticas assess and urls listed Git's internal files, and panopticas ai could report a file inside .git as an AI artifact. The exclusions now apply whether or not a .gitignore exists, in all four functions that walk a directory. A directory with no .gitignore behaves exactly like one with an empty .gitignore. all_files still turns all filtering off, and load_gitignore_patterns() still returns None when there is no .gitignore. Closes #1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #1.
Summary
.gitignoreno longer has its.gitdirectory scanned..git,.jekyll-cache,.ruff_cache,.DS_Store) now apply whether or not a.gitignoreexists.-all-filesandload_gitignore_patterns()are unchanged.The cause
The built-in exclusions were appended to the patterns read from
.gitignore. With no.gitignorethere was no matcher at all, so nothing was excluded:panopticas assessandpanopticas urlslisted Git's internal files.panopticas aicould report a file inside.gitas an AI artifact.identify_files()returned those files to callers.Decision
Issue #1 asked for a decision between three options:
.gitby default — yes. It is never repository content.-all-files(all_files=True) disables all filtering and still shows.git..git. A directory with no.gitignorenow behaves exactly like one with an empty.gitignore; the two differing was the bug.Changes
ALWAYS_IGNOREDholds the four built-in patterns._scan_spec(directory)returns the.gitignorematcher, or a matcher ofALWAYS_IGNOREDalone when there is no.gitignore.identify_files(),identify_files_with_metrics(),find_files()andfind_ai_files()use it.load_gitignore_patterns()is public and documented as returningNonewith no.gitignore. That contract is kept; the fallback lives in the private helper.Effect
Across 167 cloned repositories, six have no root
.gitignore. Files under.git/scanned went from 308 to 0, with no other difference in the files selected.kospex: no change to its file inventory.
get_repo_files()already skips.gitpaths itself. Because kospex takes its file list fromidentify_files(), a committed.DS_Storein a repository without a.gitignorewould previously have been inventoried and no longer is — the same as already happens in repositories that have a.gitignore.Not changed
-all-filesstill lists.git..gitand discards each file instead of pruning the directory.Testing
pytest: 774 passed.TestScanWithoutGitignorebuilds a repository with a.gitdirectory and no.gitignore; five of its six tests failed before the change, and the sixth pins the unchangedall_filesbehaviour.panopticas assesson a freshgit initdirectory lists only the working files.🤖 Generated with Claude Code