gitignore: use unambiguous paths

Fixes #1324

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-11-14 14:43:00 +02:00
parent 88ed542b94
commit 6de91c0b28
3 changed files with 8 additions and 6 deletions
+2 -1
View File
@@ -151,7 +151,8 @@ class Git(Base):
def _get_gitignore(self, path):
assert os.path.isabs(path)
entry = os.path.basename(path)
# NOTE: using '/' prefix to make path unambiguous
entry = '/' + os.path.basename(path)
gitignore = os.path.join(os.path.dirname(path), self.GITIGNORE)
if not gitignore.startswith(self.root_dir):
+4 -4
View File
@@ -205,8 +205,8 @@ class TestGitIgnoreBasic(CheckoutBase):
self.assertEqual(len(ignored), 2)
self.assertIn(fname1, ignored)
self.assertIn(fname2, ignored)
self.assertIn('/' + fname1, ignored)
self.assertIn('/' + fname2, ignored)
class TestGitIgnoreWhenCheckout(CheckoutBase):
@@ -232,13 +232,13 @@ class TestGitIgnoreWhenCheckout(CheckoutBase):
ignored = self.read_ignored()
self.assertEqual(len(ignored), 1)
self.assertIn(fname_master, ignored)
self.assertIn('/' + fname_master, ignored)
self.dvc.scm.checkout(branch_1)
ret = main(['checkout'])
self.assertEqual(ret, 0)
ignored = self.read_ignored()
self.assertIn(fname_branch, ignored)
self.assertIn('/' + fname_branch, ignored)
class TestCheckoutMissingMd5InStageFile(TestRepro):
+2 -1
View File
@@ -45,7 +45,8 @@ class TestIgnore(TestGit):
def _count_gitignore(self):
with open(Git.GITIGNORE, 'r') as fd:
lines = fd.readlines()
return len(list(filter(lambda x: x.strip() == 'foo', lines)))
return len(list(filter(lambda x: x.strip() == '/' + self.FOO,
lines)))
def test(self):
git = Git(self._root_dir)