Repository navigation
fix(discover): a .gitignore never hides a file git tracks - #2608
Merged
Merged
Conversation
git applies ignore rules to untracked paths only, but discovery applied them to every path. A nested .gitignore line `manager`, meant for a built binary, hid cluster-api's tracked config/manager/ kustomization, and with it the Deployment its overlays point at. When the indexed directory is in a git repository, discovery now reads `git ls-files -z` once. A directory that git's rules ignore (.gitignore files, info/exclude, the global excludes file) is still entered when it holds tracked files. Inside it, untracked files and directories stay ignored, as in git. A tracked file is kept although a rule matches it. The built-in skip list, .cbmignore and the size cap apply as before. If git cannot run, nothing changes. On the 17 infra corpora git lists 34 tracked files that an ignore rule matches. The fix indexes 26 of them, all from that list. The other 8 are never indexed for other reasons: no language (.tfvars, .gitkeep) or a built-in skip directory (vendor/). No file is lost and no untracked file appears. cluster-api gains the manager kustomization (4 Resources, its overlay IMPORTS), helm-charts a Chart, and otel-demo a Route. Test: discover_gitignore_never_hides_tracked_files builds a real git repository. It fails without the fix. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Discovery reads the tracked-file set through the supervised subprocess API instead of cbm_popen, so no shell parses the command: - git is resolved to an absolute path from absolute PATH entries only (cbm_test_impact_find_git), never the current directory; - the repository path is a single argv entry; - the child environment drops repository-local variables, so an inherited GIT_DIR cannot redirect -C; - core.fsmonitor is off for the call; - stdout goes to a private mkstemp file that is read and removed. discover.c needs no entry on the security allow-list. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
DeusData
force-pushed
the
fix/gitignore-tracked-files
branch
from
October 12, 2026 17:41
8f5fc4e to
2aeaabd
Compare
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.
What
Discovery applied
.gitignorerules to every path. git applies them to untracked paths only, so a tracked file can match an ignore pattern and still be part of the repository.Real case: kubernetes-sigs/cluster-api has
test/infrastructure/docker/.gitignorewith the linemanager, meant for a built binary. It also hid the trackedconfig/manager/kustomization and the Deployment its overlays point at.Fix (src/discover/discover.c)
git -C <root> ls-files -zonce (throughcbm_popen_git, asgit_context.cdoes). It keeps two sets: tracked paths, and every directory above one..gitignorefiles,info/exclude, the global excludes file) is still entered when it holds tracked files..cbmignoreand the size cap. With no repository, or if git fails, behaviour is exactly as before.should_skip_directorybecomesdirectory_verdict(keep / skip / git-ignored). Untracked paths get the same verdicts as before, including the.cbmignorenegation of a global-excludes match.Evidence (17 infra corpora, before = main, after = this branch)
Oracle:
git ls-files -ci --exclude-standard, the tracked files an ignore rule matches. It lists 34 existing files in 7 corpora..tfvars/.gitkeephave no language (0 of 240.tfvarsare indexed on main), and 5 sit undervendor/, which is on the built-in skip listGraph gains:
config/managerkustomization, +4 Resources, +8 CONFIGURES, and the overlay's IMPORTS now resolve.Test
discover_gitignore_never_hides_tracked_files(suitediscover) builds a real git repository:.gitignorewithmanagerand*.gen.go;*.gen.go.It fails without the fix (
ASSERT(manager_found)).Not in this PR
The test-impact inventory filter (
inventory_filter.c) applies the same ignore rules to itsgit ls-treerows, which are all tracked. That divergence is safe: a changed file missing from its ledger falls back to running every test. It is noted as a follow-up.