Kaynağa Gözat

Require that callers pass in a relative path to IgnoreFilterManager.

Jelmer Vernooij 7 yıl önce
ebeveyn
işleme
6e4a4d61c0
3 değiştirilmiş dosya ile 10 ekleme ve 10 silme
  1. 1 1
      dulwich/ignore.py
  2. 4 4
      dulwich/porcelain.py
  3. 5 5
      dulwich/tests/test_ignore.py

+ 1 - 1
dulwich/ignore.py

@@ -296,7 +296,7 @@ class IgnoreFilterManager(object):
         :return: Iterator over Pattern instances
         """
         if os.path.isabs(path):
-            path = os.path.relpath(path, self._top_path)
+            raise ValueError('%s is an absolute path' % path)
         filters = [(0, f) for f in self._global_filters]
         if os.path.sep != '/':
             path = path.replace(os.path.sep, '/')

+ 4 - 4
dulwich/porcelain.py

@@ -345,15 +345,15 @@ def add(repo=".", paths=None):
         if not isinstance(paths, list):
             paths = [paths]
         for p in paths:
-            if ignore_manager.is_ignored(p):
-                ignored.add(p)
-                continue
-
             # FIXME: Support patterns, directories.
             if os.path.isabs(p) and p.startswith(repo.path):
                 relpath = os.path.relpath(p, repo.path)
             else:
                 relpath = p
+
+            if ignore_manager.is_ignored(relpath):
+                ignored.add(relpath)
+                continue
             relpaths.append(relpath)
         r.stage(relpaths)
     return (relpaths, ignored)

+ 5 - 5
dulwich/tests/test_ignore.py

@@ -220,12 +220,12 @@ class IgnoreFilterManagerTests(TestCase):
         m = IgnoreFilterManager.from_repo(repo)
         self.assertTrue(m.is_ignored('dir/blie'))
         self.assertIs(None,
-                      m.is_ignored(os.path.join(repo.path, 'dir', 'bloe')))
-        self.assertIs(None, m.is_ignored(os.path.join(repo.path, 'dir')))
-        self.assertTrue(m.is_ignored(os.path.join(repo.path, 'foo', 'bar')))
-        self.assertTrue(m.is_ignored(os.path.join(repo.path, 'excluded')))
+                      m.is_ignored(os.path.join('dir', 'bloe')))
+        self.assertIs(None, m.is_ignored('dir'))
+        self.assertTrue(m.is_ignored(os.path.join('foo', 'bar')))
+        self.assertTrue(m.is_ignored(os.path.join('excluded')))
         self.assertTrue(m.is_ignored(os.path.join(
-            repo.path, 'dir2', 'fileinignoreddir')))
+            'dir2', 'fileinignoreddir')))
         self.assertFalse(m.is_ignored('dir3'))
         self.assertTrue(m.is_ignored('dir3/'))
         self.assertTrue(m.is_ignored('dir3/bla'))