[BUG] Ancestor .ignore and .repomixignore are not applied when targeting a subdirectory, unlike ancestor .gitignore
Description
When repomix is pointed at a subdirectory, ignore rules from parent directories are applied inconsistently: ancestor .gitignore files are respected, but ancestor .ignore and .repomixignore files are not. So repomix packages/foo in a monorepo packs files that the project's own root .repomixignore exists to keep out.
This is the remaining half of #776, which reports .gitignore patterns being dropped when targeting a subdirectory. On current main the .gitignore half of that report no longer reproduces — the asymmetry is now between the ignore files themselves.
Reproduction
rm -rf /tmp/anc && mkdir -p /tmp/anc/sub
cd /tmp/anc && git init -q
printf 'secret.txt\n' > .repomixignore
printf 'ga.txt\n' > .gitignore
printf 'x\n' > sub/secret.txt
printf 'x\n' > sub/ga.txt
printf 'x\n' > sub/keep.txt
git add -A && git -c user.name=dev -c [email protected] commit -qm init$ repomix sub -o - | grep '<file path=' # repomix 1.18.0, built from main at 9f01703a
<file path="keep.txt">
<file path="secret.txt"> # <-- the ancestor .repomixignore does not apply
# sub/ga.txt absent: ancestor .gitignore does
$ repomix . -o - | grep '<file path=' # same tool, same files, run from the root
<file path="sub/keep.txt">
<file path=".gitignore">
<file path=".repomixignore">sub/ga.txt is excluded by both invocations, because the ancestor .gitignore is applied either way. sub/secret.txt is excluded only when the root is the target — the ancestor .repomixignore is consulted for its own tree, never above it. Packing the repository root is therefore the only way a root .repomixignore protects a subdirectory, which is the opposite of what the docs promise for it ("a .repomixignore file in your project root", same wording for .ignore).
Cause
.gitignore is delegated to globby, which walks parent directories for it — this is deliberate, and createBaseGlobbyOptions says so:
// src/core/file/fileSearch.ts:427-430
cwd: rootDir,
ignore: ignorePatterns,
gitignore: config.ignore.useGitignore,
ignoreFiles: ignoreFilePatterns,.ignore and .repomixignore are instead registered as glob patterns relative to the target, so only the target's own tree is scanned:
// src/core/file/fileSearch.ts:450 and :453 (getIgnoreFilePatterns)
ignoreFilePatterns.push('**/.ignore');
...
ignoreFilePatterns.push('**/.repomixignore');Both mechanisms reach the same directory list, but only one of them looks above rootDir.
The question for maintainers
Either behaviour is defensible, which is why I'd rather not just pick one in a PR:
- Honour ancestors — consistent with the ancestor
.gitignorehandling and with how#375framed "git-compatible" ignore resolution. A.repomixignoreabove the target then also needs the depth semantics that gitignore gives its patterns. - Treat the target as the project root — arguably what "run repomix on this directory" means. Then ancestor
.gitignoreshould stop being applied, which is a breaking change for anyone who currently relies on it.
The inconsistency is the bug either way: today the same file is packed or not depending on which of two root-level ignore files names it. Happy to implement whichever direction is agreed.
Usage Context
Repomix CLI
Repomix Version
1.18.0 (built from main at 9f01703a)
Node.js Version
v24.18.0
Source: yamadashy/repomix