Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user guide should anticipate common failure mode (* in $HOME/.gitignore) #815

Closed
ApolloTang opened this issue Feb 18, 2018 · 5 comments
Closed
Labels
doc An issue with or an improvement to documentation.

Comments

@ApolloTang
Copy link

What version of ripgrep are you using?

ripgrep 0.8.0 (rev )
-SIMD -AVX

What operating system are you using ripgrep on?

macOS High Sierra
10.13.3

Bug report

First time on ripgrep, following User Guide

but recursive search does not work !

rg-bug

$ rg 'fn write\(' --debug
DEBUG/grep::search/grep/src/search.rs:195: regex ast:
Literal {
    chars: [
        'f',
        'n',
        ' ',
        'w',
        'r',
        'i',
        't',
        'e',
        '('
    ],
    casei: false
}
DEBUG/grep::literals/grep/src/literals.rs:38: literal prefixes detected: Literals { lits: [Complete(fn write()], limit_size: 250, limit_class: 10 }
DEBUG/globset/globset/src/lib.rs:401: built glob set; 0 literals, 1 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG/globset/globset/src/lib.rs:396: glob converted to regex: Glob { glob: "**/*", re: "(?-u)^(?:/?|.*/).*$", opts: GlobOptions { case_insensitive: false, literal_separator: false }, tokens: Tokens([RecursivePrefix, ZeroOrMore]) }
DEBUG/globset/globset/src/lib.rs:396: glob converted to regex: Glob { glob: "**/*", re: "(?-u)^(?:/?|.*/).*$", opts: GlobOptions { case_insensitive: false, literal_separator: false }, tokens: Tokens([RecursivePrefix, ZeroOrMore]) }
DEBUG/globset/globset/src/lib.rs:396: glob converted to regex: Glob { glob: "**/._*", re: "(?-u)^(?:/?|.*/)\\._.*$", opts: GlobOptions { case_insensitive: false, literal_separator: false }, tokens: Tokens([RecursivePrefix, Literal('.'), Literal('_'), ZeroOrMore]) }
DEBUG/globset/globset/src/lib.rs:401: built glob set; 0 literals, 28 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 3 regexes
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./.gitignore__: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./Cargo.toml: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./CHANGELOG.md: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./complete: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./globset: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./ignore: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./ci: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./benchsuite: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./tests: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./Cargo.lock: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./build.rs: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./HomebrewFormula: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./grep: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./README.md: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./termcolor: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./appveyor.yml: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./COPYING: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./UNLICENSE: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./compile: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./doc: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./wincolor: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./.travis.yml: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./snapcraft.yaml: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./LICENSE-MIT: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./pkg: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
DEBUG/ignore::walk/ignore/src/walk.rs:1392: ignoring ./src: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/apollotang/.gitignore"), original: "*/", actual: "**/*", is_whitelist: false, is_only_dir: true })))
No files were searched, which means ripgrep probably applied a filter you didn't expect. Try running again with --debug.
~/Desktop/ripgrep-0.7.1
$
@okdana
Copy link
Contributor

okdana commented Feb 18, 2018

The debug output explains it: rg has traversed up the file tree, where it found ~/.gitignore, which contains the rule *, which makes it ignore all files.

You can control which ignore files rg respects with -u, --no-ignore, --no-ignore-vcs, --no-ignore-parent, and so on. --no-ignore-parent might be the easiest thing here.

I wonder if it would make sense for there to be an option to make rg stop looking for parent .gitignore files once it encounters a parent containing a .git directory? That way it'd only respect the VCS ignores for the current repo. Might not be reliable or a common enough problem, idk

@ApolloTang
Copy link
Author

Thanks for quick response @okdana, Yes I do have a legacy .gitignore in my ~/ and I completely forgot all about it.

@BurntSushi
Copy link
Owner

I wonder if it would make sense for there to be an option to make rg stop looking for parent .gitignore files once it encounters a parent containing a .git directory? That way it'd only respect the VCS ignores for the current repo. Might not be reliable or a common enough problem, idk

This should actually be the current behavior:

ripgrep/tests/tests.rs

Lines 615 to 644 in 9b7f420

sherlock!(ignore_git_parent_stop, "Sherlock", ".",
|wd: WorkDir, mut cmd: Command| {
// This tests that searching parent directories for .gitignore files stops
// after it sees a .git directory. To test this, we create this directory
// hierarchy:
//
// .gitignore (contains `sherlock`)
// foo/
// .git
// bar/
// sherlock
//
// And we perform the search inside `foo/bar/`. ripgrep will stop looking
// for .gitignore files after it sees `foo/.git/`, and therefore not
// respect the top-level `.gitignore` containing `sherlock`.
wd.remove("sherlock");
wd.create(".gitignore", "sherlock\n");
wd.create_dir("foo");
wd.create_dir("foo/.git");
wd.create_dir("foo/bar");
wd.create("foo/bar/sherlock", hay::SHERLOCK);
cmd.current_dir(wd.path().join("foo").join("bar"));
let lines: String = wd.stdout(&mut cmd);
let expected = "\
sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock
sherlock:be, to a very large extent, the result of luck. Sherlock Holmes
";
assert_eq!(lines, expected);
});

The problem here is that the guide instructs folks to download a zip containing the source, which, when unpacked, isn't actually a git directory.

@okdana
Copy link
Contributor

okdana commented Feb 18, 2018

Oh, lol. Well then.

@BurntSushi BurntSushi added the doc An issue with or an improvement to documentation. label Feb 20, 2018
@BurntSushi
Copy link
Owner

I'm going to re-open this. I think the * in $HOME/.gitignore is a common enough pattern that it would probably be wise to explicitly call this out in the user guide somewhere.

@BurntSushi BurntSushi reopened this Feb 20, 2018
@BurntSushi BurntSushi changed the title First time on ripgrep, following User Guide, but recursive search doesn't work user guide should anticipate common failure mode (* in $HOME/.gitignore) Feb 20, 2018
BurntSushi added a commit that referenced this issue Feb 21, 2018
This adds a hint for end users that run into a common failure mode where
ripgrep won't search any files because they have a `*` rule in their
`$HOME/.gitignore`.

Fixes #815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc An issue with or an improvement to documentation.
Projects
None yet
Development

No branches or pull requests

3 participants