test-lib: add test_dir_is_empty()
[gitweb.git] / t / t4014-format-patch.sh
index 58d418098d793b284bb4a7222cf9709c45b26c90..256affce89517a707f9054d2c9643db4f5398832 100755 (executable)
@@ -43,7 +43,7 @@ test_expect_success setup '
 test_expect_success "format-patch --ignore-if-in-upstream" '
 
        git format-patch --stdout master..side >patch0 &&
-       cnt=`grep "^From " patch0 | wc -l` &&
+       cnt=$(grep "^From " patch0 | wc -l) &&
        test $cnt = 3
 
 '
@@ -52,7 +52,7 @@ test_expect_success "format-patch --ignore-if-in-upstream" '
 
        git format-patch --stdout \
                --ignore-if-in-upstream master..side >patch1 &&
-       cnt=`grep "^From " patch1 | wc -l` &&
+       cnt=$(grep "^From " patch1 | wc -l) &&
        test $cnt = 2
 
 '
@@ -69,7 +69,7 @@ test_expect_success "format-patch doesn't consider merge commits" '
        git checkout -b merger master &&
        test_tick &&
        git merge --no-ff slave &&
-       cnt=`git format-patch -3 --stdout | grep "^From " | wc -l` &&
+       cnt=$(git format-patch -3 --stdout | grep "^From " | wc -l) &&
        test $cnt = 3
 '
 
@@ -77,7 +77,7 @@ test_expect_success "format-patch result applies" '
 
        git checkout -b rebuild-0 master &&
        git am -3 patch0 &&
-       cnt=`git rev-list master.. | wc -l` &&
+       cnt=$(git rev-list master.. | wc -l) &&
        test $cnt = 2
 '
 
@@ -85,7 +85,7 @@ test_expect_success "format-patch --ignore-if-in-upstream result applies" '
 
        git checkout -b rebuild-1 master &&
        git am -3 patch1 &&
-       cnt=`git rev-list master.. | wc -l` &&
+       cnt=$(git rev-list master.. | wc -l) &&
        test $cnt = 2
 '
 
@@ -293,7 +293,7 @@ check_threading () {
        (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_PATH" -ne '
+       perl -ne '
                if (/^(message-id|references|in-reply-to)/i) {
                        $printing = 1;
                } elsif (/^\S/) {
@@ -762,24 +762,77 @@ test_expect_success 'format-patch --signature="" suppresses signatures' '
        ! grep "^-- \$" output
 '
 
+test_expect_success 'prepare mail-signature input' '
+       cat >mail-signature <<-\EOF
+
+       Test User <test.email@kernel.org>
+       http://git.kernel.org/cgit/git/git.git
+
+       git.kernel.org/?p=git/git.git;a=summary
+
+       EOF
+'
+
+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 &&
+       {
+               cat mail-signature && echo
+       } >expect &&
+       test_cmp expect actual
+'
+
+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 &&
+       {
+               cat mail-signature && echo
+       } >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '--no-signature suppresses format.signaturefile ' '
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout --no-signature -1 >output &&
+       check_patch output &&
+       ! grep "^-- \$" output
+'
+
+test_expect_success '--signature-file overrides format.signaturefile' '
+       cat >other-mail-signature <<-\EOF
+       Use this other signature instead of mail-signature.
+       EOF
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout \
+                       --signature-file=other-mail-signature -1 >output &&
+       check_patch output &&
+       sed -e "1,/^-- \$/d" <output >actual &&
+       {
+               cat other-mail-signature && echo
+       } >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '--signature overrides format.signaturefile' '
+       test_config format.signaturefile mail-signature &&
+       git format-patch --stdout --signature="my sig" -1 >output &&
+       check_patch output &&
+       grep "my sig" output
+'
+
 test_expect_success TTY 'format-patch --stdout paginates' '
        rm -f pager_used &&
-       (
-               GIT_PAGER="wc >pager_used" &&
-               export GIT_PAGER &&
-               test_terminal git format-patch --stdout --all
-       ) &&
+       test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all &&
        test_path_is_file pager_used
 '
 
  test_expect_success TTY 'format-patch --stdout pagination can be disabled' '
        rm -f pager_used &&
-       (
-               GIT_PAGER="wc >pager_used" &&
-               export GIT_PAGER &&
-               test_terminal git --no-pager format-patch --stdout --all &&
-               test_terminal git -c "pager.format-patch=false" format-patch --stdout --all
-       ) &&
+       test_terminal env GIT_PAGER="wc >pager_used" git --no-pager format-patch --stdout --all &&
+       test_terminal env GIT_PAGER="wc >pager_used" git -c "pager.format-patch=false" format-patch --stdout --all &&
        test_path_is_missing pager_used &&
        test_path_is_missing .git/pager_used
 '
@@ -972,6 +1025,59 @@ test_expect_success 'empty subject prefix does not have extra space' '
        test_cmp expect actual
 '
 
+test_expect_success '--from=ident notices bogus ident' '
+       test_must_fail git format-patch -1 --stdout --from=foo >patch
+'
+
+test_expect_success '--from=ident replaces author' '
+       git format-patch -1 --stdout --from="Me <me@example.com>" >patch &&
+       cat >expect <<-\EOF &&
+       From: Me <me@example.com>
+
+       From: A U Thor <author@example.com>
+
+       EOF
+       sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head &&
+       test_cmp expect patch.head
+'
+
+test_expect_success '--from uses committer ident' '
+       git format-patch -1 --stdout --from >patch &&
+       cat >expect <<-\EOF &&
+       From: C O Mitter <committer@example.com>
+
+       From: A U Thor <author@example.com>
+
+       EOF
+       sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head &&
+       test_cmp expect patch.head
+'
+
+test_expect_success '--from omits redundant in-body header' '
+       git format-patch -1 --stdout --from="A U Thor <author@example.com>" >patch &&
+       cat >expect <<-\EOF &&
+       From: A U Thor <author@example.com>
+
+       EOF
+       sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head &&
+       test_cmp expect patch.head
+'
+
+test_expect_success 'in-body headers trigger content encoding' '
+       GIT_AUTHOR_NAME="éxötìc" test_commit exotic &&
+       test_when_finished "git reset --hard HEAD^" &&
+       git format-patch -1 --stdout --from >patch &&
+       cat >expect <<-\EOF &&
+       From: C O Mitter <committer@example.com>
+       Content-Type: text/plain; charset=UTF-8
+
+       From: éxötìc <author@example.com>
+
+       EOF
+       sed -ne "/^From:/p; /^$/p; /^Content-Type/p; /^---$/q" <patch >patch.head &&
+       test_cmp expect patch.head
+'
+
 append_signoff()
 {
        C=$(git commit-tree HEAD^^{tree} -p HEAD) &&