1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-03-03 14:32:22 +02:00

ignore: support .git directory OR file

This improves support for submodules, which seem to use a '.git' file
instead of a '.git' directory to indicate a worktree.

Fixes #893
This commit is contained in:
Andrew Gallant 2018-04-23 18:33:25 -04:00
parent 2a9d007261
commit 507801c1f2
No known key found for this signature in database
GPG Key ID: B2E3A4923F8B0D44
2 changed files with 35 additions and 2 deletions

View File

@ -254,7 +254,7 @@ impl Ignore {
git_global_matcher: self.0.git_global_matcher.clone(),
git_ignore_matcher: gi_matcher,
git_exclude_matcher: gi_exclude_matcher,
has_git: dir.join(".git").is_dir(),
has_git: dir.join(".git").exists(),
opts: self.0.opts,
};
(ig, errs.into_error_option())

View File

@ -651,7 +651,7 @@ sherlock!(ignore_git_parent_stop, "Sherlock", ".",
//
// .gitignore (contains `sherlock`)
// foo/
// .git
// .git/
// bar/
// sherlock
//
@ -674,6 +674,39 @@ sherlock:be, to a very large extent, the result of luck. Sherlock Holmes
assert_eq!(lines, expected);
});
// Like ignore_git_parent_stop, but with a .git file instead of a .git
// directory.
sherlock!(ignore_git_parent_stop_file, "Sherlock", ".",
|wd: WorkDir, mut cmd: Command| {
// This tests that searching parent directories for .gitignore files stops
// after it sees a .git *file*. A .git file is used for submodules. 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("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);
});
sherlock!(ignore_ripgrep_parent_no_stop, "Sherlock", ".",
|wd: WorkDir, mut cmd: Command| {
// This is like the `ignore_git_parent_stop` test, except it checks that