{"thread":{"id":"51827","subject":"git-send-email does not use conditional configuration","startedAt":"2019-09-11T06:15:00Z","lastAt":"2019-09-11T18:05:04Z","messageCount":4,"participants":["Konstantinos Dalamagkidis","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"382152","messageId":"CANTPZbbLNJPEEeG8BgdDEVYS=gudz4SvqGe==28EQHXDXUxuwQ@mail.gmail.com","threadId":"51827","inReplyTo":null,"subject":"git-send-email does not use conditional configuration","fromName":"Konstantinos Dalamagkidis","fromEmail":"konstantinos@dalamagkidis.info","sentAt":"2019-09-11T06:14:45Z","receivedAt":"2019-09-11T06:15:00Z","isPatch":false,"sender":{"key":"konstantinos@dalamagkidis.info","avatar":null},"body":"Hello,\n\nIn my git configuration, I have an includeif section for work\nrelated repositories that configures the user and sendemail\nsections.\n\nI can verify that the configuration is read correctly by git:\n\n% git config --get-regex \"sendemail.*\"\nsendemail.smtpencryption tls\nsendemail.smtpserver smtp.office365.com\nsendemail.smtpserverport 587\nsendemail.smtpuser dalamagkidis@work.com\n\nBut when running git send-email the default sendmail is used:\n\n% git send-email --dry-run 0001*\n[...]\nDry-OK. Log says:\nSendmail: /usr/sbin/sendmail -i test@example.com dalamagkidis@work.com\nFrom: Konstantinos Dalamagkidis <konstantinos@dalamagkidis.info>\nTo: test@example.com\nCc: Konstantinos Dalamagkidis <dalamagkidis@work.com>\n[...]\n\nIf I move the sendemail section to the main gitconfig file, it\nworks as expected. I normally use v2.20.1, but I could also\nreproduce this with v2.23.\n\nRgds\nKonstantinos\n"},{"id":"382161","messageId":"20190911140833.GA13916@sigill.intra.peff.net","threadId":"51827","inReplyTo":"CANTPZbbLNJPEEeG8BgdDEVYS=gudz4SvqGe==28EQHXDXUxuwQ@mail.gmail.com","subject":"Re: git-send-email does not use conditional configuration","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-09-11T14:08:33Z","receivedAt":"2019-09-11T14:08:35Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 11, 2019 at 08:14:45AM +0200, Konstantinos Dalamagkidis wrote:\n\n> In my git configuration, I have an includeif section for work\n> related repositories that configures the user and sendemail\n> sections.\n\nWhat kind of includeIf are you using? Does it work with an\nunconditional include? This seems to work for me:\n\n  $ git config --global include.path one\n  $ git config --file ~/one sendemail.smtpserver one.example.com\n  $ git send-email --dry-run -1 --to nobody | grep ^Server\n  Server: one.example.com\n\n  $ git config --global includeIf.gitdir:$PWD/.path two\n  $ git config --file ~/two sendemail.smtpserver two.example.com\n  $ git send-email --dry-run -1 --to nobody | grep ^Server\n  Server: two.example.com\n\nI.e. both unconditional and gitdir includes work for me. If you do\nsomething similar, what output do you get?\n\n> I can verify that the configuration is read correctly by git:\n> \n> % git config --get-regex \"sendemail.*\"\n> sendemail.smtpencryption tls\n> sendemail.smtpserver smtp.office365.com\n> sendemail.smtpserverport 587\n> sendemail.smtpuser dalamagkidis@work.com\n\nThanks for this output. That rules out that \"git config\" is somehow\nmisbehaving in a way that normal internal config lookups wouldn't.\n\nThe rest of git-config should behave the same, but you could also try:\n\n  git config --get sendemail.smtpserver\n\nwhich is what send-email will actually run (you can run send-email with\nGIT_TRACE=1 to see the full set of commands if you want to try them\nmanually).\n\n-Peff\n"},{"id":"382168","messageId":"d4717b7f-b7a4-208b-6b83-7993b6bd7886@dalamagkidis.info","threadId":"51827","inReplyTo":"20190911140833.GA13916@sigill.intra.peff.net","subject":"Re: git-send-email does not use conditional configuration","fromName":"Konstantinos Dalamagkidis","fromEmail":"konstantinos@dalamagkidis.info","sentAt":"2019-09-11T16:58:26Z","receivedAt":"2019-09-11T17:05:21Z","isPatch":false,"sender":{"key":"konstantinos@dalamagkidis.info","avatar":null},"body":"On 9/11/19 4:08 PM, Jeff King wrote:\n> On Wed, Sep 11, 2019 at 08:14:45AM +0200, Konstantinos Dalamagkidis wrote:\n> \n>> In my git configuration, I have an includeif section for work\n>> related repositories that configures the user and sendemail\n>> sections.\n> \n> What kind of includeIf are you using? Does it work with an\n> unconditional include? This seems to work for me:\n> \n>    $ git config --global include.path one\n>    $ git config --file ~/one sendemail.smtpserver one.example.com\n>    $ git send-email --dry-run -1 --to nobody | grep ^Server\n>    Server: one.example.com\n> \n>    $ git config --global includeIf.gitdir:$PWD/.path two\n>    $ git config --file ~/two sendemail.smtpserver two.example.com\n>    $ git send-email --dry-run -1 --to nobody | grep ^Server\n>    Server: two.example.com\n> \n> I.e. both unconditional and gitdir includes work for me. If you do\n> something similar, what output do you get?\n\nI am using \"includeIf.gitdir:/work\". I tried to reproduce it at my home \nworkstation where I have the exact same configuration, but in the \nbeginning I couldn't. Then I realized, that at work the /work folder is \nactually a symlink to a different directory. When I did the same at \nhome, I could reproduce the issue:\n\n% pwd\n/work/repo\n% git send-email --dry-run -1 --to nobody | grep ^From\nFrom: Konstantinos Dalamagkidis <work-email@example.com>\n% cd ../repo-symlink\n% git send-email --dry-run -1 --to nobody | grep ^From\nFrom: Konstantinos Dalamagkidis <personal-email@example.com>\n% realpath .\n/home/dalamagkidis/tmp/repo\n\nIt appears that git-config and git-send-email parse the gitdir slightly \ndifferently when it comes to symlinks. More specifically git-send-email \nuses the realpath of the repository to determine which configuration to \nuse. It also explains why nobody came across this problem before.\n\n\nRgds\nKonstantinos\n"},{"id":"382171","messageId":"20190911180501.GA26087@sigill.intra.peff.net","threadId":"51827","inReplyTo":"d4717b7f-b7a4-208b-6b83-7993b6bd7886@dalamagkidis.info","subject":"Git.pm normalizes $GIT_DIR, was Re: git-send-email does not use conditional configuration","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-09-11T18:05:01Z","receivedAt":"2019-09-11T18:05:04Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 11, 2019 at 06:58:26PM +0200, Konstantinos Dalamagkidis wrote:\n\n> I am using \"includeIf.gitdir:/work\". I tried to reproduce it at my home\n> workstation where I have the exact same configuration, but in the beginning\n> I couldn't. Then I realized, that at work the /work folder is actually a\n> symlink to a different directory. When I did the same at home, I could\n> reproduce the issue:\n> \n> % pwd\n> /work/repo\n> % git send-email --dry-run -1 --to nobody | grep ^From\n> From: Konstantinos Dalamagkidis <work-email@example.com>\n> % cd ../repo-symlink\n> % git send-email --dry-run -1 --to nobody | grep ^From\n> From: Konstantinos Dalamagkidis <personal-email@example.com>\n> % realpath .\n> /home/dalamagkidis/tmp/repo\n> \n> It appears that git-config and git-send-email parse the gitdir slightly\n> differently when it comes to symlinks. More specifically git-send-email uses\n> the realpath of the repository to determine which configuration to use. It\n> also explains why nobody came across this problem before.\n\nAh, that's interesting. In both cases it's git-config who is doing the\npath comparison. And it should be happy with either form due to\n0624c63ce6 (config: match both symlink & realpath versions in\nIncludeIf.gitdir:*, 2017-05-16).\n\nBut if send-email is normalizing the path and setting $GIT_DIR before we\neven hit git-config, then that would fool it (git-config never even sees\nthe symlinked path). And that seems to be the case, which is due to the\nGit.pm perl module. Running:\n\n  git init repo\n  ln -s repo link\n  cd link\n  git config alias.env '!echo $GIT_DIR'\n  perl -MGit -le '\n    my $repo = Git->repository();\n    print \"env=\", $repo->command(qw(env));\n    print \"resolved=\", $repo->command(qw(rev-parse --git-dir));\n  '\n\ngives me:\n\n  env=/home/peff/tmp/repo/.git\n  resolved=/home/peff/tmp/repo/.git\n\nI'd argue that Git.pm probably shouldn't be setting $GIT_DIR at all when\nwe've auto-discovered the repo from the current directory (instead all\nof the sub-programs should just do their own auto-discovery). But even\nif we feed the constructor another repository path, it probably should\nbe keeping what it puts in $GIT_DIR as close to what it was original\ngiven.\n\nI'll admit I'm slightly afraid to touch Git.pm at all, though. It's old,\nrarely touched code that I suspect has poor test coverage. But I'll cc\nÆvar, who was the most recent brave person. ;)\n\n-Peff\n"}]}