diff options
-rw-r--r-- | git/config.py | 28 | ||||
-rw-r--r-- | test/test_config.py | 8 |
2 files changed, 24 insertions, 12 deletions
diff --git a/git/config.py b/git/config.py index e36af9fe..eb46c41b 100644 --- a/git/config.py +++ b/git/config.py @@ -467,20 +467,24 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje keyword = match.group(1) value = match.group(2).strip() - if keyword == "gitdir": - value = osp.expanduser(value) - if fnmatch.fnmatchcase(self._repo.git_dir, value): - paths += self.items(section) - - elif keyword == "gitdir/i": + if keyword in ["gitdir", "gitdir/i"]: value = osp.expanduser(value) - # Ensure that glob is always case insensitive. - value = re.sub( - r"[a-zA-Z]", - lambda m: f"[{m.group().lower()}{m.group().upper()}]", - value - ) + if not any(value.startswith(s) for s in ["./", "/"]): + value = "**/" + value + if value.endswith("/"): + value += "**" + + # Ensure that glob is always case insensitive if required. + if keyword.endswith("/i"): + value = re.sub( + r"[a-zA-Z]", + lambda m: "[{}{}]".format( + m.group().lower(), + m.group().upper() + ), + value + ) if fnmatch.fnmatchcase(self._repo.git_dir, value): paths += self.items(section) diff --git a/test/test_config.py b/test/test_config.py index 12fad15c..406d794e 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -299,6 +299,14 @@ class TestBase(TestCase): assert not config._has_includes() assert config._included_paths() == [] + # Ensure that config is included if path in hierarchy. + with open(path1, "w") as stream: + stream.write(template.format("gitdir", "target1/", path2)) + + with GitConfigParser(path1, repo=repo) as config: + assert config._has_includes() + assert config._included_paths() == [("path", path2)] + @with_rw_directory def test_conditional_includes_from_branch_name(self, rw_dir): # Initiate mocked branch |