desktop icon indicating copy to clipboard operation
desktop copied to clipboard

Conditional includes in .gitconfig not supported

Open ferenczy opened this issue 5 years ago β€’ 14 comments

Describe 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

  1. Create two configuration files as described above, one included in the other one
  2. Create a new repository under the directory you have specified in the includeIf directive (gitdir:...)
  3. Check if the included config is correctly applied by executing git config user.email in your repository
  4. 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.

ferenczy avatar Apr 22 '21 17:04 ferenczy

Thanks for the report @ferenczy. I did test out conditional includes last year (and it worked), but that was prior to us shipping various config improvements (https://github.com/desktop/desktop/pull/11595 and https://github.com/desktop/desktop/pull/11591). @sergiou87 should have some thoughts about this since he worked on that feature.

steveward avatar Apr 22 '21 20:04 steveward

Thank you for bringing this up @ferenczy! ❀️

I just checked and the problem seems to be we're running git config --global user.email, and when a specific scope (like --global) is given, git config won't look for for included files like the one you have unless we also specify --includes.

We'll look into this and let you know πŸ˜„

sergiou87 avatar Apr 23 '21 08:04 sergiou87

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.

ferenczy avatar Apr 27 '21 01:04 ferenczy

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 πŸ˜…

sergiou87 avatar Apr 27 '21 08:04 sergiou87

Who's key it?

HadesStyx avatar Apr 28 '21 06:04 HadesStyx

Let him personally write,all that's

  • [ ] I'll give you what I normall****

HadesStyx avatar Apr 28 '21 06:04 HadesStyx

@sergiou87 OK, I'll take a look at it. Is it just about changing command-line options of the Git command the GitHub desktop is executing or should I expect more changes, please. I mean, is it possible it will have any consequences/side-effects?

@HadesStyx Were those questions addressed to me? If so, I don't understand what you're asking, I'm afraid. πŸ™‚

ferenczy avatar May 05 '21 14:05 ferenczy

@ferenczy yeah, it should be just that… but as everything, it might have unexpected consequences or side-effects πŸ˜‚ Β I think the idea would be trying to keep the changes to only affect the Repository Settings screen, if possible.

Also, don't worry about HadesStyx, those were just random comments. We get a bunch of those every day πŸ˜…

sergiou87 avatar May 05 '21 15:05 sergiou87

@sergiou87 @ferenczy , Hi guys any progress on this? I ran into this issue today as well. The display on GitHub Desktop doesn't truly represent the git configurations.

Bro3Simon avatar Feb 17 '22 01:02 Bro3Simon

From #15734:

The feature request

Here is an example of what I have set up. It may be atypical, but hopefully this is still a valid feature request:

When managing my dotfiles, I have a global .gitconfig that is common to all machines/environments. That .gitconfig includes the following:

[include]
  path = .gitconfig.local

In this way, the global settings for certain values can be set on a per-machine/per-environment basis. Github Desktop always updates ~/.gitconfig with [user] values without following the [include] to see where else it might be "included" (or already exist).

I found issue 12041, but it seems this is still broken.

See --[no-]includes for context.

Proposed solution

Support [include] such that the [user] value can be sourced from any/all included files.

In my example above, some useful config values to have in .gitconfig.local might be:

[user] 
  name = <value here>
  email = <value here>

[credential]
  helper = <platform-specific value>

[diff]
  guitool = <platform-specific tool>

Hopefully this further demonstrates the usefulness of this feature.

steveward avatar Dec 07 '22 17:12 steveward

From #15734:

Thanks for copying here. :)

driverkt avatar Feb 09 '23 21:02 driverkt

RE: https://github.com/desktop/desktop/issues/12041#issuecomment-827421458

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 πŸ˜…

RE: https://github.com/desktop/desktop/issues/12041#issuecomment-832758100

OK, I'll take a look at it. Is it just about changing command-line options of the Git command the GitHub desktop is executing or should I expect more changes, please. I mean, is it possible it will have any consequences/side-effects?

RE: https://github.com/desktop/desktop/issues/12041#issuecomment-832760665

yeah, it should be just that… but as everything, it might have unexpected consequences or side-effects πŸ˜‚ I think the idea would be trying to keep the changes to only affect the Repository Settings screen, if possible.

From a quick search of the codebase for user.email, it looks like the way this config is read/updated inconsistently (maybe by design) across GitHub Desktop; with some places seeming to use getGlobalConfigValue('user.email') / setGlobalConfigValue('user.email', email); and other places using getConfigValue(repository, 'user.email', true) / etc

  • https://github.com/search?q=repo%3Adesktop%2Fdesktop+user.email&type=code

All of getConfigValue / getGlobalConfigValue / setConfigValue / setGlobalConfigValue seem to be defined in desktop/app/src/lib/git/config.ts:

https://github.com/desktop/desktop/blob/development/app/src/lib/git/config.ts#L5-L29

https://github.com/desktop/desktop/blob/development/app/src/lib/git/config.ts#L154-L175

There also seems to be a addGlobalConfigValue:

https://github.com/desktop/desktop/blob/6aa1e092c738da2851624fdf376daa658ccdaa69/app/src/lib/git/config.ts#L177-L187

And addGlobalConfigValueIfMissing:

https://github.com/desktop/desktop/blob/6aa1e092c738da2851624fdf376daa658ccdaa69/app/src/lib/git/config.ts#L204-L219

0xdevalias avatar Dec 17 '23 12:12 0xdevalias

Any updates on this? It's a particularly irritating issue for us who have multiple git profiles.

johnmckee02 avatar Aug 20 '24 17:08 johnmckee02

Related: https://github.com/desktop/desktop/issues/9255

steveward avatar Oct 15 '24 14:10 steveward