]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-email: fix a "first config key wins" regression in v2.33.0
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 6 Sep 2021 07:33:29 +0000 (09:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Sep 2021 20:18:55 +0000 (13:18 -0700)
Fix a regression in my c95e3a3f0b8 (send-email: move trivial config
handling to Perl, 2021-05-28) where we'd pick the first config key out
of multiple defined ones, instead of using the normal "last key wins"
semantics of "git config --get".

This broke e.g. cases where a .git/config would have a different
sendemail.smtpServer than ~/.gitconfig. We'd pick the ~/.gitconfig
over .git/config, instead of preferring the repository-local
version. The same would go for /etc/gitconfig etc.

The full list of impacted config keys (the %config_settings values
which are references to scalars, not arrays) is:

    sendemail.smtpencryption
    sendemail.smtpserver
    sendemail.smtpserverport
    sendemail.smtpuser
    sendemail.smtppass
    sendemail.smtpdomain
    sendemail.smtpauth
    sendemail.smtpbatchsize
    sendemail.smtprelogindelay
    sendemail.tocmd
    sendemail.cccmd
    sendemail.aliasfiletype
    sendemail.envelopesender
    sendemail.confirm
    sendemail.from
    sendemail.assume8bitencoding
    sendemail.composeencoding
    sendemail.transferencoding
    sendemail.sendmailcmd

I.e. having any of these set in say ~/.gitconfig and in-repo
.git/config regressed in v2.33.0 to prefer the --global one over the
--local.

To test this add a test of config priority to one of these config
variables, most don't have tests at all, but there was an existing one
for sendemail.8bitEncoding.

The "git config" (instead of "test_config") is somewhat of an
anti-pattern, but follows established conventions in
t9001-send-email.sh, likewise with any other pattern or idiom in this
test.

The populating of home/.gitconfig and setting of HOME= is copied from
a test in t0017-env-helper.sh added in 1ff750b128e (tests: make
GIT_TEST_GETTEXT_POISON a boolean, 2019-06-21). This test fails
without this bugfix, but now it works.

Reported-by: Eli Schwartz <eschwartz@archlinux.org>
Tested-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-send-email.perl
t/t9001-send-email.sh

index 57911386835b91b93600abca306c2d28a42f1410..0a6dcc1f887cfb3e98d45c090a4ed7a0e85c176d 100755 (executable)
@@ -373,7 +373,7 @@ sub read_config {
                        @$target = @values;
                }
                else {
-                       my $v = $known_keys->{$key}->[0];
+                       my $v = $known_keys->{$key}->[-1];
                        next unless defined $v;
                        next if $configured->{$setting}++;
                        $$target = $v;
index 612de095fd730df14707a02faafd45eef387da35..fd680a90ac401d83fa9b4134c06c024fa9a39929 100755 (executable)
@@ -1533,6 +1533,21 @@ test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
        test_cmp content-type-decl actual
 '
 
+test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
+       clean_fake_sendmail &&
+       git config sendemail.assume8bitEncoding UTF-8 &&
+       test_when_finished "rm -rf home" &&
+       mkdir home &&
+       git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
+       echo bogus |
+       env HOME="$(pwd)/home" DEBUG=1 \
+       git send-email --from=author@example.com --to=nobody@example.com \
+                       --smtp-server="$(pwd)/fake.sendmail" \
+                       email-using-8bit >stdout &&
+       egrep "Content|MIME" msgtxt1 >actual &&
+       test_cmp content-type-decl actual
+'
+
 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
        clean_fake_sendmail &&
        git config sendemail.assume8bitEncoding "bogus too" &&