Skip to content

Commit f37011d

Browse files
committed
Fix logic to properly compare glob pattern to value
1 parent 8e263b8 commit f37011d

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

git/config.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import logging
1414
import os
1515
import re
16-
import glob
1716
import fnmatch
1817
from collections import OrderedDict
1918

@@ -452,10 +451,7 @@ def string_decode(v):
452451
raise e
453452

454453
def _has_includes(self):
455-
return self._merge_includes and any(
456-
section == 'include' or section.startswith('includeIf ')
457-
for section in self.sections()
458-
)
454+
return self._merge_includes and len(self._included_paths())
459455

460456
def _included_paths(self):
461457
"""Return all paths that must be included to configuration.
@@ -471,21 +467,26 @@ def _included_paths(self):
471467
keyword = match.group(1)
472468
value = match.group(2).strip()
473469

474-
if keyword in ["gitdir", "gitdir/i"]:
470+
if keyword == "gitdir":
475471
value = osp.expanduser(value)
476-
flags = [re.IGNORECASE] if keyword == "gitdir/i" else []
477-
regexp = re.compile(fnmatch.translate(value), *flags)
478-
479-
if any(
480-
regexp.match(path) is not None
481-
and self._repo.git_dir.startswith(path)
482-
for path in glob.glob(value)
483-
):
472+
if fnmatch.fnmatchcase(self._repo.git_dir, value):
484473
paths += self.items(section)
485474

475+
elif keyword == "gitdir/i":
476+
value = osp.expanduser(value)
477+
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+
)
484+
485+
if fnmatch.fnmatchcase(self._repo.git_dir, value):
486+
paths += self.items(section)
486487

487488
elif keyword == "onbranch":
488-
if value == self._repo.active_branch.name:
489+
if fnmatch.fnmatchcase(self._repo.active_branch.name, value):
489490
paths += self.items(section)
490491

491492
return paths

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