about summary refs log tree commit diff
path: root/third_party/git/t/t4014-format-patch.sh
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/git/t/t4014-format-patch.sh')
-rwxr-xr-xthird_party/git/t/t4014-format-patch.sh1059
1 files changed, 412 insertions, 647 deletions
diff --git a/third_party/git/t/t4014-format-patch.sh b/third_party/git/t/t4014-format-patch.sh
index b653dd7d4452..ca7debf1d4c0 100755
--- a/third_party/git/t/t4014-format-patch.sh
+++ b/third_party/git/t/t4014-format-patch.sh
@@ -9,6 +9,7 @@ test_description='various format-patch tests'
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_expect_success setup '
+
 	for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
 	cat file >elif &&
 	git add file elif &&
@@ -33,8 +34,7 @@ test_expect_success setup '
 	git commit -m "Side changes #3 with \\n backslash-n in it." &&
 
 	git checkout master &&
-	git diff-tree -p C2 >patch &&
-	git apply --index <patch &&
+	git diff-tree -p C2 | git apply --index &&
 	test_tick &&
 	git commit -m "Master accepts moral equivalent of #2" &&
 
@@ -59,28 +59,33 @@ test_expect_success setup '
 	git checkout master
 '
 
-test_expect_success 'format-patch --ignore-if-in-upstream' '
+test_expect_success "format-patch --ignore-if-in-upstream" '
+
 	git format-patch --stdout master..side >patch0 &&
-	grep "^From " patch0 >from0 &&
-	test_line_count = 3 from0
+	cnt=$(grep "^From " patch0 | wc -l) &&
+	test $cnt = 3
+
 '
 
-test_expect_success 'format-patch --ignore-if-in-upstream' '
+test_expect_success "format-patch --ignore-if-in-upstream" '
+
 	git format-patch --stdout \
 		--ignore-if-in-upstream master..side >patch1 &&
-	grep "^From " patch1 >from1 &&
-	test_line_count = 2 from1
+	cnt=$(grep "^From " patch1 | wc -l) &&
+	test $cnt = 2
+
 '
 
-test_expect_success 'format-patch --ignore-if-in-upstream handles tags' '
+test_expect_success "format-patch --ignore-if-in-upstream handles tags" '
 	git tag -a v1 -m tag side &&
 	git tag -a v2 -m tag master &&
 	git format-patch --stdout --ignore-if-in-upstream v2..v1 >patch1 &&
-	grep "^From " patch1 >from1 &&
-	test_line_count = 2 from1
+	cnt=$(grep "^From " patch1 | wc -l) &&
+	test $cnt = 2
 '
 
 test_expect_success "format-patch doesn't consider merge commits" '
+
 	git checkout -b slave master &&
 	echo "Another line" >>file &&
 	test_tick &&
@@ -91,138 +96,148 @@ test_expect_success "format-patch doesn't consider merge commits" '
 	git checkout -b merger master &&
 	test_tick &&
 	git merge --no-ff slave &&
-	git format-patch -3 --stdout >patch &&
-	grep "^From " patch >from &&
-	test_line_count = 3 from
+	cnt=$(git format-patch -3 --stdout | grep "^From " | wc -l) &&
+	test $cnt = 3
 '
 
-test_expect_success 'format-patch result applies' '
+test_expect_success "format-patch result applies" '
+
 	git checkout -b rebuild-0 master &&
 	git am -3 patch0 &&
-	git rev-list master.. >list &&
-	test_line_count = 2 list
+	cnt=$(git rev-list master.. | wc -l) &&
+	test $cnt = 2
 '
 
-test_expect_success 'format-patch --ignore-if-in-upstream result applies' '
+test_expect_success "format-patch --ignore-if-in-upstream result applies" '
+
 	git checkout -b rebuild-1 master &&
 	git am -3 patch1 &&
-	git rev-list master.. >list &&
-	test_line_count = 2 list
+	cnt=$(git rev-list master.. | wc -l) &&
+	test $cnt = 2
 '
 
 test_expect_success 'commit did not screw up the log message' '
-	git cat-file commit side >actual &&
-	grep "^Side .* with .* backslash-n" actual
+
+	git cat-file commit side | grep "^Side .* with .* backslash-n"
+
 '
 
 test_expect_success 'format-patch did not screw up the log message' '
+
 	grep "^Subject: .*Side changes #3 with .* backslash-n" patch0 &&
 	grep "^Subject: .*Side changes #3 with .* backslash-n" patch1
+
 '
 
 test_expect_success 'replay did not screw up the log message' '
-	git cat-file commit rebuild-1 >actual &&
-	grep "^Side .* with .* backslash-n" actual
+
+	git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
+
 '
 
 test_expect_success 'extra headers' '
+
 	git config format.headers "To: R E Cipient <rcipient@example.com>
 " &&
 	git config --add format.headers "Cc: S E Cipient <scipient@example.com>
 " &&
-	git format-patch --stdout master..side >patch2 &&
-	sed -e "/^\$/q" patch2 >hdrs2 &&
+	git format-patch --stdout master..side > patch2 &&
+	sed -e "/^\$/q" patch2 > hdrs2 &&
 	grep "^To: R E Cipient <rcipient@example.com>\$" hdrs2 &&
 	grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs2
+
 '
 
 test_expect_success 'extra headers without newlines' '
+
 	git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" &&
 	git config --add format.headers "Cc: S E Cipient <scipient@example.com>" &&
 	git format-patch --stdout master..side >patch3 &&
-	sed -e "/^\$/q" patch3 >hdrs3 &&
+	sed -e "/^\$/q" patch3 > hdrs3 &&
 	grep "^To: R E Cipient <rcipient@example.com>\$" hdrs3 &&
 	grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs3
+
 '
 
 test_expect_success 'extra headers with multiple To:s' '
+
 	git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" &&
 	git config --add format.headers "To: S E Cipient <scipient@example.com>" &&
-	git format-patch --stdout master..side >patch4 &&
-	sed -e "/^\$/q" patch4 >hdrs4 &&
+	git format-patch --stdout master..side > patch4 &&
+	sed -e "/^\$/q" patch4 > hdrs4 &&
 	grep "^To: R E Cipient <rcipient@example.com>,\$" hdrs4 &&
 	grep "^ *S E Cipient <scipient@example.com>\$" hdrs4
 '
 
 test_expect_success 'additional command line cc (ascii)' '
+
 	git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
-	git format-patch --cc="S E Cipient <scipient@example.com>" --stdout master..side >patch5 &&
-	sed -e "/^\$/q" patch5 >hdrs5 &&
-	grep "^Cc: R E Cipient <rcipient@example.com>,\$" hdrs5 &&
-	grep "^ *S E Cipient <scipient@example.com>\$" hdrs5
+	git format-patch --cc="S E Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
+	grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch5 &&
+	grep "^ *S E Cipient <scipient@example.com>\$" patch5
 '
 
 test_expect_failure 'additional command line cc (rfc822)' '
+
 	git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
-	git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout master..side >patch5 &&
-	sed -e "/^\$/q" patch5 >hdrs5 &&
-	grep "^Cc: R E Cipient <rcipient@example.com>,\$" hdrs5 &&
-	grep "^ *\"S. E. Cipient\" <scipient@example.com>\$" hdrs5
+	git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
+	grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch5 &&
+	grep "^ *\"S. E. Cipient\" <scipient@example.com>\$" patch5
 '
 
 test_expect_success 'command line headers' '
+
 	git config --unset-all format.headers &&
-	git format-patch --add-header="Cc: R E Cipient <rcipient@example.com>" --stdout master..side >patch6 &&
-	sed -e "/^\$/q" patch6 >hdrs6 &&
-	grep "^Cc: R E Cipient <rcipient@example.com>\$" hdrs6
+	git format-patch --add-header="Cc: R E Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch6 &&
+	grep "^Cc: R E Cipient <rcipient@example.com>\$" patch6
 '
 
 test_expect_success 'configuration headers and command line headers' '
+
 	git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
-	git format-patch --add-header="Cc: S E Cipient <scipient@example.com>" --stdout master..side >patch7 &&
-	sed -e "/^\$/q" patch7 >hdrs7 &&
-	grep "^Cc: R E Cipient <rcipient@example.com>,\$" hdrs7 &&
-	grep "^ *S E Cipient <scipient@example.com>\$" hdrs7
+	git format-patch --add-header="Cc: S E Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch7 &&
+	grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch7 &&
+	grep "^ *S E Cipient <scipient@example.com>\$" patch7
 '
 
 test_expect_success 'command line To: header (ascii)' '
+
 	git config --unset-all format.headers &&
-	git format-patch --to="R E Cipient <rcipient@example.com>" --stdout master..side >patch8 &&
-	sed -e "/^\$/q" patch8 >hdrs8 &&
-	grep "^To: R E Cipient <rcipient@example.com>\$" hdrs8
+	git format-patch --to="R E Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
+	grep "^To: R E Cipient <rcipient@example.com>\$" patch8
 '
 
 test_expect_failure 'command line To: header (rfc822)' '
-	git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout master..side >patch8 &&
-	sed -e "/^\$/q" patch8 >hdrs8 &&
-	grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" hdrs8
+
+	git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
+	grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" patch8
 '
 
 test_expect_failure 'command line To: header (rfc2047)' '
-	git format-patch --to="R Ä Cipient <rcipient@example.com>" --stdout master..side >patch8 &&
-	sed -e "/^\$/q" patch8 >hdrs8 &&
-	grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" hdrs8
+
+	git format-patch --to="R Ä Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
+	grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" patch8
 '
 
 test_expect_success 'configuration To: header (ascii)' '
+
 	git config format.to "R E Cipient <rcipient@example.com>" &&
-	git format-patch --stdout master..side >patch9 &&
-	sed -e "/^\$/q" patch9 >hdrs9 &&
-	grep "^To: R E Cipient <rcipient@example.com>\$" hdrs9
+	git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
+	grep "^To: R E Cipient <rcipient@example.com>\$" patch9
 '
 
 test_expect_failure 'configuration To: header (rfc822)' '
+
 	git config format.to "R. E. Cipient <rcipient@example.com>" &&
-	git format-patch --stdout master..side >patch9 &&
-	sed -e "/^\$/q" patch9 >hdrs9 &&
-	grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" hdrs9
+	git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
+	grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" patch9
 '
 
 test_expect_failure 'configuration To: header (rfc2047)' '
+
 	git config format.to "R Ä Cipient <rcipient@example.com>" &&
-	git format-patch --stdout master..side >patch9 &&
-	sed -e "/^\$/q" patch9 >hdrs9 &&
-	grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" hdrs9
+	git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
+	grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" patch9
 '
 
 # check_patch <patch>: Verify that <patch> looks like a half-sane
@@ -234,79 +249,89 @@ check_patch () {
 }
 
 test_expect_success 'format.from=false' '
-	git -c format.from=false format-patch --stdout master..side >patch &&
-	sed -e "/^\$/q" patch >hdrs &&
+
+	git -c format.from=false format-patch --stdout master..side |
+	sed -e "/^\$/q" >patch &&
 	check_patch patch &&
-	! grep "^From: C O Mitter <committer@example.com>\$" hdrs
+	! grep "^From: C O Mitter <committer@example.com>\$" patch
 '
 
 test_expect_success 'format.from=true' '
-	git -c format.from=true format-patch --stdout master..side >patch &&
-	sed -e "/^\$/q" patch >hdrs &&
-	check_patch hdrs &&
-	grep "^From: C O Mitter <committer@example.com>\$" hdrs
+
+	git -c format.from=true format-patch --stdout master..side |
+	sed -e "/^\$/q" >patch &&
+	check_patch patch &&
+	grep "^From: C O Mitter <committer@example.com>\$" patch
 '
 
 test_expect_success 'format.from with address' '
-	git -c format.from="F R Om <from@example.com>" format-patch --stdout master..side >patch &&
-	sed -e "/^\$/q" patch >hdrs &&
-	check_patch hdrs &&
-	grep "^From: F R Om <from@example.com>\$" hdrs
+
+	git -c format.from="F R Om <from@example.com>" format-patch --stdout master..side |
+	sed -e "/^\$/q" >patch &&
+	check_patch patch &&
+	grep "^From: F R Om <from@example.com>\$" patch
 '
 
 test_expect_success '--no-from overrides format.from' '
-	git -c format.from="F R Om <from@example.com>" format-patch --no-from --stdout master..side >patch &&
-	sed -e "/^\$/q" patch >hdrs &&
-	check_patch hdrs &&
-	! grep "^From: F R Om <from@example.com>\$" hdrs
+
+	git -c format.from="F R Om <from@example.com>" format-patch --no-from --stdout master..side |
+	sed -e "/^\$/q" >patch &&
+	check_patch patch &&
+	! grep "^From: F R Om <from@example.com>\$" patch
 '
 
 test_expect_success '--from overrides format.from' '
-	git -c format.from="F R Om <from@example.com>" format-patch --from --stdout master..side >patch &&
-	sed -e "/^\$/q" patch >hdrs &&
-	check_patch hdrs &&
-	! grep "^From: F R Om <from@example.com>\$" hdrs
+
+	git -c format.from="F R Om <from@example.com>" format-patch --from --stdout master..side |
+	sed -e "/^\$/q" >patch &&
+	check_patch patch &&
+	! grep "^From: F R Om <from@example.com>\$" patch
 '
 
 test_expect_success '--no-to overrides config.to' '
+
 	git config --replace-all format.to \
 		"R E Cipient <rcipient@example.com>" &&
-	git format-patch --no-to --stdout master..side >patch10 &&
-	sed -e "/^\$/q" patch10 >hdrs10 &&
-	check_patch hdrs10 &&
-	! grep "^To: R E Cipient <rcipient@example.com>\$" hdrs10
+	git format-patch --no-to --stdout master..side |
+	sed -e "/^\$/q" >patch10 &&
+	check_patch patch10 &&
+	! grep "^To: R E Cipient <rcipient@example.com>\$" patch10
 '
 
 test_expect_success '--no-to and --to replaces config.to' '
+
 	git config --replace-all format.to \
 		"Someone <someone@out.there>" &&
 	git format-patch --no-to --to="Someone Else <else@out.there>" \
-		--stdout master..side >patch11 &&
-	sed -e "/^\$/q" patch11 >hdrs11 &&
-	check_patch hdrs11 &&
-	! grep "^To: Someone <someone@out.there>\$" hdrs11 &&
-	grep "^To: Someone Else <else@out.there>\$" hdrs11
+		--stdout master..side |
+	sed -e "/^\$/q" >patch11 &&
+	check_patch patch11 &&
+	! grep "^To: Someone <someone@out.there>\$" patch11 &&
+	grep "^To: Someone Else <else@out.there>\$" patch11
 '
 
 test_expect_success '--no-cc overrides config.cc' '
+
 	git config --replace-all format.cc \
 		"C E Cipient <rcipient@example.com>" &&
-	git format-patch --no-cc --stdout master..side >patch12 &&
-	sed -e "/^\$/q" patch12 >hdrs12 &&
-	check_patch hdrs12 &&
-	! grep "^Cc: C E Cipient <rcipient@example.com>\$" hdrs12
+	git format-patch --no-cc --stdout master..side |
+	sed -e "/^\$/q" >patch12 &&
+	check_patch patch12 &&
+	! grep "^Cc: C E Cipient <rcipient@example.com>\$" patch12
 '
 
 test_expect_success '--no-add-header overrides config.headers' '
+
 	git config --replace-all format.headers \
 		"Header1: B E Cipient <rcipient@example.com>" &&
-	git format-patch --no-add-header --stdout master..side >patch13 &&
-	sed -e "/^\$/q" patch13 >hdrs13 &&
-	check_patch hdrs13 &&
-	! grep "^Header1: B E Cipient <rcipient@example.com>\$" hdrs13
+	git format-patch --no-add-header --stdout master..side |
+	sed -e "/^\$/q" >patch13 &&
+	check_patch patch13 &&
+	! grep "^Header1: B E Cipient <rcipient@example.com>\$" patch13
 '
 
 test_expect_success 'multiple files' '
+
 	rm -rf patches/ &&
 	git checkout side &&
 	git format-patch -o patches/ master &&
@@ -332,7 +357,7 @@ test_expect_success 'reroll count (-v)' '
 check_threading () {
 	expect="$1" &&
 	shift &&
-	git format-patch --stdout "$@" >patch &&
+	(git format-patch --stdout "$@"; echo $? > status.out) |
 	# Prints everything between the Message-ID and In-Reply-To,
 	# and replaces all Message-ID-lookalikes by a sequence number
 	perl -ne '
@@ -347,11 +372,12 @@ check_threading () {
 			print;
 		}
 		print "---\n" if /^From /i;
-	' <patch >actual &&
+	' > actual &&
+	test 0 = "$(cat status.out)" &&
 	test_cmp "$expect" actual
 }
 
-cat >>expect.no-threading <<EOF
+cat >> expect.no-threading <<EOF
 ---
 ---
 ---
@@ -362,7 +388,7 @@ test_expect_success 'no threading' '
 	check_threading expect.no-threading master
 '
 
-cat >expect.thread <<EOF
+cat > expect.thread <<EOF
 ---
 Message-Id: <0>
 ---
@@ -379,7 +405,7 @@ test_expect_success 'thread' '
 	check_threading expect.thread --thread master
 '
 
-cat >expect.in-reply-to <<EOF
+cat > expect.in-reply-to <<EOF
 ---
 Message-Id: <0>
 In-Reply-To: <1>
@@ -399,7 +425,7 @@ test_expect_success 'thread in-reply-to' '
 		--thread master
 '
 
-cat >expect.cover-letter <<EOF
+cat > expect.cover-letter <<EOF
 ---
 Message-Id: <0>
 ---
@@ -420,7 +446,7 @@ test_expect_success 'thread cover-letter' '
 	check_threading expect.cover-letter --cover-letter --thread master
 '
 
-cat >expect.cl-irt <<EOF
+cat > expect.cl-irt <<EOF
 ---
 Message-Id: <0>
 In-Reply-To: <1>
@@ -452,7 +478,7 @@ test_expect_success 'thread explicit shallow' '
 		--in-reply-to="<test.message>" --thread=shallow master
 '
 
-cat >expect.deep <<EOF
+cat > expect.deep <<EOF
 ---
 Message-Id: <0>
 ---
@@ -470,7 +496,7 @@ test_expect_success 'thread deep' '
 	check_threading expect.deep --thread=deep master
 '
 
-cat >expect.deep-irt <<EOF
+cat > expect.deep-irt <<EOF
 ---
 Message-Id: <0>
 In-Reply-To: <1>
@@ -493,7 +519,7 @@ test_expect_success 'thread deep in-reply-to' '
 		--in-reply-to="<test.message>" master
 '
 
-cat >expect.deep-cl <<EOF
+cat > expect.deep-cl <<EOF
 ---
 Message-Id: <0>
 ---
@@ -517,7 +543,7 @@ test_expect_success 'thread deep cover-letter' '
 	check_threading expect.deep-cl --cover-letter --thread=deep master
 '
 
-cat >expect.deep-cl-irt <<EOF
+cat > expect.deep-cl-irt <<EOF
 ---
 Message-Id: <0>
 In-Reply-To: <1>
@@ -568,6 +594,7 @@ test_expect_success 'thread config + --no-thread' '
 '
 
 test_expect_success 'excessive subject' '
+
 	rm -rf patches/ &&
 	git checkout side &&
 	before=$(git hash-object file) &&
@@ -595,9 +622,10 @@ test_expect_success 'cover-letter inherits diff options' '
 	! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
 	git format-patch --cover-letter -1 -M &&
 	grep "file => foo .* 0 *\$" 0000-cover-letter.patch
+
 '
 
-cat >expect <<EOF
+cat > expect << EOF
   This is an excessively long subject line for a message due to the
     habit some projects have of not having a short, one-line subject at
     the start of the commit message, but rather sticking a whole
@@ -608,12 +636,14 @@ cat >expect <<EOF
 EOF
 
 test_expect_success 'shortlog of cover-letter wraps overly-long onelines' '
+
 	git format-patch --cover-letter -2 &&
-	sed -e "1,/A U Thor/d" -e "/^\$/q" 0000-cover-letter.patch >output &&
+	sed -e "1,/A U Thor/d" -e "/^\$/q" < 0000-cover-letter.patch > output &&
 	test_cmp expect output
+
 '
 
-cat >expect <<EOF
+cat > expect << EOF
 index $before..$after 100644
 --- a/file
 +++ b/file
@@ -626,14 +656,16 @@ index $before..$after 100644
 EOF
 
 test_expect_success 'format-patch respects -U' '
+
 	git format-patch -U4 -2 &&
 	sed -e "1,/^diff/d" -e "/^+5/q" \
 		<0001-This-is-an-excessively-long-subject-line-for-a-messa.patch \
 		>output &&
 	test_cmp expect output
+
 '
 
-cat >expect <<EOF
+cat > expect << EOF
 
 diff --git a/file b/file
 index $before..$after 100644
@@ -647,9 +679,11 @@ index $before..$after 100644
 EOF
 
 test_expect_success 'format-patch -p suppresses stat' '
+
 	git format-patch -p -2 &&
-	sed -e "1,/^\$/d" -e "/^+5/q" 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch >output &&
+	sed -e "1,/^\$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output &&
 	test_cmp expect output
+
 '
 
 test_expect_success 'format-patch from a subdirectory (1)' '
@@ -702,7 +736,7 @@ test_expect_success 'format-patch from a subdirectory (3)' '
 '
 
 test_expect_success 'format-patch --in-reply-to' '
-	git format-patch -1 --stdout --in-reply-to "baz@foo.bar" >patch8 &&
+	git format-patch -1 --stdout --in-reply-to "baz@foo.bar" > patch8 &&
 	grep "^In-Reply-To: <baz@foo.bar>" patch8 &&
 	grep "^References: <baz@foo.bar>" patch8
 '
@@ -793,56 +827,21 @@ test_expect_success 'format-patch with multiple notes refs' '
 	! grep "this is note 2" out
 '
 
-test_expect_success 'format-patch with multiple notes refs in config' '
-	test_when_finished "test_unconfig format.notes" &&
-
-	git notes --ref note1 add -m "this is note 1" HEAD &&
-	test_when_finished git notes --ref note1 remove HEAD &&
-	git notes --ref note2 add -m "this is note 2" HEAD &&
-	test_when_finished git notes --ref note2 remove HEAD &&
-
-	git config format.notes note1 &&
-	git format-patch -1 --stdout >out &&
-	grep "this is note 1" out &&
-	! grep "this is note 2" out &&
-	git config format.notes note2 &&
-	git format-patch -1 --stdout >out &&
-	! grep "this is note 1" out &&
-	grep "this is note 2" out &&
-	git config --add format.notes note1 &&
-	git format-patch -1 --stdout >out &&
-	grep "this is note 1" out &&
-	grep "this is note 2" out &&
-
-	git config --replace-all format.notes note1 &&
-	git config --add format.notes false &&
-	git format-patch -1 --stdout >out &&
-	! grep "this is note 1" out &&
-	! grep "this is note 2" out &&
-	git config --add format.notes note2 &&
-	git format-patch -1 --stdout >out &&
-	! grep "this is note 1" out &&
-	grep "this is note 2" out
-'
-
-echo "fatal: --name-only does not make sense" >expect.name-only
-echo "fatal: --name-status does not make sense" >expect.name-status
-echo "fatal: --check does not make sense" >expect.check
+echo "fatal: --name-only does not make sense" > expect.name-only
+echo "fatal: --name-status does not make sense" > expect.name-status
+echo "fatal: --check does not make sense" > expect.check
 
 test_expect_success 'options no longer allowed for format-patch' '
-	test_must_fail git format-patch --name-only 2>output &&
+	test_must_fail git format-patch --name-only 2> output &&
 	test_i18ncmp expect.name-only output &&
