Skip to content

Repomix now fails on repos using backslash in .gitignore patterns #1765

Description

@iki

Description

Issue Description

When running repomix on repositories that contain .gitignore files with certain backslash-escaped patterns, it fails with error during the file filtering phase.

The underlying path validation (likely from the ignore npm package) throws an error because it encounters a string it doesn't consider a valid relative path.

Steps to Reproduce

You can reproduce this by running Repomix against the following repositories:

Test Case 1: Microsoft Data Formulator

  1. Run repomix --remote https://github.com/microsoft/data-formulator
    • Error: Error filtering files: path should be a path.relative()d string, but got "\.\NUL"
    • Failing file: data-formulator/.gitignore

Test Case 2: Claude Code (Best)

  1. Run repomix --remote https://github.com/claude-code-best/claude-code

Solution Discussion

To fix this robustly, we need to look at both the Git specification and how the file-filtering library processes paths.

1. What's the real meaning of a backslash in a .gitignore definition?

According to the official Git documentation:

  • A backslash (\) is strictly used as an escape character. It is used to escape characters that would otherwise be treated as special syntax (e.g., \!, \#, \*, \?).
  • To ignore a literal backslash, it must be escaped as well (\\).
  • Crucially: A backslash is never used as a directory separator in .gitignore, even on Windows. Directory separators are always forward slashes (/).

2. How to handle this best in Repomix?

Currently, it seems Repomix (or its dependency, like ignore) is either incorrectly parsing these escaped rules as file paths, or failing when testing actual files/strings that contain backslashes.

To respect the .gitignore meaning while preventing failing with error, Repomix could implement the following:

  • Sanitize Paths Before Validation: Ensure that any string passed to the path-checking/filtering utility is properly normalized to a valid relative path (using forward slashes /).
  • Graceful Degradation (Try/Catch): Wrap the file filtering check (e.g., the .ignores() call) in a try...catch block. If a specific path or rule causes the underlying library to throw a path should be a path.relative()d string error, Repomix should log a verbose warning and safely skip that specific file/rule, rather than failing the entire packing process with error.
  • Respect Escape Sequences: Ensure the internal globber or gitignore parser isn't accidentally transforming \* or \. into malformed file paths during its traversal phase.

By implementing a fallback/catch for malformed paths, Repomix will become much more resilient to the wild variations of .gitignore files found in the open-source ecosystem.

Usage Context

Repomix CLI

Repomix Version

1.17.0

Node.js Version

v26.5.0

EDIT: Replace AI Agent crash wording. There's no crash, just fail with error. Also fixed links

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions