Skip to content

Commit 8e263b8

Browse files
committed
Add method to retrieve all possible paths to include
1 parent d5262ac commit 8e263b8

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

git/config.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import logging
1414
import os
1515
import re
16+
import glob
17+
import fnmatch
1618
from collections import OrderedDict
1719

1820
from git.compat import (
@@ -455,6 +457,39 @@ def _has_includes(self):
455457
for section in self.sections()
456458
)
457459

460+
def _included_paths(self):
461+
"""Return all paths that must be included to configuration.
462+
"""
463+
paths = []
464+
465+
for section in self.sections():
466+
if section == "include":
467+
paths += self.items(section)
468+
469+
match = CONDITIONAL_INCLUDE_REGEXP.search(section)
470+
if match is not None and self._repo is not None:
471+
keyword = match.group(1)
472+
value = match.group(2).strip()
473+
474+
if keyword in ["gitdir", "gitdir/i"]:
475+
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+
):
484+
paths += self.items(section)
485+
486+
487+
elif keyword == "onbranch":
488+
if value == self._repo.active_branch.name:
489+
paths += self.items(section)
490+
491+
return paths
492+
458493
def read(self):
459494
"""Reads the data stored in the files we have been initialized with. It will
460495
ignore files that cannot be read, possibly leaving an empty configuration
@@ -492,7 +527,7 @@ def read(self):
492527
# Read includes and append those that we didn't handle yet
493528
# We expect all paths to be normalized and absolute (and will assure that is the case)
494529
if self._has_includes():
495-
for _, include_path in self.items('include'):
530+
for _, include_path in self._included_paths():
496531
if include_path.startswith('~'):
497532
include_path = osp.expanduser(include_path)
498533
if not osp.isabs(include_path):

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