Skip to content

Commit c3fc83f

Browse files
committed
Add missing rules to match hierarchy path
1 parent 16d3ebf commit c3fc83f

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

git/config.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -467,20 +467,24 @@ def _included_paths(self):
467467
keyword = match.group(1)
468468
value = match.group(2).strip()
469469

470-
if keyword == "gitdir":
471-
value = osp.expanduser(value)
472-
if fnmatch.fnmatchcase(self._repo.git_dir, value):
473-
paths += self.items(section)
474-
475-
elif keyword == "gitdir/i":
470+
if keyword in ["gitdir", "gitdir/i"]:
476471
value = osp.expanduser(value)
477472

478-
# Ensure that glob is always case insensitive.
479-
value = re.sub(
480-
r"[a-zA-Z]",
481-
lambda m: f"[{m.group().lower()}{m.group().upper()}]",
482-
value
483-
)
473+
if not any(value.startswith(s) for s in ["./", "/"]):
474+
value = "**/" + value
475+
if value.endswith("/"):
476+
value += "**"
477+
478+
# Ensure that glob is always case insensitive if required.
479+
if keyword.endswith("/i"):
480+
value = re.sub(
481+
r"[a-zA-Z]",
482+
lambda m: "[{}{}]".format(
483+
m.group().lower(),
484+
m.group().upper()
485+
),
486+
value
487+
)
484488

485489
if fnmatch.fnmatchcase(self._repo.git_dir, value):
486490
paths += self.items(section)

test/test_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ def test_conditional_includes_from_git_dir(self, rw_dir):
299299
assert not config._has_includes()
300300
assert config._included_paths() == []
301301

302+
# Ensure that config is included if path in hierarchy.
303+
with open(path1, "w") as stream:
304+
stream.write(template.format("gitdir", "target1/", path2))
305+
306+
with GitConfigParser(path1, repo=repo) as config:
307+
assert config._has_includes()
308+
assert config._included_paths() == [("path", path2)]
309+
302310
@with_rw_directory
303311
def test_conditional_includes_from_branch_name(self, rw_dir):
304312
# Initiate mocked branch

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy