Skip to content

globset (and thus ripgrep) interpret braces ({}) as alternative ("a or b") whereas git doesn't #1221

Open
@anntzer

Description

@anntzer

What version of ripgrep are you using?

ripgrep 0.9.0
-SIMD -AVX

How did you install ripgrep?

Fedora 29 distro package.

What operating system are you using ripgrep on?

Fedora 29.

Describe your question, feature request, or bug.

globset (and thus ripgrep) interpret braces ({}) as alternative ("a or b") whereas git doesn't, causing a different interpretation of entries containing braces in .gitignore.

If this is a bug, what are the steps to reproduce the behavior?

git init foo && cd foo
touch 'test.txt' 'test.txt{}'
echo '*.txt{}' >.gitignore
git status
rg --files --debug

If this is a bug, what is the actual behavior?

$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        foo.txt

nothing added to commit but untracked files present (use "git add" to track)

$ rg --files --debug
DEBUG/grep::search//usr/share/cargo/registry/grep-0.1.9/src/search.rs:195: original regex HIR pattern:
(?:[Zz]{0})*
DEBUG/grep::search//usr/share/cargo/registry/grep-0.1.9/src/search.rs:197: transformed regex HIR pattern:
(?:[Zz]{0})*
DEBUG/globset//usr/share/cargo/registry/globset-0.4.1/src/lib.rs:429: built glob set; 0 literals, 1 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG/globset//usr/share/cargo/registry/globset-0.4.1/src/lib.rs:424: glob converted to regex: Glob { glob: "**/*.txt{}", re: "(?-u)^(?:/?|.*/).*\\.txt$", opts: GlobOptions { case_insensitive: false, literal_separator: false, backslash_escape: true }, tokens: Tokens([RecursivePrefix, ZeroOrMore, Literal('.'), Literal('t'), Literal('x'), Literal('t'), Alternates([Tokens([])])]) }
DEBUG/globset//usr/share/cargo/registry/globset-0.4.1/src/lib.rs:429: built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 1 regexes
DEBUG/ignore::walk//usr/share/cargo/registry/ignore-0.4.3/src/walk.rs:1414: ignoring ./foo.txt: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("./.gitignore"), original: "*.txt{}", actual: "**/*.txt{}", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk//usr/share/cargo/registry/ignore-0.4.3/src/walk.rs:1414: ignoring ./.git: Ignore(IgnoreMatch(Override(Glob(Matched(Glob { from: None, original: "!.git", actual: "**/.git", is_whitelist: true, is_only_dir: false })))))
.gitignore
foo.txt{}

If this is a bug, what is the expected behavior?

rg --files should list foo.txt and ignore foo.txt{} (matching git's behavior), not the opposite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions