13
13
import logging
14
14
import os
15
15
import re
16
- import glob
17
16
import fnmatch
18
17
from collections import OrderedDict
19
18
@@ -452,10 +451,7 @@ def string_decode(v):
452
451
raise e
453
452
454
453
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 ())
459
455
460
456
def _included_paths (self ):
461
457
"""Return all paths that must be included to configuration.
@@ -471,21 +467,26 @@ def _included_paths(self):
471
467
keyword = match .group (1 )
472
468
value = match .group (2 ).strip ()
473
469
474
- if keyword in [ "gitdir" , "gitdir/i" ] :
470
+ if keyword == "gitdir" :
475
471
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 ):
484
473
paths += self .items (section )
485
474
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 )
486
487
487
488
elif keyword == "onbranch" :
488
- if value == self ._repo .active_branch .name :
489
+ if fnmatch . fnmatchcase ( self ._repo .active_branch .name , value ) :
489
490
paths += self .items (section )
490
491
491
492
return paths
0 commit comments