Skip to content
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

Merged
merged 6 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed method input, adjusted tests, formatted code
  • Loading branch information
AljoSt committed Feb 6, 2020
commit fd75bbdb47fc4225b98b3bdabcf604bc7201b91f
11 changes: 3 additions & 8 deletions dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,14 @@ def _get_gitignore(self, path):

return entry, gitignore

def _ignored(self, entry, gitignore_path):
def _ignored(self, 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
) # 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)
self.repo.git.check_ignore(path)
return True
except GitCommandError:
# If none of the paths passed to `check_ignore` are ignored,
Expand All @@ -154,7 +149,7 @@ def _ignored(self, entry, gitignore_path):
def ignore(self, path):
entry, gitignore = self._get_gitignore(path)

if self._ignored(entry, gitignore):
if self._ignored(path):
return

msg = "Adding '{}' to '{}'.".format(relpath(path), relpath(gitignore))
Expand Down
4 changes: 2 additions & 2 deletions tests/func/test_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def test_ignored(tmp_dir, scm):
tmp_dir.gen({"dir1": {"file1.jpg": "cont", "file2.txt": "cont"}})
tmp_dir.gen({".gitignore": "dir1/*.jpg"})

assert scm._ignored("file1.jpg", fspath(tmp_dir / "dir1" / ".gitignore"))
assert not scm._ignored("file2.txt", fspath(tmp_dir / "dir1" / ".gitignore"))
assert scm._ignored(fspath(tmp_dir / "dir1" / "file1.jpg"))
assert not scm._ignored(fspath(tmp_dir / "dir1" / "file2.txt"))


def test_get_gitignore(tmp_dir, scm):
Expand Down