Skip to content

Commit b996f84

Browse files
avargitster
authored andcommitted
send-email: fix a "first config key wins" regression in v2.33.0
Fix a regression in my c95e3a3 (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 1ff750b (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 <[email protected]> Tested-by: Eli Schwartz <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c95e3a3 commit b996f84

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

git-send-email.perl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ sub read_config {
373373
@$target = @values;
374374
}
375375
else {
376-
my $v = $known_keys->{$key}->[0];
376+
my $v = $known_keys->{$key}->[-1];
377377
next unless defined $v;
378378
next if $configured->{$setting}++;
379379
$$target = $v;

t/t9001-send-email.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,21 @@ test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
15331533
test_cmp content-type-decl actual
15341534
'
15351535

1536+
test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1537+
clean_fake_sendmail &&
1538+
git config sendemail.assume8bitEncoding UTF-8 &&
1539+
test_when_finished "rm -rf home" &&
1540+
mkdir home &&
1541+
git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1542+
echo bogus |
1543+
env HOME="$(pwd)/home" DEBUG=1 \
1544+
1545+
--smtp-server="$(pwd)/fake.sendmail" \
1546+
email-using-8bit >stdout &&
1547+
egrep "Content|MIME" msgtxt1 >actual &&
1548+
test_cmp content-type-decl actual
1549+
'
1550+
15361551
test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
15371552
clean_fake_sendmail &&
15381553
git config sendemail.assume8bitEncoding "bogus too" &&

0 commit comments

Comments
 (0)