Conditional includes in .gitconfig not supported
See original GitHub issueDescribe the bug
The GitHub Desktop client doesn’t support .gitconfig’s Conditional includes.
I’m using a single machine for both work and private development. Each of those requires a distinct Git user (name and email). I don’t want to configure the Git user for each and every repository individually (as I usually forget to do so and notice it when there’re several commits under a wrong user already). That’s why I’m using the Conditional includes. That allows me to have an individual configuration for a specific directory and all its subdirectories, for example:
~/development/
for personal projects with a personal user name/email~/work/
for projects I’m working on in my job
My base ~/.gitconfig
contains something like the following:
# this is a global configuration valid for the whole machine
[user]
name = My Private Name With Nickname
email = private@email
# the following section tells Git to use (actually merge to this config) the config file `~/.gitconfig-work`
# for all repositories located in the directory `~/work/` and all its subdirectories
[includeIf "gitdir/i:~/work/**"]
# include the content of `~/.gitconfig-work` here, if it contains any directives which have been already defined, it will overwrite them
path = ~/.gitconfig-work
The content of ~/.gitconfig-work
:
[user]
name = My Work Name
email = corporate@email
And that’s it. All repositories under the directory ~/work/
will be using the configuration from the base ~/.gitconfig
merged with ~/.gitconfig-work
(which overwrites anything already defined in the base config). Repositories located anywhere outside of that directory will be using just the configuration from the base config.
And Git reflects that. When I execute git config user.email
under the directory ~/work/
or its subdirectories, it prints the e-mail configured in ~/.gitconfig-work
.
The problem is that GitHub Desktop is always showing the configuration from the base config. When I open the Repository menu > Repository settings… and select Git config, the option Use my global Git config is selected and the name and the email from the base config are shown there. And, of course, it’s also used as a commit author.
Version & OS
GitHub 2.7.2 Windows 10 Pro 64-bit
Steps to reproduce the behavior
- Create two configuration files as described above, one included in the other one
- Create a new repository under the directory you have specified in the
includeIf
directive (gitdir:...
) - Check if the included config is correctly applied by executing
git config user.email
in your repository - Check the Git config section in the Repository settings… dialog in GitHub Desktop
Expected behavior
GitHub Desktop behaves consistently with the official CLI Git client. Also, for example, SourceTree behaves correctly.
Actual behavior
The Conditional includes are ignored by GitHub Desktop.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:10 (7 by maintainers)
Top GitHub Comments
I think it should be easy to do, yeah. Please go ahead and submit a PR if you feel comfortable to do so! I’ll assign the issue to you 😄
Just FYI those values will be read-only, you won’t be able to change them from the app, only see them when you open the Repository settings. We assume that if a user set up such an unusual config structure, they know what they’re doing 😅
Thanks for your replies guys!
@sergiou87 You’re right, I have tested it on my machine with the same results. I was afraid that you may be using some Git library that doesn’t support the conditional includes, so it may be complicated to fix, but this looks pretty easy to fix to me. Should I take a look and possibly create a PR? Or am I just too naive? 🙂
Also, those conditional includes are configured for a specific directory so it makes sense to me to read them with the repository configuration rather than the global configuration, i.e. using
git config user.email
in the repository directory. In such a case, the conditional includes are applied without any special option.