gitpython-developers / GitPython

GitPython is a python library used to interact with Git repositories.
http://gitpython.readthedocs.org
BSD 3-Clause "New" or "Revised" License
4.62k stars 907 forks source link

Config reader does not support includeIf #1053

Open Svenito opened 4 years ago

Svenito commented 4 years ago

If the .gitconfig file includes an includeIf directive, the config parser doesn't respect it.

~/.gitconfig file contents:

[includeIf "gitdir:~/work/git/"]
        path = ~/.gitconfig.work

[user]
        email = my@email.com
        name = Me
        useconfigonly = true

~/.gitconfig.work contents

[user]
        email: work@email.com
        name = Work

Change to the ~/work/git/project directory and run git config -l and notice that the name is set to Work. Running the following in a Python REPL

import os
from git import Repo
repo = Repo(os.getcwd())
repo.repo.config_reader().get_value("user", "name")
'Me'

And if the user hasn't got a default user setting in the ~/gitconfig file, it will throw ConfigParser.NoSectionError: No section: 'user' which is expected.

Config parser should support the includeIf directive in the config file.

Byron commented 4 years ago

Thanks for the summary!

As the implementation does support include directives already, at least in theory that should provide the necessary infrastructure to add support for conditional includes.

Here is the a link to the git documentation in case anyone wants to give it a try.

buddly27 commented 4 years ago

@Byron I just submitted a PR: #1054

Let me know if I missed anything!