1313import logging
1414import os
1515import re
16- import glob
1716import fnmatch
1817from 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