Skip to content

Commit d5262ac

Browse files
committed
Add reference to repository to config.
This is necessary when working with conditional include sections as it requires the git directory or active branch name. https://git-scm.com/docs/git-config#_conditional_includes
1 parent 9766832 commit d5262ac

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

git/config.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
250250
# list of RawConfigParser methods able to change the instance
251251
_mutating_methods_ = ("add_section", "remove_section", "remove_option", "set")
252252

253-
def __init__(self, file_or_files=None, read_only=True, merge_includes=True, config_level=None):
253+
def __init__(self, file_or_files=None, read_only=True, merge_includes=True, config_level=None, repo=None):
254254
"""Initialize a configuration reader to read the given file_or_files and to
255255
possibly allow changes to it by setting read_only False
256256
@@ -265,7 +265,10 @@ def __init__(self, file_or_files=None, read_only=True, merge_includes=True, conf
265265
:param merge_includes: if True, we will read files mentioned in [include] sections and merge their
266266
contents into ours. This makes it impossible to write back an individual configuration file.
267267
Thus, if you want to modify a single configuration file, turn this off to leave the original
268-
dataset unaltered when reading it."""
268+
dataset unaltered when reading it.
269+
:param repo: Reference to repository to use if [includeIf] sections are found in configuration files.
270+
271+
"""
269272
cp.RawConfigParser.__init__(self, dict_type=_OMD)
270273

271274
# Used in python 3, needs to stay in sync with sections for underlying implementation to work
@@ -287,6 +290,7 @@ def __init__(self, file_or_files=None, read_only=True, merge_includes=True, conf
287290
self._dirty = False
288291
self._is_initialized = False
289292
self._merge_includes = merge_includes
293+
self._repo = repo
290294
self._lock = None
291295
self._acquire_lock()
292296

git/repo/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def config_reader(self, config_level=None):
452452
files = [self._get_config_path(f) for f in self.config_level]
453453
else:
454454
files = [self._get_config_path(config_level)]
455-
return GitConfigParser(files, read_only=True)
455+
return GitConfigParser(files, read_only=True, repo=self)
456456

457457
def config_writer(self, config_level="repository"):
458458
"""
@@ -467,7 +467,7 @@ def config_writer(self, config_level="repository"):
467467
system = system wide configuration file
468468
global = user level configuration file
469469
repository = configuration file for this repostory only"""
470-
return GitConfigParser(self._get_config_path(config_level), read_only=False)
470+
return GitConfigParser(self._get_config_path(config_level), read_only=False, repo=self)
471471

472472
def commit(self, rev=None):
473473
"""The Commit object for the specified revision

0 commit comments

Comments
 (0)