Skip to content

Commit

Permalink
Respect gitignores for both .git and .sl directories
Browse files Browse the repository at this point in the history
Summary: rg only respects gitignores for directories containing or with a
parent containing a `.git` directory.
[Sapling](https://sapling-scm.com/docs/introduction/) is a VCS tool that works
with git repositories (and is what I'm using to make this commit), but uses
`.sl` instead of `.git`.  This commit respect gitignores for both `.git` and
`.sl` directories

Test Plan: `tests/misc.rs`
  • Loading branch information
vegerot committed Dec 29, 2022
1 parent 6110128 commit ebf17ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/ignore/src/dir.rs
Expand Up @@ -204,7 +204,7 @@ impl Ignore {
igtmp.absolute_base = Some(absolute_base.clone());
igtmp.has_git =
if self.0.opts.require_git && self.0.opts.git_ignore {
parent.join(".git").exists()
parent.join(".git").exists() || parent.join(".sl").exists()
} else {
false
};
Expand Down Expand Up @@ -796,7 +796,7 @@ fn resolve_git_commondir(
git_type: Option<FileType>,
) -> Result<PathBuf, Option<Error>> {
let git_dir_path = || dir.join(".git");
let git_dir = git_dir_path();
let git_dir = git_dir_path()
if !git_type.map_or(false, |ft| ft.is_file()) {
return Ok(git_dir);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/misc.rs
Expand Up @@ -578,6 +578,29 @@ rgtest!(ignore_git, |dir: Dir, mut cmd: TestCommand| {
cmd.assert_err();
});


rgtest!(uses_gitignore, |dir: Dir, mut cmd: TestCommand| {
dir.create("file1", "hi");
dir.create("file2", "hi");
dir.create_dir(".git");
dir.create(".gitignore", "file1\n");
cmd.arg("hi");

//cmd.assert_err();
eqnice!("file2:hi\n", cmd.stdout());
});

rgtest!(uses_gitignore_for_sapling, |dir: Dir, mut cmd: TestCommand| {
dir.create("file1", "hi");
dir.create("file2", "hi");
dir.create_dir(".sl");
dir.create(".gitignore", "file1\n");
cmd.arg("hi");

//cmd.assert_err();
eqnice!("file1:hi\n", cmd.stdout());
});

rgtest!(ignore_generic, |dir: Dir, mut cmd: TestCommand| {
dir.create("sherlock", SHERLOCK);
dir.create(".ignore", "sherlock\n");
Expand Down

0 comments on commit ebf17ee

Please sign in to comment.