feat(indexing): respect .gitignore when indexing#29
Merged
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
Lets users index files that the gitignore aggregator or the skip-dirs baseline would otherwise exclude (e.g. a specific package under node_modules), per PR #29 review feedback. - New --force-include flag on `libr add` and `force_include` arg on `index_directory_to_library`. Persisted on the source entry and honored on rebuild. - New `.librariantrack` file format (gitignore-syntax) opts specific patterns back in from any directory under the source root. - Force-include bypasses the skip-dirs baseline and any .gitignore match but does not rescue unsupported/binary/hidden files (the indexer can't parse them anyway). - The skip-dirs baseline and binary-extension list moved to `librarian/config.py` as INDEX_SKIP_DIRS / INDEX_SKIP_EXTENSIONS, env-overridable instead of hardcoded.
sdserranog
approved these changes
May 25, 2026
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