Repository: iterative/dvc

Issue:
gitignore: use unambiguous paths
E.g. `/dir` instead of `dir`.

Discussion:

Patch:
diff --git a/dvc/scm.py b/dvc/scm.py
index e49039721..e32ed2913 100644
--- a/dvc/scm.py
+++ b/dvc/scm.py
@@ -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):


Test patch:
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index 4e46fcde0..228dbffc7 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -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):
diff --git a/tests/test_scm.py b/tests/test_scm.py
index 2e134c24c..fd24fbf11 100644
--- a/tests/test_scm.py
+++ b/tests/test_scm.py
@@ -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)