#1873·repomix

[BUG] Negation rules in .git/info/exclude are inert, unlike the same rules in .gitignore

Author: sxh313Created Sep 21, 2026Updated Sep 21, 2026
Labelsbugneeds discussion

Description

! re-inclusion rules in .git/info/exclude have no effect. The same two lines placed in .gitignore behave exactly like Git, so the exclude file is the odd one out:

rule source important.log (Git packs) nested/a.log (Git ignores)
.gitignore packed ✅ not packed ✅
.git/info/exclude not packed ❌ packed ❌

Reproduces on main at 9f01703a built from source (npm run build, then node bin/repomix.cjs). It is a pre-existing difference, not a regression from any open PR — see the note at the bottom.

Steps to Reproduce

Two directories with the same content and the same two rules, one in .gitignore and one in .git/info/exclude. Repomix needs commits, hence the git commit.

bash
mk() {
  rm -rf "$1"; mkdir -p "$1/nested" "$1/src"
  cd "$1" || return 1
  for f in a.log important.log nested/a.log nested/important.log; do printf 'x\n' > "$f"; done
  printf 'export const a=1;\n' > src/index.ts
  git init -q .
}

mk ignore-side;  printf '%s\n' '*.log' '!important.log' > ignore-side/.gitignore
mk exclude-side; printf '%s\n' '*.log' '!important.log' > exclude-side/.git/info/exclude

for d in ignore-side exclude-side; do
  echo "### $d"
  ( cd $d
    git add -A && git -c user.name=t -c user.email=t@t commit -qm init
    for f in a.log important.log nested/a.log nested/important.log; do
      printf '  git  %-20s %s\n' "$f" "$(git check-ignore -q "$f" && echo IGNORED || echo packed)"
    done
    repomix . -o - --no-default-patterns 2>/dev/null \
      | grep -o 'path="[^"]*"' | sed 's/path="//; s/"//' | grep '\.log$' | sort | sed 's/^/  repomix  /'
  )
done

--no-default-patterns keeps .log out of the built-in list so the only rule in play is the one under test.

Git ground truth (both directories, identical)

  git  a.log                IGNORED
  git  important.log        packed
  git  nested/a.log         IGNORED
  git  nested/important.log packed

Actual: rules in .gitignore

  repomix  important.log
  repomix  nested/important.log

Matches Git. *.log is honoured at any depth and !important.log brings both copies back.

Actual: the same rules in .git/info/exclude

  repomix  nested/a.log
  repomix  nested/important.log

important.log disappears even though Git packs it, and nested/a.log is packed even though Git ignores it. Neither rule's negation is honoured.

Expected Behavior

A file Git tracks is packed, and a file Git ignores is not — the same as for .gitignore.

Cause

getIgnorePatterns() pushes the parsed exclude lines into the flat pattern list (src/core/file/fileSearch.ts:490-503, the add is line 499):

typescript
const excludePatterns = parseIgnoreContent(excludeFileContent);

for (const pattern of excludePatterns) {
  ignorePatterns.add(pattern);
}

and that list becomes globby's ignore option (src/core/file/fileSearch.ts:421-431):

typescript
{
  cwd: rootDir,
  ignore: ignorePatterns,
  gitignore: config.ignore.useGitignore,
  ignoreFiles: ignoreFilePatterns,
}

ignore is exclusion-only — every entry removes matches and nothing can put them back, so a ! entry is inert (it neither excludes nor re-includes). .gitignore and the .ignore / .repomixignore files (:450, :453) go through gitignore / ignoreFiles instead, which is globby's Git-compatible matcher: ordered rules, last match wins, plus directory pruning that keeps a re-includable subtree. That is why the identical content behaves differently depending on which file it lives in.

Fix direction

.git/info/exclude needs the same treatment the other ignore-control files get — Git's ordered evaluation rather than a merge into ignore. Two shapes that look workable:

  • Hand the exclude content to globby's ignore-file machinery so it goes through the same matcher as .gitignore. The base directory needs care: Git anchors the exclude file at the worktree root, whereas a file discovered under .git/info/ would otherwise be relative to that directory.
  • Or evaluate the exclude rules after discovery with a Git-compatible matcher (ordered last-match-wins, and Git's rule that a file cannot be re-included when a parent directory is excluded), keeping only the rules that provably cannot be re-included in ignore so directory pruning is preserved.

Happy to implement whichever you prefer.

Note on #1871

#1871 lifts slash-free exclude patterns to **/<pattern> so they match at any depth, which fixes the nested/a.log half of this table for rule sets without negations. That PR deliberately leaves a rule set containing a ! untouched, precisely so it cannot make this case worse: measured, main and #1871 give byte-identical output for the exclude-side fixture above.

System Info

  • CLI (repomix)
  • Repomix Version: 1.18.0, built from main at 9f01703a
  • Node.js Version: v24.18.0
  • Platform: Windows 11 (win32, x64)