fix(init): layer the repo's .gitignore into the init index walk - #332
Merged
Conversation
`gortex init` resolved its config with `config.Load("")`. That argument is a
*config file* path, not a repo path, so the per-repo layering never ran and
`cfg.Index.Exclude` came back empty. `indexer.New` then hit its documented
"no layering was applied" fallback and used `excludes.Builtin` alone, so the
init walk admitted every gitignored tree that does not happen to match a
builtin pattern.
On a repo whose `.gitignore` excludes `tmp/` (holding linked worktrees) and a
generated output directory, init queued 15,496 files against a tracked set of
2,693 — 5.7x — and was still parsing at 18m46s. `node_modules/` and `.next/`
were correctly skipped because they match builtin patterns, which is what made
the failure look inconsistent rather than absent.
`respect_gitignore` is documented as defaulting to true, so this was a gap
between the promise and the init path, not a design choice: only the daemon
reached the layering, through `ConfigManager.GetRepoConfig`.
Resolve the config for the actual root through that same path. The new
`initRepoConfig` helper keeps the previous best-effort fallback when the global
config cannot be read, and takes an explicit global path so tests never read the
developer's real `~/.gortex/config.yaml`.
Fixes zzet#324
zzet
approved these changes
Jul 24, 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.
Fixes #324.
Root cause
indexRepoForInitresolved its config with:config.Loadtakes a config file path, not a repo path, so the per-repolayering never ran and
cfg.Index.Excludecame back empty.indexer.Newthenhit its own documented fallback:
cmd/gortex/init.gois exactly that direct caller, so the init walk ran onexcludes.Builtinalone and admitted every gitignored tree that does not happento match a builtin pattern. Only the daemon reached the layered list, via
ConfigManager.GetRepoConfig→EffectiveExclude.The admission path never consults
.gitignoreon its own either —dirIgnoreFilesis{".gortexignore", ".ignore", ".rgignore"}— so the.gitignorelayer exists solely ininternal/config.Why this is a bug rather than a design choice
RespectGitignoreis documented as defaulting to true. The promise held for thedaemon and silently did not hold for
init.Symptom (from #324)
On a repo whose
.gitignoreexcludestmp/(holding four linked worktrees) anda generated output directory:
initStill parsing at 18m46s.
node_modules/(29.7k) and.next/(5.1k) werecorrectly skipped because they match builtin patterns — which is what made the
failure look inconsistent rather than absent.
Note for #324 readers: the issue guessed that nested git worktrees were being
treated as admissible repos. That turned out to be a red herring —
LinkedWorktreeRootsonly reports already-tracked repos. The worktrees undertmp/were swallowed simply becausetmp/was never pruned.Fix
Resolve the config for the actual root through the same path the daemon uses.
The new
initRepoConfighelper:so an unreadable
~/.gortex/config.yamlstill does not block indexing;config.
Tests
cmd/gortex/init_gitignore_test.go:TestInitRepoConfigLayersRepoGitignore— gitignored dirs are excluded, and atracked dir is still walked (so the fix cannot be "exclude everything").
TestInitRepoConfigHonoursRespectGitignoreOptOut—respect_gitignore: falsestill walks ignored trees.
Sabotage-verified: reverting the helper to the old
config.Load("")behaviourmakes
TestInitRepoConfigLayersRepoGitignorefail; restoring it passes.Verification
gofmt,go vetandgo buildclean.Full-package runs on Windows show six failures —
TestReviewCLI_AudienceAgent(path separators),
TestComputePurgePlan*andTestDefaultGlobalConfigPath_*(they read the real
HOMErather than the temp one), andTestMatchRepo_SuffixMatch(needs a running daemon). I confirmed all six fail identically on the base commit
7de88fbwithout this change, so they are pre-existing environment coupling andnot introduced here.