scm: implement gitignore (#5243)

* scm: implement gitignore; use `pygit2` backend

* Add is_ignored implementation on `pygit2` and `gitpython` backends.
* Also implement `._reset()` on `repo.scm` which is most of the changes.

* fix tests

* use _backend_func

* minor fixups
This commit is contained in:
Saugat Pachhai
2021-01-11 12:31:26 +02:00
committed by GitHub
parent 7fd191126e
commit a2c91d2058
8 changed files with 59 additions and 14 deletions
+6 -3
View File
@@ -5,7 +5,7 @@ import os
from functools import partial
from typing import Callable, Iterable, Mapping, Optional, Tuple
from funcy import first
from funcy import first, ignore
from dvc.progress import Tqdm
from dvc.scm.base import CloneError, RevError, SCMError
@@ -111,8 +111,11 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method
def git(self):
return self.repo.git
def is_ignored(self, path):
raise NotImplementedError
def is_ignored(self, path: str) -> bool:
from git.exc import GitCommandError
func = ignore(GitCommandError)(self.repo.git.check_ignore)
return bool(func(path))
@property
def root_dir(self) -> str: