format-patch: teach --no-encode-email-headers

When commit subjects or authors have non-ASCII characters, git
format-patch Q-encodes them so they can be safely sent over email.
However, if the patch transfer method is something other than email (web
review tools, sneakernet), this only serves to make the patch metadata
harder to read without first applying it (unless you can decode RFC 2047
in your head). git am as well as some email software supports
non-Q-encoded mail as described in RFC 6531.

Add --[no-]encode-email-headers and format.encodeEmailHeaders to let the
user control this behavior.

Signed-off-by: Emma Brooks <me@pluvano.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Emma Brooks
2020-04-08 04:31:38 +00:00
committed by Junio C Hamano
parent 9fadedd637
commit 19d097e3d7
9 changed files with 85 additions and 3 deletions

View File

@ -1160,6 +1160,59 @@ test_expect_success 'format-patch wraps extremely long from-header (rfc2047)' '
check_author "Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar"
'
cat >expect <<'EOF'
From: Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
Bar Foo Bar Foo Bar Foo Bar <author@example.com>
EOF
test_expect_success 'format-patch wraps extremely long from-header (non-ASCII without Q-encoding)' '
echo content >>file &&
git add file &&
GIT_AUTHOR_NAME="Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar" \
git commit -m author-check &&
git format-patch --no-encode-email-headers --stdout -1 >patch &&
sed -n "/^From: /p; /^ /p; /^$/q" patch >actual &&
test_cmp expect actual
'
cat >expect <<'EOF'
Subject: [PATCH] Foö
EOF
test_expect_success 'subject lines are unencoded with --no-encode-email-headers' '
echo content >>file &&
git add file &&
git commit -m "Foö" &&
git format-patch --no-encode-email-headers -1 --stdout >patch &&
grep ^Subject: patch >actual &&
test_cmp expect actual
'
cat >expect <<'EOF'
Subject: [PATCH] Foö
EOF
test_expect_success 'subject lines are unencoded with format.encodeEmailHeaders=false' '
echo content >>file &&
git add file &&
git commit -m "Foö" &&
git config format.encodeEmailHeaders false &&
git format-patch -1 --stdout >patch &&
grep ^Subject: patch >actual &&
test_cmp expect actual
'
cat >expect <<'EOF'
Subject: [PATCH] =?UTF-8?q?Fo=C3=B6?=
EOF
test_expect_success '--encode-email-headers overrides format.encodeEmailHeaders' '
echo content >>file &&
git add file &&
git commit -m "Foö" &&
git config format.encodeEmailHeaders false &&
git format-patch --encode-email-headers -1 --stdout >patch &&
grep ^Subject: patch >actual &&
test_cmp expect actual
'
cat >expect <<'EOF'
Subject: header with . in it
EOF