Explorar o código

gitignore patterns without a trailing slash should match directories too.

gitignore patterns with a trailing slash should match both directories
and files, while patterns with a trailing slash should match only
directories.
Segev Finer %!s(int64=7) %!d(string=hai) anos
pai
achega
b501e4d3a8
Modificáronse 2 ficheiros con 16 adicións e 10 borrados
  1. 4 0
      dulwich/ignore.py
  2. 12 10
      dulwich/tests/test_ignore.py

+ 4 - 0
dulwich/ignore.py

@@ -81,6 +81,10 @@ def translate(pat):
                 res = res + b'[' + stuff + b']'
         else:
             res = res + re.escape(c)
+
+    if not res.endswith(b'/'):
+        res = res + b'/?'
+
     return res + b'\Z'
 
 

+ 12 - 10
dulwich/tests/test_ignore.py

@@ -48,6 +48,7 @@ POSITIVE_MATCH_TESTS = [
     (b"foo/bar", b"foo/**/bar"),
     (b"foo/bla/bar", b"foo/**/bar"),
     (b"foo/bar/", b"bar/"),
+    (b"foo/bar/", b"bar"),
 ]
 
 NEGATIVE_MATCH_TESTS = [
@@ -59,16 +60,17 @@ NEGATIVE_MATCH_TESTS = [
 
 
 TRANSLATE_TESTS = [
-    (b"*.c", b'(?ms)(.*/)?[^/]+\\.c\\Z'),
-    (b"foo.c", b'(?ms)(.*/)?foo\\.c\\Z'),
-    (b"/*.c", b'(?ms)[^/]+\\.c\\Z'),
-    (b"/foo.c", b'(?ms)foo\\.c\\Z'),
-    (b"foo.c", b'(?ms)(.*/)?foo\\.c\\Z'),
-    (b"foo.[ch]", b'(?ms)(.*/)?foo\\.[ch]\\Z'),
-    (b"foo/**", b'(?ms)foo(/.*)?\\Z'),
-    (b"foo/**/blie.c", b'(?ms)foo(/.*)?\\/blie\\.c\\Z'),
-    (b"**/bla.c", b'(?ms)(.*/)?bla\\.c\\Z'),
-    (b"foo/**/bar", b'(?ms)foo(/.*)?\\/bar\\Z'),
+    (b"*.c", b'(?ms)(.*/)?[^/]+\\.c/?\\Z'),
+    (b"foo.c", b'(?ms)(.*/)?foo\\.c/?\\Z'),
+    (b"/*.c", b'(?ms)[^/]+\\.c/?\\Z'),
+    (b"/foo.c", b'(?ms)foo\\.c/?\\Z'),
+    (b"foo.c", b'(?ms)(.*/)?foo\\.c/?\\Z'),
+    (b"foo.[ch]", b'(?ms)(.*/)?foo\\.[ch]/?\\Z'),
+    (b"bar/", b'(?ms)(.*/)?bar\\/\\Z'),
+    (b"foo/**", b'(?ms)foo(/.*)?/?\\Z'),
+    (b"foo/**/blie.c", b'(?ms)foo(/.*)?\\/blie\\.c/?\\Z'),
+    (b"**/bla.c", b'(?ms)(.*/)?bla\\.c/?\\Z'),
+    (b"foo/**/bar", b'(?ms)foo(/.*)?\\/bar/?\\Z'),
 ]