Skip to content

Commit

Permalink
Merge pull request iterative#2481 from efiop/2476
Browse files Browse the repository at this point in the history
scm: remove `pkg install` leftovers
  • Loading branch information
efiop authored Sep 9, 2019
2 parents a529f7d + ce27444 commit b0b958e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 51 deletions.
5 changes: 0 additions & 5 deletions dvc/scm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class FileNotInCommitError(SCMError):
"""


class FileNotInTargetSubdirError(SCMError):
"""Thrown when trying to place .gitignore for a file that not in
the file subdirectory."""


class CloneError(SCMError):
def __init__(self, url, path, cause):
super(CloneError, self).__init__(
Expand Down
18 changes: 3 additions & 15 deletions dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
Base,
SCMError,
FileNotInRepoError,
FileNotInTargetSubdirError,
CloneError,
RevError,
)
Expand Down Expand Up @@ -104,22 +103,12 @@ def dir(self):
def ignore_file(self):
return self.GITIGNORE

def _get_gitignore(self, path, ignore_file_dir=None):
if not ignore_file_dir:
ignore_file_dir = os.path.dirname(os.path.realpath(path))
def _get_gitignore(self, path):
ignore_file_dir = os.path.dirname(path)

assert os.path.isabs(path)
assert os.path.isabs(ignore_file_dir)

if not path.startswith(ignore_file_dir):
msg = (
"{} file has to be located in one of '{}' subdirectories"
", not outside '{}'"
)
raise FileNotInTargetSubdirError(
msg.format(self.GITIGNORE, path, ignore_file_dir)
)

entry = relpath(path, ignore_file_dir).replace(os.sep, "/")
# NOTE: using '/' prefix to make path unambiguous
if len(entry) > 0 and entry[0] != "/":
Expand All @@ -143,8 +132,7 @@ def _ignored(entry, gitignore_path):
return False

def ignore(self, path):
base_dir = os.path.dirname(path)
entry, gitignore = self._get_gitignore(path, base_dir)
entry, gitignore = self._get_gitignore(path)

if self._ignored(entry, gitignore):
return
Expand Down
40 changes: 9 additions & 31 deletions tests/func/test_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import os

import pytest
from git import Repo

from dvc.system import System
from dvc.utils.compat import str # noqa: F401
from dvc.scm import SCM, NoSCM, Git
from dvc.scm.base import FileNotInTargetSubdirError

from tests.basic_env import TestDir, TestGit, TestGitSubmodule
from tests.utils import get_gitignore_content
Expand Down Expand Up @@ -97,6 +96,14 @@ def test_get_gitignore(self, git, repo_dir):
assert entry == "/dir"
assert gitignore == os.path.join(repo_dir._root_dir, Git.GITIGNORE)

def test_get_gitignore_symlink(self, git, repo_dir):
link = os.path.join(repo_dir.root_dir, "link")
target = os.path.join(repo_dir.root_dir, repo_dir.DATA_SUB)
System.symlink(target, link)
entry, gitignore = Git(repo_dir._root_dir)._get_gitignore(link)
assert entry == "/link"
assert gitignore == os.path.join(repo_dir.root_dir, Git.GITIGNORE)

def test_get_gitignore_subdir(self, git, repo_dir):
data_dir = os.path.join(
repo_dir._root_dir, os.path.join("dir1", "file1")
Expand All @@ -116,35 +123,6 @@ def test_get_gitignore_subdir(self, git, repo_dir):
repo_dir._root_dir, "dir1", Git.GITIGNORE
)

def test_get_gitignore_ignorefile_dir(self, git, repo_dir):
git = Git(repo_dir._root_dir)

file_double_dir = os.path.join("dir1", "dir2", "file1")
data_dir1 = os.path.join(repo_dir._root_dir, file_double_dir)
dir1_real1 = os.path.realpath("dir1")
entry, gitignore = git._get_gitignore(data_dir1, dir1_real1)
assert entry == "/dir2/file1"
gitignore1 = os.path.join(repo_dir._root_dir, "dir1", Git.GITIGNORE)
assert gitignore == gitignore1

triple_dir = os.path.join("dir1", "dir2", "dir3")
data_dir2 = os.path.join(repo_dir._root_dir, triple_dir)
dir1_real2 = os.path.realpath("dir1")
entry, gitignore = git._get_gitignore(data_dir2, dir1_real2)
assert entry == "/dir2/dir3"
gitignore2 = os.path.join(repo_dir._root_dir, "dir1", Git.GITIGNORE)
assert gitignore == gitignore2

def test_get_gitignore_ignorefile_dir_upper_level(self, git, repo_dir):
git = Git(repo_dir._root_dir)

file_double_dir = os.path.join("dir1", "dir2", "file1")
data_dir1 = os.path.join(repo_dir._root_dir, file_double_dir)
ignore_file_dir = os.path.realpath(os.path.join("aa", "bb"))

with pytest.raises(FileNotInTargetSubdirError):
git._get_gitignore(data_dir1, ignore_file_dir)

def test_gitignore_should_end_with_newline(self, git, repo_dir):
git = Git(repo_dir._root_dir)

Expand Down

0 comments on commit b0b958e

Please sign in to comment.