Fixes
fix: `--gitignore` skips nested repositories in ignored folders again (#9648)
fix: --gitignore skips nested repositories in ignored folders again (#9648)
Summary
With --gitignore (useGitignore), cspell again skips a git repository kept in a folder that .gitignore excludes, such as a tool's cache of cloned dependencies. Since 10.4.0, these files were checked. A submodule in an ignored folder is still checked, as git does.
Fixes #9645
Before and after
A project with a clone in an ignored cache folder, and a submodule in an ignored vendor/ folder:
project/
.gitignore .cache/ and vendor/
.gitmodules lists vendor/lib
README.md
.cache/dep/ a clone, with its own .git
vendor/lib/ a submodule
Before, cspell checked the clone:
$ cspell lint --gitignore --dot "**/*.md"
.cache/dep/NOTES.md:1:1 - Unknown word (Thsi) fix: (This)
.cache/dep/NOTES.md:1:9 - Unknown word (misspeled) fix: (misspelled)
vendor/lib/NOTES.md:1:1 - Unknown word (Anothr) fix: (Another)
vendor/lib/NOTES.md:1:8 - Unknown word (typpo) fix: (typo)
CSpell: Files checked: 3, Issues found: 4 in 2 files.
After, it skips the clone and checks the submodule:
$ cspell lint --gitignore --dot "**/*.md"
vendor/lib/NOTES.md:1:1 - Unknown word (Anothr) fix: (Another)
vendor/lib/NOTES.md:1:8 - Unknown word (typpo) fix: (typo)
CSpell: Files checked: 2, Issues found: 2 in 1 file.
What to know:
- A repository in an ignored folder is skipped with all its files, unless
.gitmoduleslists it as a submodule. - A repository added with plain
git add, without a.gitmodulesentry, is skipped too. - A worktree in an ignored folder is skipped too.
- Running cspell inside the nested repository still checks its files.
- In a folder that isn't ignored, the
.gitignorefiles above a nested repository still don't apply to its files.
Technical Details
- When the search for
.gitignorefiles reaches a nested repository belowgitignoreRoot(by default, the repository cspell runs in), it first asks the outer repository's.gitignorefiles whether the nested repository's folder is ignored. If it is, every file in it is ignored, whatever the.gitignorefiles inside it say. - Submodules are read from the outer repository's
.gitmodulesfile. The submodules of an ignored repository are ignored with it.
fix: Detect file types by folder, such as `.git/config` (#9641)
fix: Detect file types by folder, such as .git/config (#9641)
Summary
File types can now be detected by the folder a file is in, not only by its name. The first two are git's own files, which had no file type before.
.git/configis detected asproperties, like.gitconfig..git/info/excludeis detected asignore, like.gitignore.
Technical Details
- In
@cspell/filetypes, an entry in a file type'sfilenamesmay now contain/. It matches the end of a path. A\in the path is read as/. - In such an entry,
*stays within one folder, and**spans folders. - A match on the path wins over a match on the name or extension.
- cspell-lib now passes the full path when it looks up a file's type.
findMatchingFileTypescould return no file type for a path, depending on the path given in the previous call. That is fixed.