summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Retailleau <jeremy.retailleau@gmail.com>2020-09-02 17:38:43 -0700
committerJeremy Retailleau <jeremy.retailleau@gmail.com>2020-09-02 17:38:43 -0700
commitc3fc83f2333eaee5fbcbef6df9f4ed9eb320fd11 (patch)
tree623b4a3b380ad9c83fbc58a19c1ce23b36747c97
parent16d3ebfa3ad32d281ebdd77de587251015d04b3b (diff)
downloadgitpython-c3fc83f2333eaee5fbcbef6df9f4ed9eb320fd11.tar.gz
Add missing rules to match hierarchy path
-rw-r--r--git/config.py28
-rw-r--r--test/test_config.py8
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