Skip to content

Read conditional include #1054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
buddly27 committed Sep 2, 2020
commit d5262acbd33b70fb676284991207fb24fa9ac895
8 changes: 6 additions & 2 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -265,7 +265,10 @@ def __init__(self, file_or_files=None, read_only=True, merge_includes=True, conf
: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
Expand All @@ -287,6 +290,7 @@ def __init__(self, file_or_files=None, read_only=True, merge_includes=True, conf
self._dirty = False
self._is_initialized = False
self._merge_includes = merge_includes
self._repo = repo
self._lock = None
self._acquire_lock()

Expand Down
4 changes: 2 additions & 2 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def config_reader(self, config_level=None):
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"):
"""
Expand All @@ -467,7 +467,7 @@ def config_writer(self, config_level="repository"):
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
Expand Down