mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-16 22:42:20 +02:00
ignore: support backslash escaping
Use the new `Globset::backslash_escape` knob to conform to git behavior: `\` will escape the following character. For example, the pattern `\*` will match a file literally named `*`. Also tweak a test in ripgrep that was relying on this incorrect behavior. Closes #526, Closes #811
This commit is contained in:
committed by
Andrew Gallant
parent
54256515b4
commit
91d0756f62
@ -477,6 +477,7 @@ impl GitignoreBuilder {
|
|||||||
GlobBuilder::new(&glob.actual)
|
GlobBuilder::new(&glob.actual)
|
||||||
.literal_separator(literal_separator)
|
.literal_separator(literal_separator)
|
||||||
.case_insensitive(self.case_insensitive)
|
.case_insensitive(self.case_insensitive)
|
||||||
|
.backslash_escape(true)
|
||||||
.build()
|
.build()
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
Error::Glob {
|
Error::Glob {
|
||||||
@ -635,6 +636,10 @@ mod tests {
|
|||||||
ignored!(ig35, "./.", ".a/b", ".a/b");
|
ignored!(ig35, "./.", ".a/b", ".a/b");
|
||||||
ignored!(ig36, "././", ".a/b", ".a/b");
|
ignored!(ig36, "././", ".a/b", ".a/b");
|
||||||
ignored!(ig37, "././.", ".a/b", ".a/b");
|
ignored!(ig37, "././.", ".a/b", ".a/b");
|
||||||
|
ignored!(ig38, ROOT, "\\[", "[");
|
||||||
|
ignored!(ig39, ROOT, "\\?", "?");
|
||||||
|
ignored!(ig40, ROOT, "\\*", "*");
|
||||||
|
ignored!(ig41, ROOT, "\\a", "a");
|
||||||
|
|
||||||
not_ignored!(ignot1, ROOT, "amonths", "months");
|
not_ignored!(ignot1, ROOT, "amonths", "months");
|
||||||
not_ignored!(ignot2, ROOT, "monthsa", "months");
|
not_ignored!(ignot2, ROOT, "monthsa", "months");
|
||||||
|
@ -800,11 +800,7 @@ clean!(regression_25, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/30
|
// See: https://github.com/BurntSushi/ripgrep/issues/30
|
||||||
clean!(regression_30, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
clean!(regression_30, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
if cfg!(windows) {
|
wd.create(".gitignore", "vendor/**\n!vendor/manifest");
|
||||||
wd.create(".gitignore", "vendor/**\n!vendor\\manifest");
|
|
||||||
} else {
|
|
||||||
wd.create(".gitignore", "vendor/**\n!vendor/manifest");
|
|
||||||
}
|
|
||||||
wd.create_dir("vendor");
|
wd.create_dir("vendor");
|
||||||
wd.create("vendor/manifest", "test");
|
wd.create("vendor/manifest", "test");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user