-	test_must_fail git format-patch --name-status 2>output &&
+	test_must_fail git format-patch --name-status 2> output &&
 	test_i18ncmp expect.name-status output &&
-	test_must_fail git format-patch --check 2>output &&
-	test_i18ncmp expect.check output
-'
+	test_must_fail git format-patch --check 2> output &&
+	test_i18ncmp expect.check output'
 
 test_expect_success 'format-patch --numstat should produce a patch' '
-	git format-patch --numstat --stdout master..side >output &&
-	grep "^diff --git a/" output >diff &&
-	test_line_count = 5 diff
-'
+	git format-patch --numstat --stdout master..side > output &&
+	test 5 = $(grep "^diff --git a/" output | wc -l)'
 
 test_expect_success 'format-patch -- <path>' '
 	git format-patch master..side -- file 2>error &&
@@ -853,25 +852,20 @@ test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
 	git format-patch --ignore-if-in-upstream HEAD
 '
 
-test_expect_success 'get git version' '
-	git_version=$(git --version) &&
-	git_version=${git_version##* }
-'
+git_version="$(git --version | sed "s/.* //")"
 
 signature() {
 	printf "%s\n%s\n\n" "-- " "${1:-$git_version}"
 }
 
 test_expect_success 'format-patch default signature' '
-	git format-patch --stdout -1 >patch &&
-	tail -n 3 patch >output &&
+	git format-patch --stdout -1 | tail -n 3 >output &&
 	signature >expect &&
 	test_cmp expect output
 '
 
 test_expect_success 'format-patch --signature' '
-	git format-patch --stdout --signature="my sig" -1 >patch &&
-	tail -n 3 patch >output &&
+	git format-patch --stdout --signature="my sig" -1 | tail -n 3 >output &&
 	signature "my sig" >expect &&
 	test_cmp expect output
 '
@@ -903,8 +897,8 @@ test_expect_success 'format-patch --signature --cover-letter' '
 	git config --unset-all format.signature &&
 	git format-patch --stdout --signature="my sig" --cover-letter \
 		-1 >output &&
-	grep "my sig" output >sig &&
-	test_line_count = 2 sig
+	grep "my sig" output &&
+	test 2 = $(grep "my sig" output | wc -l)
 '
 
 test_expect_success 'format.signature="" suppresses signatures' '
@@ -941,7 +935,7 @@ test_expect_success 'prepare mail-signature input' '
 test_expect_success '--signature-file=file works' '
 	git format-patch --stdout --signature-file=mail-signature -1 >output &&
 	check_patch output &&
-	sed -e "1,/^-- \$/d" output >actual &&
+	sed -e "1,/^-- \$/d" <output >actual &&
 	{
 		cat mail-signature && echo
 	} >expect &&
@@ -952,7 +946,7 @@ test_expect_success 'format.signaturefile works' '
 	test_config format.signaturefile mail-signature &&
 	git format-patch --stdout -1 >output &&
 	check_patch output &&
-	sed -e "1,/^-- \$/d" output >actual &&
+	sed -e "1,/^-- \$/d" <output >actual &&
 	{
 		cat mail-signature && echo
 	} >expect &&
@@ -974,7 +968,7 @@ test_expect_success '--signature-file overrides format.signaturefile' '
 	git format-patch --stdout \
 			--signature-file=other-mail-signature -1 >output &&
 	check_patch output &&
-	sed -e "1,/^-- \$/d" output >actual &&
+	sed -e "1,/^-- \$/d" <output >actual &&
 	{
 		cat other-mail-signature && echo
 	} >expect &&
@@ -1043,7 +1037,7 @@ test_expect_success 'format-patch wraps extremely long subject (ascii)' '
 	git add file &&
 	git commit -m "$M512" &&
 	git format-patch --stdout -1 >patch &&
-	sed -n "/^Subject/p; /^ /p; /^$/q" patch >subject &&
+	sed -n "/^Subject/p; /^ /p; /^$/q" <patch >subject &&
 	test_cmp expect subject
 '
 
@@ -1082,7 +1076,7 @@ test_expect_success 'format-patch wraps extremely long subject (rfc2047)' '
 	git add file &&
 	git commit -m "$M512" &&
 	git format-patch --stdout -1 >patch &&
-	sed -n "/^Subject/p; /^ /p; /^$/q" patch >subject &&
+	sed -n "/^Subject/p; /^ /p; /^$/q" <patch >subject &&
 	test_cmp expect subject
 '
 
@@ -1091,7 +1085,7 @@ check_author() {
 	git add file &&
 	GIT_AUTHOR_NAME=$1 git commit -m author-check &&
 	git format-patch --stdout -1 >patch &&
-	sed -n "/^From: /p; /^ /p; /^$/q" patch >actual &&
+	sed -n "/^From: /p; /^ /p; /^$/q" <patch >actual &&
 	test_cmp expect actual
 }
 
@@ -1211,7 +1205,7 @@ test_expect_success '--from=ident replaces author' '
 	From: A U Thor <author@example.com>
 
 	EOF
-	sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
+	sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head &&
 	test_cmp expect patch.head
 '
 
@@ -1223,7 +1217,7 @@ test_expect_success '--from uses committer ident' '
 	From: A U Thor <author@example.com>
 
 	EOF
-	sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
+	sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head &&
 	test_cmp expect patch.head
 '
 
@@ -1233,7 +1227,7 @@ test_expect_success '--from omits redundant in-body header' '
 	From: A U Thor <author@example.com>
 
 	EOF
-	sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
+	sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head &&
 	test_cmp expect patch.head
 '
 
@@ -1248,7 +1242,7 @@ test_expect_success 'in-body headers trigger content encoding' '
 	From: éxötìc <author@example.com>
 
 	EOF
-	sed -ne "/^From:/p; /^$/p; /^Content-Type/p; /^---$/q" patch >patch.head &&
+	sed -ne "/^From:/p; /^$/p; /^Content-Type/p; /^---$/q" <patch >patch.head &&
 	test_cmp expect patch.head
 '
 
@@ -1262,283 +1256,283 @@ append_signoff()
 
 test_expect_success 'signoff: commit with no body' '
 	append_signoff </dev/null >actual &&
-	cat <<-\EOF | sed "s/EOL$//" >expect &&
-	4:Subject: [PATCH] EOL
-	8:
-	9:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+	cat <<\EOF | sed "s/EOL$//" >expected &&
+4:Subject: [PATCH] EOL
+8:
+9:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: commit with only subject' '
 	echo subject | append_signoff >actual &&
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	9:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: commit with only subject that does not end with NL' '
 	printf subject | append_signoff >actual &&
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	9:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: no existing signoffs' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	body
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	10:
-	11:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+body
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: no existing signoffs and no trailing NL' '
 	printf "subject\n\nbody" | append_signoff >actual &&
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	10:
-	11:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: some random signoff' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	body
+body
 
-	Signed-off-by: my@house
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	10:
-	11:Signed-off-by: my@house
-	12:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+Signed-off-by: my@house
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: my@house
+12:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: misc conforming footer elements' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	body
+body
 
-	Signed-off-by: my@house
-	(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
-	Tested-by: Some One <someone@example.com>
-	Bug: 1234
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	10:
-	11:Signed-off-by: my@house
-	15:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+Signed-off-by: my@house
+(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
+Tested-by: Some One <someone@example.com>
+Bug: 1234
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: my@house
+15:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: some random signoff-alike' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	body
-	Fooled-by-me: my@house
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	11:
-	12:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+body
+Fooled-by-me: my@house
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+11:
+12:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: not really a signoff' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	I want to mention about Signed-off-by: here.
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	9:I want to mention about Signed-off-by: here.
-	10:
-	11:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+I want to mention about Signed-off-by: here.
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:I want to mention about Signed-off-by: here.
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: not really a signoff (2)' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	My unfortunate
-	Signed-off-by: example happens to be wrapped here.
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	10:Signed-off-by: example happens to be wrapped here.
-	11:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+My unfortunate
+Signed-off-by: example happens to be wrapped here.
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:Signed-off-by: example happens to be wrapped here.
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: valid S-o-b paragraph in the middle' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	Signed-off-by: my@house
-	Signed-off-by: your@house
+Signed-off-by: my@house
+Signed-off-by: your@house
 
-	A lot of houses.
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	9:Signed-off-by: my@house
-	10:Signed-off-by: your@house
-	11:
-	13:
-	14:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+A lot of houses.
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:Signed-off-by: my@house
+10:Signed-off-by: your@house
+11:
+13:
+14:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: the same signoff at the end' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	body
+body
 
-	Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	10:
-	11:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: the same signoff at the end, no trailing NL' '
 	printf "subject\n\nSigned-off-by: C O Mitter <committer@example.com>" |
 		append_signoff >actual &&
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	9:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: the same signoff NOT at the end' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	body
+body
 
-	Signed-off-by: C O Mitter <committer@example.com>
-	Signed-off-by: my@house
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	10:
-	11:Signed-off-by: C O Mitter <committer@example.com>
-	12:Signed-off-by: my@house
-	EOF
-	test_cmp expect actual
+Signed-off-by: C O Mitter <committer@example.com>
+Signed-off-by: my@house
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+12:Signed-off-by: my@house
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: tolerate garbage in conforming footer' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	body
+body
 
-	Tested-by: my@house
-	Some Trash
-	Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	10:
-	13:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+Tested-by: my@house
+Some Trash
+Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+13:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: respect trailer config' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	Myfooter: x
-	Some Trash
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	11:
-	12:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual &&
+Myfooter: x
+Some Trash
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+11:
+12:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual &&
 
 	test_config trailer.Myfooter.ifexists add &&
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	Myfooter: x
-	Some Trash
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	11:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+Myfooter: x
+Some Trash
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'signoff: footer begins with non-signoff without @ sign' '
-	append_signoff <<-\EOF >actual &&
-	subject
+	append_signoff <<\EOF >actual &&
+subject
 
-	body
+body
 
-	Reviewed-id: Noone
-	Tested-by: my@house
-	Change-id: Ideadbeef
-	Signed-off-by: C O Mitter <committer@example.com>
-	Bug: 1234
-	EOF
-	cat >expect <<-\EOF &&
-	4:Subject: [PATCH] subject
-	8:
-	10:
-	14:Signed-off-by: C O Mitter <committer@example.com>
-	EOF
-	test_cmp expect actual
+Reviewed-id: Noone
+Tested-by: my@house
+Change-id: Ideadbeef
+Signed-off-by: C O Mitter <committer@example.com>
+Bug: 1234
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+14:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'format patch ignores color.ui' '
@@ -1549,218 +1543,46 @@ test_expect_success 'format patch ignores color.ui' '
 	test_cmp expect actual
 '
 
-test_expect_success 'cover letter with invalid --cover-from-description and config' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	test_must_fail git format-patch --cover-letter --cover-from-description garbage master &&
-	test_config format.coverFromDescription garbage &&
-	test_must_fail git format-patch --cover-letter master
-'
-
-test_expect_success 'cover letter with format.coverFromDescription = default' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	test_config format.coverFromDescription default &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter master >actual &&
-	grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	grep "^config subject$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with --cover-from-description default' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter --cover-from-description default master >actual &&
-	grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	grep "^config subject$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with format.coverFromDescription = none' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	test_config format.coverFromDescription none &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter master >actual &&
-	grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
-	grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	! grep "^config subject$" actual &&
-	! grep "^body$" actual
-'
-
-test_expect_success 'cover letter with --cover-from-description none' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter --cover-from-description none master >actual &&
-	grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
-	grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	! grep "^config subject$" actual &&
-	! grep "^body$" actual
-'
-
-test_expect_success 'cover letter with format.coverFromDescription = message' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	test_config format.coverFromDescription message &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter master >actual &&
-	grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	grep "^config subject$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with --cover-from-description message' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter --cover-from-description message master >actual &&
-	grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	grep "^config subject$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with format.coverFromDescription = subject' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	test_config format.coverFromDescription subject &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter master >actual &&
-	grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	! grep "^config subject$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with --cover-from-description subject' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter --cover-from-description subject master >actual &&
-	grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	! grep "^config subject$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with format.coverFromDescription = auto (short subject line)' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	test_config format.coverFromDescription auto &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter master >actual &&
-	grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	! grep "^config subject$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with --cover-from-description auto (short subject line)' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter --cover-from-description auto master >actual &&
-	grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	! grep "^config subject$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with format.coverFromDescription = auto (long subject line)' '
-	test_config branch.rebuild-1.description "this is a really long first line and it is over 100 characters long which is the threshold for long subjects
-
-body" &&
-	test_config format.coverFromDescription auto &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter master >actual &&
-	grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	grep "^this is a really long first line and it is over 100 characters long which is the threshold for long subjects$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with --cover-from-description auto (long subject line)' '
-	test_config branch.rebuild-1.description "this is a really long first line and it is over 100 characters long which is the threshold for long subjects
-
-body" &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter --cover-from-description auto master >actual &&
-	grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	grep "^this is a really long first line and it is over 100 characters long which is the threshold for long subjects$" actual &&
-	grep "^body$" actual
-'
-
-test_expect_success 'cover letter with command-line --cover-from-description overrides config' '
-	test_config branch.rebuild-1.description "config subject
-
-body" &&
-	test_config format.coverFromDescription none &&
-	git checkout rebuild-1 &&
-	git format-patch --stdout --cover-letter --cover-from-description subject master >actual &&
-	grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
-	! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
-	! grep "^config subject$" actual &&
-	grep "^body$" actual
-'
-
 test_expect_success 'cover letter using branch description (1)' '
 	git checkout rebuild-1 &&
 	test_config branch.rebuild-1.description hello &&
 	git format-patch --stdout --cover-letter master >actual &&
-	grep hello actual
+	grep hello actual >/dev/null
 '
 
 test_expect_success 'cover letter using branch description (2)' '
 	git checkout rebuild-1 &&
 	test_config branch.rebuild-1.description hello &&
 	git format-patch --stdout --cover-letter rebuild-1~2..rebuild-1 >actual &&
-	grep hello actual
+	grep hello actual >/dev/null
 '
 
 test_expect_success 'cover letter using branch description (3)' '
 	git checkout rebuild-1 &&
 	test_config branch.rebuild-1.description hello &&
 	git format-patch --stdout --cover-letter ^master rebuild-1 >actual &&
-	grep hello actual
+	grep hello actual >/dev/null
 '
 
 test_expect_success 'cover letter using branch description (4)' '
 	git checkout rebuild-1 &&
 	test_config branch.rebuild-1.description hello &&
 	git format-patch --stdout --cover-letter master.. >actual &&
-	grep hello actual
+	grep hello actual >/dev/null
 '
 
 test_expect_success 'cover letter using branch description (5)' '
 	git checkout rebuild-1 &&
 	test_config branch.rebuild-1.description hello &&
 	git format-patch --stdout --cover-letter -2 HEAD >actual &&
-	grep hello actual
+	grep hello actual >/dev/null
 '
 
 test_expect_success 'cover letter using branch description (6)' '
 	git checkout rebuild-1 &&
 	test_config branch.rebuild-1.description hello &&
 	git format-patch --stdout --cover-letter -2 >actual &&
-	grep hello actual
+	grep hello actual >/dev/null
 '
 
 test_expect_success 'cover letter with nothing' '
@@ -1810,39 +1632,11 @@ test_expect_success 'From line has expected format' '
 	test_cmp from filtered
 '
 
-test_expect_success 'format-patch -o with no leading directories' '
-	rm -fr patches &&
-	git format-patch -o patches master..side &&
-	count=$(git rev-list --count master..side) &&
-	ls patches >list &&
-	test_line_count = $count list
-'
-
-test_expect_success 'format-patch -o with leading existing directories' '
-	rm -rf existing-dir &&
-	mkdir existing-dir &&
-	git format-patch -o existing-dir/patches master..side &&
-	count=$(git rev-list --count master..side) &&
-	ls existing-dir/patches >list &&
-	test_line_count = $count list
-'
-
-test_expect_success 'format-patch -o with leading non-existing directories' '
-	rm -rf non-existing-dir &&
-	git format-patch -o non-existing-dir/patches master..side &&
-	count=$(git rev-list --count master..side) &&
-	test_path_is_dir non-existing-dir &&
-	ls non-existing-dir/patches >list &&
-	test_line_count = $count list
-'
-
 test_expect_success 'format-patch format.outputDirectory option' '
 	test_config format.outputDirectory patches &&
 	rm -fr patches &&
 	git format-patch master..side &&
-	count=$(git rev-list --count master..side) &&
-	ls patches >list &&
-	test_line_count = $count list
+	test $(git rev-list master..side | wc -l) -eq $(ls patches | wc -l)
 '
 
 test_expect_success 'format-patch -o overrides format.outputDirectory' '
@@ -1855,41 +1649,20 @@ test_expect_success 'format-patch -o overrides format.outputDirectory' '
 
 test_expect_success 'format-patch --base' '
 	git checkout patchid &&
-
-	git format-patch --stdout --base=HEAD~3 -1 >patch &&
-	tail -n 7 patch >actual1 &&
-
-	git format-patch --stdout --base=HEAD~3 HEAD~.. >patch &&
-	tail -n 7 patch >actual2 &&
-
-	echo >expect &&
-	git rev-parse HEAD~3 >commit-id-base &&
-	echo "base-commit: $(cat commit-id-base)" >>expect &&
-
-	git show --patch HEAD~2 >patch &&
-	git patch-id --stable <patch >patch.id.raw &&
-	awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>expect &&
-
-	git show --patch HEAD~1 >patch &&
-	git patch-id --stable <patch >patch.id.raw &&
-	awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>expect &&
-
-	signature >>expect &&
-	test_cmp expect actual1 &&
-	test_cmp expect actual2 &&
-
+	git format-patch --stdout --base=HEAD~3 -1 | tail -n 7 >actual1 &&
+	git format-patch --stdout --base=HEAD~3 HEAD~.. | tail -n 7 >actual2 &&
+	echo >expected &&
+	echo "base-commit: $(git rev-parse HEAD~3)" >>expected &&
+	echo "prerequisite-patch-id: $(git show --patch HEAD~2 | git patch-id --stable | awk "{print \$1}")" >>expected &&
+	echo "prerequisite-patch-id: $(git show --patch HEAD~1 | git patch-id --stable | awk "{print \$1}")" >>expected &&
+	signature >> expected &&
+	test_cmp expected actual1 &&
+	test_cmp expected actual2 &&
 	echo >fail &&
-	echo "base-commit: $(cat commit-id-base)" >>fail &&
-
-	git show --patch HEAD~2 >patch &&
-	git patch-id --unstable <patch >patch.id.raw &&
-	awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>fail &&
-
-	git show --patch HEAD~1 >patch &&
-	git patch-id --unstable <patch >patch.id.raw &&
-	awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>fail &&
-
-	signature >>fail &&
+	echo "base-commit: $(git rev-parse HEAD~3)" >>fail &&
+	echo "prerequisite-patch-id: $(git show --patch HEAD~2 | git patch-id --unstable | awk "{print \$1}")" >>fail &&
+	echo "prerequisite-patch-id: $(git show --patch HEAD~1 | git patch-id --unstable | awk "{print \$1}")" >>fail &&
+	signature >> fail &&
 	! test_cmp fail actual1 &&
 	! test_cmp fail actual2
 '
@@ -1899,9 +1672,8 @@ test_expect_success 'format-patch --base errors out when base commit is in revis
 	test_must_fail git format-patch --base=HEAD~1 -2 &&
 	git format-patch --stdout --base=HEAD~2 -2 >patch &&
 	grep "^base-commit:" patch >actual &&
-	git rev-parse HEAD~2 >commit-id-base &&
-	echo "base-commit: $(cat commit-id-base)" >expect &&
-	test_cmp expect actual
+	echo "base-commit: $(git rev-parse HEAD~2)" >expected &&
+	test_cmp expected actual
 '
 
 test_expect_success 'format-patch --base errors out when base commit is not ancestor of revision list' '
@@ -1927,8 +1699,8 @@ test_expect_success 'format-patch --base errors out when base commit is not ance
 	test_must_fail git format-patch --base=$(cat commit-id-Z) -3 &&
 	git format-patch --stdout --base=$(cat commit-id-base) -3 >patch &&
 	grep "^base-commit:" patch >actual &&
-	echo "base-commit: $(cat commit-id-base)" >expect &&
-	test_cmp expect actual
+	echo "base-commit: $(cat commit-id-base)" >expected &&
+	test_cmp expected actual
 '
 
 test_expect_success 'format-patch --base=auto' '
@@ -1939,9 +1711,8 @@ test_expect_success 'format-patch --base=auto' '
 	test_commit N2 &&
 	git format-patch --stdout --base=auto -2 >patch &&
 	grep "^base-commit:" patch >actual &&
-	git rev-parse upstream >commit-id-base &&
-	echo "base-commit: $(cat commit-id-base)" >expect &&
-	test_cmp expect actual
+	echo "base-commit: $(git rev-parse upstream)" >expected &&
+	test_cmp expected actual
 '
 
 test_expect_success 'format-patch errors out when history involves criss-cross' '
@@ -1971,29 +1742,23 @@ test_expect_success 'format-patch errors out when history involves criss-cross'
 	test_must_fail 	git format-patch --base=auto -1
 '
 
-test_expect_success 'format-patch format.useAutoBase option' '
+test_expect_success 'format-patch format.useAutoBaseoption' '
+	test_when_finished "git config --unset format.useAutoBase" &&
 	git checkout local &&
-	test_config format.useAutoBase true &&
+	git config format.useAutoBase true &&
 	git format-patch --stdout -1 >patch &&
 	grep "^base-commit:" patch >actual &&
-	git rev-parse upstream >commit-id-base &&
-	echo "base-commit: $(cat commit-id-base)" >expect &&
-	test_cmp expect actual
+	echo "base-commit: $(git rev-parse upstream)" >expected &&
+	test_cmp expected actual
 '
 
 test_expect_success 'format-patch --base overrides format.useAutoBase' '
-	test_config format.useAutoBase true &&
+	test_when_finished "git config --unset format.useAutoBase" &&
+	git config format.useAutoBase true &&
 	git format-patch --stdout --base=HEAD~1 -1 >patch &&
 	grep "^base-commit:" patch >actual &&
-	git rev-parse HEAD~1 >commit-id-base &&
-	echo "base-commit: $(cat commit-id-base)" >expect &&
-	test_cmp expect actual
-'
-
-test_expect_success 'format-patch --no-base overrides format.useAutoBase' '
-	test_config format.useAutoBase true &&
-	git format-patch --stdout --no-base -1 >patch &&
-	! grep "^base-commit:" patch
+	echo "base-commit: $(git rev-parse HEAD~1)" >expected &&
+	test_cmp expected actual
 '
 
 test_expect_success 'format-patch --base with --attach' '
@@ -2068,7 +1833,7 @@ test_expect_success 'interdiff: cover-letter' '
 	git format-patch --cover-letter --interdiff=boop~2 -1 boop &&
 	test_i18ngrep "^Interdiff:$" 0000-cover-letter.patch &&
 	test_i18ngrep ! "^Interdiff:$" 0001-fleep.patch &&
-	sed "1,/^@@ /d; /^-- $/q" 0000-cover-letter.patch >actual &&
+	sed "1,/^@@ /d; /^-- $/q" <0000-cover-letter.patch >actual &&
 	test_cmp expect actual
 '
 
@@ -2084,7 +1849,7 @@ test_expect_success 'interdiff: solo-patch' '
 	EOF
 	git format-patch --interdiff=boop~2 -1 boop &&
 	test_i18ngrep "^Interdiff:$" 0001-fleep.patch &&
-	sed "1,/^  @@ /d; /^$/q" 0001-fleep.patch >actual &&
+	sed "1,/^  @@ /d; /^$/q" <0001-fleep.patch >actual &&
 	test_cmp expect actual
 '