summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Retailleau <jeremy.retailleau@gmail.com>2020-09-02 14:03:17 -0700
committerJeremy Retailleau <jeremy.retailleau@gmail.com>2020-09-02 14:03:17 -0700
commitd5262acbd33b70fb676284991207fb24fa9ac895 (patch)
treef6fdc8665bd573c0907ebc6170642ca056789290
parent9766832e11cdd8afed16dfd2d64529c2ae9c3382 (diff)
downloadgitpython-d5262acbd33b70fb676284991207fb24fa9ac895.tar.gz
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
-rw-r--r--git/config.py8
-rw-r--r--git/repo/base.py4
2 files changed, 8 insertions, 4 deletions
diff --git a/git/config.py b/git/config.py
index e686dcd3..6d4135f5 100644
--- a/git/config.py
+++ b/git/config.py
@@ -250,7 +250,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
# list of RawConfigParser methods able to change the instance
_mutating_methods_ = ("add_section", "remove_section", "remove_option", "set")
- def __init__(self, file_or_files=None, read_only=True, merge_includes=True, config_level=None):
+ def __init__(self, file_or_files=None, read_only=True, merge_includes=True, config_level=None, repo=None):
"""Initialize a configuration reader to read the given file_or_files and to
possibly allow changes to it by setting read_only False
@@ -265,7 +265,10 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
:param merge_includes: if True, we will read files mentioned in [include] sections and merge their
contents into ours. This makes it impossible to write back an individual configuration file.
Thus, if you want to modify a single configuration file, turn this off to leave the original
- dataset unaltered when reading it."""
+ dataset unaltered when reading it.
+ :param repo: Reference to repository to use if [includeIf] sections are found in configuration files.
+
+ """
cp.RawConfigParser.__init__(self, dict_type=_OMD)
# Used in python 3, needs to stay in sync with sections for underlying implementation to work
@@ -287,6 +290,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
self._dirty = False
self._is_initialized = False
self._merge_includes = merge_includes
+ self._repo = repo
self._lock = None
self._acquire_lock()
diff --git a/git/repo/base.py b/git/repo/base.py
index 591ccec5..2579a7d7 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -452,7 +452,7 @@ class Repo(object):
files = [self._get_config_path(f) for f in self.config_level]
else:
files = [self._get_config_path(config_level)]
- return GitConfigParser(files, read_only=True)
+ return GitConfigParser(files, read_only=True, repo=self)
def config_writer(self, config_level="repository"):
"""
@@ -467,7 +467,7 @@ class Repo(object):
system = system wide configuration file
global = user level configuration file
repository = configuration file for this repostory only"""
- return GitConfigParser(self._get_config_path(config_level), read_only=False)
+ return GitConfigParser(self._get_config_path(config_level), read_only=False, repo=self)
def commit(self, rev=None):
"""The Commit object for the specified revision