diff options
author | Canop <cano.petrole@gmail.com> | 2020-09-06 16:09:10 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-09-06 16:09:10 +0200 |
commit | 84995c105161aa7641ab2042fd58ef2d26354b05 (patch) | |
tree | a5b3da1731fdcfc86f10fe2349abf43247f4c80f /src/git/ignore.rs | |
parent | 1b4f7c40e1a7a27e5e72f8d63f4565acad7fdd72 (diff) |
don't gitignore files when not in a git repository
.gitignore files, including the global one, aren't used anymore
when not in a git repository
Fix #274
Diffstat (limited to 'src/git/ignore.rs')
-rw-r--r-- | src/git/ignore.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/git/ignore.rs b/src/git/ignore.rs index ca67a5f..e10e77b 100644 --- a/src/git/ignore.rs +++ b/src/git/ignore.rs @@ -105,6 +105,7 @@ pub fn find_global_ignore() -> Option<GitIgnoreFile> { #[derive(Debug, Clone, Default)] pub struct GitIgnoreChain { + in_repo: bool, file_ids: Vec<Id<GitIgnoreFile>>, } impl GitIgnoreChain { @@ -142,6 +143,7 @@ impl GitIgnorer { chain.push(self.files.alloc(gif)); } if is_repo(dir) { + chain.in_repo = true; break; } if let Some(parent) = dir.parent() { @@ -158,16 +160,21 @@ impl GitIgnorer { // we don't want the .gitignore files of super repositories // (see https://github.com/Canop/broot/issues/160) let mut chain = if is_repo(dir) { - self.global_chain.clone() + let mut chain = self.global_chain.clone(); + chain.in_repo = true; + chain } else { parent_chain.clone() }; - let ignore_file = dir.join(".gitignore"); - if let Ok(gif) = GitIgnoreFile::new(&ignore_file) { - chain.push(self.files.alloc(gif)); + if chain.in_repo { + let ignore_file = dir.join(".gitignore"); + if let Ok(gif) = GitIgnoreFile::new(&ignore_file) { + chain.push(self.files.alloc(gif)); + } } chain } + /// return true if the given path should not be ignored pub fn accepts( &self, chain: &GitIgnoreChain, @@ -175,6 +182,11 @@ impl GitIgnorer { filename: &str, directory: bool, ) -> bool { + if !chain.in_repo { + // if we're not in a git repository, then .gitignore files, including + // the global ones, are irrelevant + return true; + } // we start with deeper files: deeper rules have a bigger priority for id in chain.file_ids.iter().rev() { let file = &self.files[*id]; |