{"thread":{"id":"59576","subject":"Bug with git-config includeIf","startedAt":"2023-04-11T16:32:11Z","lastAt":"2023-04-12T06:26:43Z","messageCount":4,"participants":["Matthias Beyer","Junio C Hamano","Emily Shaffer"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"475152","messageId":"3352350.44csPzL39Z@takeshi","threadId":"59576","inReplyTo":null,"subject":"Bug with git-config includeIf","fromName":"Matthias Beyer","fromEmail":"mail@beyermatthias.de","sentAt":"2023-04-11T16:05:18Z","receivedAt":"2023-04-11T16:32:11Z","isPatch":false,"sender":{"key":"mail@beyermatthias.de","avatar":null},"body":"Hi,\n\nplease keep me in CC when replying, I am not subscribed.\n\nI experience the following (seemingly) bug in my git setup:\n\nI have three files for my git configuration:\n\n* ~/.gitconfig -> ~/config/git/gitconfig\n* ~/config/git/gitconfig_private\n* ~/config/git/gitconfig_work\n\nThe gitconfig_private sets my email address to this very email address, the \ngitconfig_work sets it to me work email address.\n\nThe gitconfig file has a `includeIf` directive:\n\n```\n[include]\n    path = ~/config/git/gitconfig_private                                                                                                                                                                                                                                                                                    \n\n[includeIf \"gitdir:~/dev/work/\"]\n    path = ~/config/git/gitconfig_work   \n```\n\nThat means, from my understanding, that all git repositories in ~/dev/work \nshould now have the work-related email address set.\n\nIf I go to ~/dev/work/somerepo and `git config --get user.email` it indeed \nshows the expected email address.\n\nBut if I go to a subdirectory in that repository, the very same command shows \nthe private email address, and commits get written with that private email \naddress.\n\nDid I miss something obvious or did I discover a bug?\n\ngit: 2.38.4\n\nBest,\nMatthias"},{"id":"475154","messageId":"xmqqr0sq9x0f.fsf@gitster.g","threadId":"59576","inReplyTo":"3352350.44csPzL39Z@takeshi","subject":"Re: Bug with git-config includeIf","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-04-11T16:58:08Z","receivedAt":"2023-04-11T16:58:17Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthias Beyer <mail@beyermatthias.de> writes:\n\n> [includeIf \"gitdir:~/dev/work/\"]\n>     path = ~/config/git/gitconfig_work   \n> ```\n>\n> That means, from my understanding, that all git repositories in ~/dev/work \n> should now have the work-related email address set.\n>\n> If I go to ~/dev/work/somerepo and `git config --get user.email` it indeed \n> shows the expected email address.\n\nThe pattern given to \"gitdir:\" ends with \"/\" and implicitly \"**\" is\nadded after it.  If \"~/dev/work/somerepo\" is a repository, going\nthere and \"git rev-parse --git-dir\" would say \".git\" or\n\"~/dev/work/somerepo/.git\", then the includeIf should trigger.\n\n> But if I go to a subdirectory in that repository, the very same command shows \n> the private email address, and commits get written with that private email \n> address.\n\nI use exactly the same configuration (not for working on this\nproject, though), and your symptom does not reproduce for me, which\npuzzles me.  I go to an equivelent of your ~/dev/work/somerepo/subdir\nand \"git rev-parse --git-dir\" would still report an equivalent of\nyour \"~/dev/work/somerepo/.git\", and my \"git config --show-origin user.name\"\ndoes point at the value of \"includeIf.gitdir:~/dev/work/.path\".\n\nI wonder what the difference of the set-up is.  \n\nMy ~/dev/work/somerepo/.git equivalent is a directory.  Perhas yours\nis not?  That should not cause any difference and it is merely a\nguess in the dark.\n\n"},{"id":"475155","messageId":"CAJoAoZ=VdHy0gTCGiWnRw==Wbmfst2Gpg2Tf498_P+batU1ixw@mail.gmail.com","threadId":"59576","inReplyTo":"3352350.44csPzL39Z@takeshi","subject":"Re: Bug with git-config includeIf","fromName":"Emily Shaffer","fromEmail":"nasamuffin@google.com","sentAt":"2023-04-11T17:00:40Z","receivedAt":"2023-04-11T17:01:35Z","isPatch":false,"sender":{"key":"nasamuffin@google.com","avatar":"https://avatars.githubusercontent.com/u/1606826?v=4"},"body":"On Tue, Apr 11, 2023 at 9:32 AM Matthias Beyer <mail@beyermatthias.de> wrote:\n>\n> Hi,\n>\n> please keep me in CC when replying, I am not subscribed.\n>\n> I experience the following (seemingly) bug in my git setup:\n>\n> I have three files for my git configuration:\n>\n> * ~/.gitconfig -> ~/config/git/gitconfig\n> * ~/config/git/gitconfig_private\n> * ~/config/git/gitconfig_work\n>\n> The gitconfig_private sets my email address to this very email address, the\n> gitconfig_work sets it to me work email address.\n>\n> The gitconfig file has a `includeIf` directive:\n>\n> ```\n> [include]\n>     path = ~/config/git/gitconfig_private\n>\n> [includeIf \"gitdir:~/dev/work/\"]\n>     path = ~/config/git/gitconfig_work\n> ```\n>\n> That means, from my understanding, that all git repositories in ~/dev/work\n> should now have the work-related email address set.\n>\n> If I go to ~/dev/work/somerepo and `git config --get user.email` it indeed\n> shows the expected email address.\n>\n> But if I go to a subdirectory in that repository, the very same command shows\n> the private email address, and commits get written with that private email\n> address.\n\nOne thing that can help a lot to debug is to run `git config --list\n--show-scope` from this subdirectory where your config is misbehaving\n- that will help you understand which of _private or _work is being\nincluded in the parse, in which order. It could be there is another\nstray config overwriting here.\n\n>\n> Did I miss something obvious or did I discover a bug?\n>\n> git: 2.38.4\n>\n> Best,\n> Matthias\n"},{"id":"475187","messageId":"3613557.iIbC2pHGDl@takeshi","threadId":"59576","inReplyTo":"xmqqr0sq9x0f.fsf@gitster.g","subject":"Re: Bug with git-config includeIf","fromName":"Matthias Beyer","fromEmail":"mail@beyermatthias.de","sentAt":"2023-04-12T06:26:29Z","receivedAt":"2023-04-12T06:26:43Z","isPatch":false,"sender":{"key":"mail@beyermatthias.de","avatar":null},"body":"Hi,\n\nthanks for your reply.\n\nI found the issue. As always, one nastly little detail: ~/dev is actually a \nsymlink on my system(s) to ~/archive/development/\n\ngit rev-parse --git-dir of course resolves that symlink and thus ~/dev/work/ \ndoes not actually match ~/archive/development/\n\nUsing that path in the includeIf produces the expected results. \n\nThanks for your patience.\nMatthias\n\nAm Dienstag, 11. April 2023, 18:58:08 CEST schrieb Junio C Hamano:\n> Matthias Beyer <mail@beyermatthias.de> writes:\n> > [includeIf \"gitdir:~/dev/work/\"]\n> > \n> >     path = ~/config/git/gitconfig_work\n> > \n> > ```\n> > \n> > That means, from my understanding, that all git repositories in ~/dev/work\n> > should now have the work-related email address set.\n> > \n> > If I go to ~/dev/work/somerepo and `git config --get user.email` it indeed\n> > shows the expected email address.\n> \n> The pattern given to \"gitdir:\" ends with \"/\" and implicitly \"**\" is\n> added after it.  If \"~/dev/work/somerepo\" is a repository, going\n> there and \"git rev-parse --git-dir\" would say \".git\" or\n> \"~/dev/work/somerepo/.git\", then the includeIf should trigger.\n> \n> > But if I go to a subdirectory in that repository, the very same command\n> > shows the private email address, and commits get written with that\n> > private email address.\n> \n> I use exactly the same configuration (not for working on this\n> project, though), and your symptom does not reproduce for me, which\n> puzzles me.  I go to an equivelent of your ~/dev/work/somerepo/subdir\n> and \"git rev-parse --git-dir\" would still report an equivalent of\n> your \"~/dev/work/somerepo/.git\", and my \"git config --show-origin user.name\"\n> does point at the value of \"includeIf.gitdir:~/dev/work/.path\".\n> \n> I wonder what the difference of the set-up is.\n> \n> My ~/dev/work/somerepo/.git equivalent is a directory.  Perhas yours\n> is not?  That should not cause any difference and it is merely a\n> guess in the dark.\n"}]}