Bug 1447872 [wpt PR 10131] - Fix python gitignore for directories., a=testonly
authorjgraham <james@hoppipolla.co.uk>
Mon, 09 Apr 2018 17:43:07 +0000
changeset 413633 73e34216cc87216c0a6adcf8c915d6eedae4a224
parent 413632 c0c9886ad6a79c474fc1bc06a3ca4e8daa57383e
child 413634 34bfd03e5075136aa3fc7778e49cb1f368cf881d
push id33850
push userapavel@mozilla.com
push dateMon, 16 Apr 2018 09:53:48 +0000
treeherdermozilla-central@6276ec7ebbf3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1447872, 10131
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1447872 [wpt PR 10131] - Fix python gitignore for directories., a=testonly Automatic update from web-platform-testsFix python gitignore for directories. (#10131) For top level directories like _venv/ we were creating the regexp ^\_venv/$, which we were then feeding paths like _venv/bin/foo which it fails to match. Since we are matching against full paths, we certainly want to allow matching _venv/* and probably also bare _venv, so add a special case for paths with a trailing slash to allow these options. wpt-commits: 174f76430b32801d32cb3974c46894e866bad7a3 wpt-pr: 10131 wpt-commits: 174f76430b32801d32cb3974c46894e866bad7a3 wpt-pr: 10131
testing/web-platform/tests/tools/gitignore/gitignore.py
testing/web-platform/tests/tools/gitignore/tests/test_gitignore.py
--- a/testing/web-platform/tests/tools/gitignore/gitignore.py
+++ b/testing/web-platform/tests/tools/gitignore/gitignore.py
@@ -12,16 +12,22 @@ def fnmatch_translate(pat, path_name=Fal
     if pat[0] == "/" or path_name:
         parts.append("^")
         any_char = "[^/]"
         if pat[0] == "/":
             pat = pat[1:]
     else:
         any_char = "."
         parts.append("^(?:.*/)?")
+    if pat[-1] == "/":
+        # If the last character is / match this directory or any subdirectory
+        pat = pat[:-1]
+        suffix = "(?:/|$)"
+    else:
+        suffix = "$"
     while i < len(pat):
         c = pat[i]
         if c == "\\":
             if i < len(pat) - 1:
                 i += 1
                 c = pat[i]
                 parts.append(re.escape(c))
             else:
@@ -58,17 +64,17 @@ def fnmatch_translate(pat, path_name=Fal
         elif c == "?":
             parts.append(any_char)
         else:
             parts.append(re.escape(c))
         i += 1
 
     if seq:
         raise ValueError
-    parts.append("$")
+    parts.append(suffix)
     try:
         return re.compile("".join(parts))
     except Exception:
         raise
 
 
 def parse_line(line):
     line = line.rstrip()
--- a/testing/web-platform/tests/tools/gitignore/tests/test_gitignore.py
+++ b/testing/web-platform/tests/tools/gitignore/tests/test_gitignore.py
@@ -6,28 +6,30 @@ match_data = [
     ("foo", False, ["a/foo", "foo"]),
     ("*.a", False, ["foo.a", "a/foo.a", "a/b/foo.a", "a.a/foo.a"]),
     ("*.py[co]", False, ["a.pyc", "a.pyo", "a/b/c.pyc"]),
     ("\\#*", False, ["#a", "a/#b"]),
     ("*#", False, ["a#", "a/b#", "#a#"]),
     ("/*.c", False, ["a.c", ".c"]),
     ("**/b", False, ["a/b", "a/c/b"]),
     ("*b", True, ["ab"]),
-    ("**/b", True, ["a/b"])
+    ("**/b", True, ["a/b"]),
+    ("a/", True, ["a", "a/b", "a/b/c"])
 ]
 
 mismatch_data = [
     ("foo", False, ["foob", "afoo"]),
     ("*.a", False, ["a", "foo:a", "a.a/foo"]),
     ("*.py[co]", False, ["a.pyd", "pyo"]),
     ("/*.c", False, ["a/b.c"]),
     ("*b", True, ["a/b"]),
     ("**b", True, ["a/b"]),
     ("a[/]b", True, ["a/b"]),
     ("**/b", True, ["a/c/b"]),
+    ("a", True, ["ab"])
 ]
 
 invalid_data = [
     "[a",
     "***/foo",
     "a\\",
 ]
 
@@ -35,38 +37,43 @@ filter_data = [
     ("foo", True),
     ("a", False),
     ("a/b", False),
     ("a/c", True),
     ("a/c/", False),
     ("c/b", True)
 ]
 
+
 def expand_data(compact_data):
     for pattern, path_name, inputs in compact_data:
         for input in inputs:
             yield pattern, input, path_name
 
+
 @pytest.mark.parametrize("pattern, input, path_name", expand_data(match_data))
 def tests_match(pattern, input, path_name):
     regexp = fnmatch_translate(pattern, path_name)
     assert regexp.match(input) is not None
 
+
 @pytest.mark.parametrize("pattern, input, path_name", expand_data(mismatch_data))
 def tests_no_match(pattern, input, path_name):
     regexp = fnmatch_translate(pattern, path_name)
     assert regexp.match(input) is None
 
+
 @pytest.mark.parametrize("pattern", invalid_data)
 def tests_invalid(pattern):
     with pytest.raises(ValueError):
         fnmatch_translate(pattern, False)
     with pytest.raises(ValueError):
         fnmatch_translate(pattern, True)
 
+
 @pytest.mark.parametrize("path, expected", filter_data)
 def test_path_filter(path, expected):
     extras = [
         "#foo",
         "a  ",
         "**/b",
         "a/c/",
         "!c/b",