diff --git a/ignore/src/dir.rs b/ignore/src/dir.rs index 77ee6ad3..13065c3d 100644 --- a/ignore/src/dir.rs +++ b/ignore/src/dir.rs @@ -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()) diff --git a/tests/tests.rs b/tests/tests.rs index 855f2484..cab1f42d 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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