-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
check root .gitignore in '_ignored' #3284
Changes from 2 commits
8a76742
4d772fe
fd75bbd
72919ee
ea61fa6
468daec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,7 +18,6 @@ | |||||
from dvc.utils import relpath | ||||||
from dvc.utils.fs import path_isin | ||||||
|
||||||
|
||||||
logger = logging.getLogger(__name__) | ||||||
|
||||||
|
||||||
|
@@ -133,15 +132,24 @@ def _get_gitignore(self, path): | |||||
|
||||||
return entry, gitignore | ||||||
|
||||||
@staticmethod | ||||||
def _ignored(entry, gitignore_path): | ||||||
if os.path.exists(gitignore_path): | ||||||
with open(gitignore_path, "r") as fobj: | ||||||
ignore_list = fobj.readlines() | ||||||
return any( | ||||||
filter(lambda x: x.strip() == entry.strip(), ignore_list) | ||||||
) | ||||||
return False | ||||||
def _ignored(self, entry, gitignore_path): | ||||||
|
||||||
# We want to check first if `entry` is already being ignored | ||||||
# by the .gitignore file in the root dir. | ||||||
|
||||||
entry = ( | ||||||
entry[1:] if entry[0] == "/" else entry | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it won't be needed if we just pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm don't know what happened there haha |
||||||
) # make sure that joining the paths works | ||||||
entry_path = os.path.join(os.path.dirname(gitignore_path), entry) | ||||||
from git.exc import GitCommandError | ||||||
|
||||||
try: | ||||||
self.repo.git.check_ignore(entry_path) | ||||||
return True | ||||||
except GitCommandError: | ||||||
# If none of the paths passed to `check_ignore` are ignored, | ||||||
# GitPython annoyingly raises an Exception | ||||||
return False | ||||||
|
||||||
def ignore(self, path): | ||||||
entry, gitignore = self._get_gitignore(path) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simply pass
path
to it now, since we no longer work with entries. π Your PR is helping tidy this a lot π