#1870·repomix

[BUG] .git/info/exclude patterns only apply to the top level of the packed directory

Author: sxh313Created Sep 20, 2026Updated Sep 21, 2026
Labelsbug

Description

Patterns in .git/info/exclude are only matched against paths at the top level of the packed directory. A nested file that Git considers ignored still gets packed.

.gitignore handles the same pattern correctly, so the two sources of ignore patterns disagree with each other and with Git.

This matters because .git/info/exclude is the standard place to keep a file out of Git without editing the tracked .gitignore — local secrets, scratch fixtures, personal paths. Docs advertise the feature as git-compatible (index.md: "Git-Aware: Respects your .gitignore and .git/info/exclude files"; configuration.md: "patterns listed in your project's .gitignore files and .git/info/exclude are used"), and it was requested that way in #375.

Reproduction

Two directories with the same shape and the same one-line pattern, differing only in which file it lives in.

bash
rm -rf /tmp/exc && mkdir -p /tmp/exc/{gitignore,exclude}/sub
for d in gitignore exclude; do
  git init -q /tmp/exc/$d
  echo A > /tmp/exc/$d/secret.txt
  echo B > /tmp/exc/$d/sub/secret.txt
  echo C > /tmp/exc/$d/keep.txt
done
echo secret.txt > /tmp/exc/gitignore/.gitignore
echo secret.txt > /tmp/exc/exclude/.git/info/exclude
for d in gitignore exclude; do
  git -C /tmp/exc/$d add -A
  git -C /tmp/exc/$d -c user.name=dev -c [email protected] commit -qm init
done

Git's answer is the same in both cases — an unanchored pattern (no slash) matches at any depth:

bash
$ cd /tmp/exc/exclude && git check-ignore -v secret.txt sub/secret.txt
.git/info/exclude:1:secret.txt  secret.txt
.git/info/exclude:1:secret.txt  sub/secret.txt

$ cd /tmp/exc/gitignore && git check-ignore -v secret.txt sub/secret.txt
.gitignore:1:secret.txt secret.txt
.gitignore:1:secret.txt sub/secret.txt

Repomix's answer differs (run against a build of main at 9f01703a):

bash
$ node bin/repomix.cjs /tmp/exc/gitignore -o /tmp/exc/out-gitignore.txt
<file path=".gitignore">
<file path="keep.txt">

$ node bin/repomix.cjs /tmp/exc/exclude -o /tmp/exc/out-exclude.txt
<file path="sub/secret.txt">   # <-- leaked
<file path="keep.txt">

Expected: sub/secret.txt excluded in both cases, matching Git. Actual: excluded only via .gitignore. The root-level secret.txt is correctly excluded in both, so the exclude file is being read — it just doesn't get Git's semantics below the top level.

Verified by control as well as by comparison: with the pattern line removed from .git/info/exclude, the root secret.txt reappears too, so the exclusion above is coming from that file and not from a default pattern.

Cause

In src/core/file/fileSearch.ts, .gitignore is delegated to globby's own gitignore option, which implements Git's matching rules:

typescript
// src/core/file/fileSearch.ts:427-430 (createBaseGlobbyOptions)
cwd: rootDir,
ignore: ignorePatterns,
gitignore: config.ignore.useGitignore,
ignoreFiles: ignoreFilePatterns,

.git/info/exclude, by contrast, is parsed and merged into repomix's flat pattern set, which is then passed to globby as ordinary cwd-relative globs:

typescript
// src/core/file/fileSearch.ts:490-503
const excludeFilePath = path.join(rootDir, '.git', 'info', 'exclude');
const excludeFileContent = await fs.readFile(excludeFilePath, 'utf8');
const excludePatterns = parseIgnoreContent(excludeFileContent);
for (const pattern of excludePatterns) {
  ignorePatterns.add(pattern);
}

As a glob, secret.txt matches only ./secret.txt; as a gitignore pattern it matches secret.txt at every depth. Same divergence applies to .repomixignore / .ignore and ignore.customPatterns, which go through the same set — those have no Git contract to match, but .git/info/exclude does.

Happy to send a PR if the direction is agreed — the narrow fix is to translate unanchored exclude patterns (no / in the pattern) to **/<pattern> when reading that file, which keeps them aligned with Git without touching the other sources.

Usage Context

Repomix CLI

Repomix Version

1.18.0 (built from main at 9f01703a)

Node.js Version

v24.18.0