feat(indexing): respect .gitignore when indexing#29
Open
torresmateo wants to merge 1 commit into
Open
Conversation
Aggregates patterns from every .gitignore under the indexed root and skips matching files. Hardcoded baseline (.git, node_modules, caches, binaries) still applies. New --include-ignored flag on libr add (and include_ignored arg on index_directory_to_library) opts out. The previously-duplicated _should_skip_file in cli.py and server.py now delegates to a shared helper in librarian/sources/ignore.py.
sdserranog
reviewed
May 22, 2026
| ".git", | ||
| ".svn", | ||
| ".hg", | ||
| "node_modules", |
There was a problem hiding this comment.
I sometimes look into node_modules to figure out a library's types or to debug a bug and see whether it's in my code or a dependency. Not sure if we can add an explicit flag to include a file or directory, even if it's on the list or in .gitignore, instead of --include-ignored.
Collaborator
Author
There was a problem hiding this comment.
This is a good point, I think having --include-ignore makes sense as a convenience shorthand. I'm thinking of these options for manually allowlisting specific files/directories:
- Have
.librariantrackwhich overrides.gitignoreon the specific directory - Have
--force-include <list of files/directories>to include.
In both cases pointing to a directory will recursively include files inside as if --include-igore was used. And for this we'll also remove the hardcoded default in these lines.
How does this sound?
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 #28.
Summary
.gitignoreunder the indexed root and skip matching files during indexing..git,node_modules,__pycache__, caches, binaries, fonts, media) still applies —.gitignorelayers on top.--include-ignoredflag onlibr add(andinclude_ignoredarg onindex_directory_to_library) opts out. The flag is persisted on the source entry and honored bylibr index buildon rebuild._should_skip_fileincli.pyandserver.pynow delegates to a sharedlibrarian/sources/ignore.py. This file is the home for the newGitignoreMatcher(which usespathspec'sGitIgnoreSpecunder the hood and rewrites nested patterns to be anchored under their containing directory).Test plan
make checkclean (lint, format, mypy)make test-fast— 96 passed / 8 skippedtests/test_gitignore.pycovering: no-gitignore, root patterns, floating patterns at any depth, anchored patterns, nested-gitignore scoping, negation, out-of-root paths, the always-skip baseline, and the include-ignored pathbuild/in.gitignore;libr add --dry-runshows 1 file,libr add --dry-run --include-ignoredshows 2 filesnode_modules/tree:SKIP node_modules/pkg/skip.md,KEEP src/readme.md