From patchwork Mon Aug 19 23:52:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11102359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78E2D1399 for ; Mon, 19 Aug 2019 23:52:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BD8D205F4 for ; Mon, 19 Aug 2019 23:52:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aBZKz5N+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728839AbfHSXwv (ORCPT ); Mon, 19 Aug 2019 19:52:51 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:41805 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728817AbfHSXwv (ORCPT ); Mon, 19 Aug 2019 19:52:51 -0400 Received: by mail-io1-f68.google.com with SMTP id j5so8229496ioj.8 for ; Mon, 19 Aug 2019 16:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=LB8+QP0W14RloAxZEFjr6JGDTw9glCiy+r71pQ3Kpn0=; b=aBZKz5N+KZ3Syqti3vj4XoYdfhs/JBhcJNW/aEEd18+BP6jf8cPviv6iNkMu6VNTOk Sp5MDfBsXpYFS9uRn3eEFjQVzzP9zaJsS6iTgXOo9NfS6O5Pksz9LKpiMZmIXPHZcZOI SN9kmsbbgHvXO9/6OpgQuKngSLltx9LQozxaFGix3qA6706I7rDUaGXDQdC+otkjb6+y zx5f5DC25xQzMRpAr7TSrnEwkyZBZlKf2IdmTBDDgjZf7s7UEyn5VrUtDKyhez0vaVs7 Aj1r+odm4TOQFPrl9+OOFXduOtPJ/q33HRb2jp2uorM9FtjdOGmNXDRCXJR1CYWOplA8 HENA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=LB8+QP0W14RloAxZEFjr6JGDTw9glCiy+r71pQ3Kpn0=; b=Iv14PuYyIw4OUdQzAEyY/ThzGZyuy1DEzpmIHNl3PhPBt6+kvPVC4Sp5xWezBMX7bB 39R+Tc/UgfF9rj+Vwq399c9QFH3Y/cttZ07F3I5fKr2EJ2+0ARQX6BqsnlPSqHOlYwdG +4CSZcX2FKp3OUidOJ/w7ZE91yzvGUyt8NlUIsT0QgNkkiC6an3p1QtfvQOWg+eoS45W P0SWWC+iWWynb/cXmyO3goG+/XJluu9OQihtDcFQ/W6TNOKAQ9cAAqTm1m0rsL+2Uyml fNblr2FtfGpiXQjZmq43OX664/7fd/eUcDyOIDxmNdmZGM+Oi4zQGPgT8WJ4+vYgFCpE +/Ow== X-Gm-Message-State: APjAAAXlW6YjAtHimWwxo1gwAGYlv73pLysmFtx+EKdpMVUpYcYi+uJ2 jiAi4OuAE/bLI7u0ihpi8o91D9t6 X-Google-Smtp-Source: APXvYqx+pdqeCAwt0GQjHnML7CR09ueLJEgZJFktvxC9EH5TKObl4uRFtLzfEJ1LeBHX3cLpMwiieQ== X-Received: by 2002:a05:6638:105:: with SMTP id x5mr472201jao.43.1566258768412; Mon, 19 Aug 2019 16:52:48 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.89.95]) by smtp.gmail.com with ESMTPSA id h3sm5002943iof.65.2019.08.19.16.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 16:52:47 -0700 (PDT) Date: Mon, 19 Aug 2019 19:52:46 -0400 From: Denton Liu To: Git Mailing List Cc: =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Junio C Hamano , Eric Sunshine Subject: [PATCH v2 1/4] t4014: clean up style Message-ID: <76a0a274fde564f709d294acd7d6da17167f05b5.1566258525.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In Git's tests, there is typically no space between the redirection operator and the filename. Remove these spaces. Since output is silenced when running without `-v` and debugging output is useful with `-v`, remove redirections to /dev/null. Change here-docs from `<<\EOF` to `<<-\EOF` so that they can be indented along with the rest of the test case. Convert all instances of `cnt=$(... | wc -l) && test $cnt = N` into uses of `test_line_count()`. For style, move the ending sq of test cases onto its own line whenever they do not conform. Rename output files from "expected" to "expect" to conform with the usual convention. Finally, refactor to remove Git commands upstream of pipe as well as Git commands that are in a non-variable-assignment subshell (e.g. `echo "base-commit: $(git rev-parse HEAD)"`. This way, if an invocation of a Git command fails, the return code won't be lost. Keep upstream non-Git commands since we have to assume a base level of sanity. Signed-off-by: Denton Liu --- This patch is getting a little unwieldy. Perhaps we could split it into several smaller patches? Unfortunately, I'm not really sure where a logical place to split it would be. t/t4014-format-patch.sh | 733 +++++++++++++++++++++------------------- 1 file changed, 387 insertions(+), 346 deletions(-) diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index ca7debf1d4..0114608b1f 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -34,7 +34,8 @@ test_expect_success setup ' git commit -m "Side changes #3 with \\n backslash-n in it." && git checkout master && - git diff-tree -p C2 | git apply --index && + git diff-tree -p C2 >patch && + git apply --index patch0 && - cnt=$(grep "^From " patch0 | wc -l) && - test $cnt = 3 - + grep "^From " patch0 >from0 && + test_line_count = 3 from0 ' 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) && - test $cnt = 2 - + grep "^From " patch1 >from1 && + test_line_count = 2 from1 ' 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 && - cnt=$(grep "^From " patch1 | wc -l) && - test $cnt = 2 + grep "^From " patch1 >from1 && + test_line_count = 2 from1 ' test_expect_success "format-patch doesn't consider merge commits" ' @@ -96,29 +95,31 @@ 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) && - test $cnt = 3 + git format-patch -3 --stdout >patch && + grep "^From " patch >from && + test_line_count = 3 from ' test_expect_success "format-patch result applies" ' git checkout -b rebuild-0 master && git am -3 patch0 && - cnt=$(git rev-list master.. | wc -l) && - test $cnt = 2 + git rev-list master.. >list && + test_line_count = 2 list ' 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) && - test $cnt = 2 + git rev-list master.. >list && + test_line_count = 2 list ' test_expect_success 'commit did not screw up the log message' ' - git cat-file commit side | grep "^Side .* with .* backslash-n" + git cat-file commit side >actual && + grep "^Side .* with .* backslash-n" actual ' @@ -131,7 +132,8 @@ test_expect_success 'format-patch did not screw up the log message' ' test_expect_success 'replay did not screw up the log message' ' - git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n" + git cat-file commit rebuild-1 >actual && + grep "^Side .* with .* backslash-n" actual ' @@ -141,8 +143,8 @@ test_expect_success 'extra headers' ' " && git config --add format.headers "Cc: S E Cipient " && - 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 \$" hdrs2 && grep "^Cc: S E Cipient \$" hdrs2 @@ -153,7 +155,7 @@ test_expect_success 'extra headers without newlines' ' git config --replace-all format.headers "To: R E Cipient " && git config --add format.headers "Cc: S E Cipient " && git format-patch --stdout master..side >patch3 && - sed -e "/^\$/q" patch3 > hdrs3 && + sed -e "/^\$/q" patch3 >hdrs3 && grep "^To: R E Cipient \$" hdrs3 && grep "^Cc: S E Cipient \$" hdrs3 @@ -163,8 +165,8 @@ test_expect_success 'extra headers with multiple To:s' ' git config --replace-all format.headers "To: R E Cipient " && git config --add format.headers "To: S E Cipient " && - 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 ,\$" hdrs4 && grep "^ *S E Cipient \$" hdrs4 ' @@ -172,72 +174,82 @@ test_expect_success 'extra headers with multiple To:s' ' test_expect_success 'additional command line cc (ascii)' ' git config --replace-all format.headers "Cc: R E Cipient " && - git format-patch --cc="S E Cipient " --stdout master..side | sed -e "/^\$/q" >patch5 && - grep "^Cc: R E Cipient ,\$" patch5 && - grep "^ *S E Cipient \$" patch5 + git format-patch --cc="S E Cipient " --stdout master..side >patch5 && + sed -e "/^\$/q" patch5 >hdrs5 && + grep "^Cc: R E Cipient ,\$" hdrs5 && + grep "^ *S E Cipient \$" hdrs5 ' test_expect_failure 'additional command line cc (rfc822)' ' git config --replace-all format.headers "Cc: R E Cipient " && - git format-patch --cc="S. E. Cipient " --stdout master..side | sed -e "/^\$/q" >patch5 && - grep "^Cc: R E Cipient ,\$" patch5 && - grep "^ *\"S. E. Cipient\" \$" patch5 + git format-patch --cc="S. E. Cipient " --stdout master..side >patch5 && + sed -e "/^\$/q" patch5 >hdrs5 && + grep "^Cc: R E Cipient ,\$" hdrs5 && + grep "^ *\"S. E. Cipient\" \$" hdrs5 ' test_expect_success 'command line headers' ' git config --unset-all format.headers && - git format-patch --add-header="Cc: R E Cipient " --stdout master..side | sed -e "/^\$/q" >patch6 && - grep "^Cc: R E Cipient \$" patch6 + git format-patch --add-header="Cc: R E Cipient " --stdout master..side >patch6 && + sed -e "/^\$/q" patch6 >hdrs6 && + grep "^Cc: R E Cipient \$" hdrs6 ' test_expect_success 'configuration headers and command line headers' ' git config --replace-all format.headers "Cc: R E Cipient " && - git format-patch --add-header="Cc: S E Cipient " --stdout master..side | sed -e "/^\$/q" >patch7 && - grep "^Cc: R E Cipient ,\$" patch7 && - grep "^ *S E Cipient \$" patch7 + git format-patch --add-header="Cc: S E Cipient " --stdout master..side >patch7 && + sed -e "/^\$/q" patch7 >hdrs7 && + grep "^Cc: R E Cipient ,\$" hdrs7 && + grep "^ *S E Cipient \$" hdrs7 ' test_expect_success 'command line To: header (ascii)' ' git config --unset-all format.headers && - git format-patch --to="R E Cipient " --stdout master..side | sed -e "/^\$/q" >patch8 && - grep "^To: R E Cipient \$" patch8 + git format-patch --to="R E Cipient " --stdout master..side >patch8 && + sed -e "/^\$/q" patch8 >hdrs8 && + grep "^To: R E Cipient \$" hdrs8 ' test_expect_failure 'command line To: header (rfc822)' ' - git format-patch --to="R. E. Cipient " --stdout master..side | sed -e "/^\$/q" >patch8 && - grep "^To: \"R. E. Cipient\" \$" patch8 + git format-patch --to="R. E. Cipient " --stdout master..side >patch8 && + sed -e "/^\$/q" patch8 >hdrs8 && + grep "^To: \"R. E. Cipient\" \$" hdrs8 ' test_expect_failure 'command line To: header (rfc2047)' ' - git format-patch --to="R Ä Cipient " --stdout master..side | sed -e "/^\$/q" >patch8 && - grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= \$" patch8 + git format-patch --to="R Ä Cipient " --stdout master..side >patch8 && + sed -e "/^\$/q" patch8 >hdrs8 && + grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= \$" hdrs8 ' test_expect_success 'configuration To: header (ascii)' ' git config format.to "R E Cipient " && - git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 && - grep "^To: R E Cipient \$" patch9 + git format-patch --stdout master..side >patch9 && + sed -e "/^\$/q" patch9 >hdrs9 && + grep "^To: R E Cipient \$" hdrs9 ' test_expect_failure 'configuration To: header (rfc822)' ' git config format.to "R. E. Cipient " && - git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 && - grep "^To: \"R. E. Cipient\" \$" patch9 + git format-patch --stdout master..side >patch9 && + sed -e "/^\$/q" patch9 >hdrs9 && + grep "^To: \"R. E. Cipient\" \$" hdrs9 ' test_expect_failure 'configuration To: header (rfc2047)' ' git config format.to "R Ä Cipient " && - git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 && - grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= \$" patch9 + git format-patch --stdout master..side >patch9 && + sed -e "/^\$/q" patch9 >hdrs9 && + grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= \$" hdrs9 ' # check_patch : Verify that looks like a half-sane @@ -250,52 +262,52 @@ check_patch () { test_expect_success 'format.from=false' ' - git -c format.from=false format-patch --stdout master..side | - sed -e "/^\$/q" >patch && + git -c format.from=false format-patch --stdout master..side >patch && + sed -e "/^\$/q" patch >hdrs && check_patch patch && - ! grep "^From: C O Mitter \$" patch + ! grep "^From: C O Mitter \$" hdrs ' test_expect_success 'format.from=true' ' - git -c format.from=true format-patch --stdout master..side | - sed -e "/^\$/q" >patch && - check_patch patch && - grep "^From: C O Mitter \$" patch + git -c format.from=true format-patch --stdout master..side >patch && + sed -e "/^\$/q" patch >hdrs && + check_patch hdrs && + grep "^From: C O Mitter \$" hdrs ' test_expect_success 'format.from with address' ' - git -c format.from="F R Om " format-patch --stdout master..side | - sed -e "/^\$/q" >patch && - check_patch patch && - grep "^From: F R Om \$" patch + git -c format.from="F R Om " format-patch --stdout master..side >patch && + sed -e "/^\$/q" patch >hdrs && + check_patch hdrs && + grep "^From: F R Om \$" hdrs ' test_expect_success '--no-from overrides format.from' ' - git -c format.from="F R Om " format-patch --no-from --stdout master..side | - sed -e "/^\$/q" >patch && - check_patch patch && - ! grep "^From: F R Om \$" patch + git -c format.from="F R Om " format-patch --no-from --stdout master..side >patch && + sed -e "/^\$/q" patch >hdrs && + check_patch hdrs && + ! grep "^From: F R Om \$" hdrs ' test_expect_success '--from overrides format.from' ' - git -c format.from="F R Om " format-patch --from --stdout master..side | - sed -e "/^\$/q" >patch && - check_patch patch && - ! grep "^From: F R Om \$" patch + git -c format.from="F R Om " format-patch --from --stdout master..side >patch && + sed -e "/^\$/q" patch >hdrs && + check_patch hdrs && + ! grep "^From: F R Om \$" hdrs ' test_expect_success '--no-to overrides config.to' ' git config --replace-all format.to \ "R E Cipient " && - git format-patch --no-to --stdout master..side | - sed -e "/^\$/q" >patch10 && - check_patch patch10 && - ! grep "^To: R E Cipient \$" patch10 + git format-patch --no-to --stdout master..side >patch10 && + sed -e "/^\$/q" patch10 >hdrs10 && + check_patch hdrs10 && + ! grep "^To: R E Cipient \$" hdrs10 ' test_expect_success '--no-to and --to replaces config.to' ' @@ -303,31 +315,31 @@ test_expect_success '--no-to and --to replaces config.to' ' git config --replace-all format.to \ "Someone " && git format-patch --no-to --to="Someone Else " \ - --stdout master..side | - sed -e "/^\$/q" >patch11 && - check_patch patch11 && - ! grep "^To: Someone \$" patch11 && - grep "^To: Someone Else \$" patch11 + --stdout master..side >patch11 && + sed -e "/^\$/q" patch11 >hdrs11 && + check_patch hdrs11 && + ! grep "^To: Someone \$" hdrs11 && + grep "^To: Someone Else \$" hdrs11 ' test_expect_success '--no-cc overrides config.cc' ' git config --replace-all format.cc \ "C E Cipient " && - git format-patch --no-cc --stdout master..side | - sed -e "/^\$/q" >patch12 && - check_patch patch12 && - ! grep "^Cc: C E Cipient \$" patch12 + git format-patch --no-cc --stdout master..side >patch12 && + sed -e "/^\$/q" patch12 >hdrs12 && + check_patch hdrs12 && + ! grep "^Cc: C E Cipient \$" hdrs12 ' test_expect_success '--no-add-header overrides config.headers' ' git config --replace-all format.headers \ "Header1: B E Cipient " && - git format-patch --no-add-header --stdout master..side | - sed -e "/^\$/q" >patch13 && - check_patch patch13 && - ! grep "^Header1: B E Cipient \$" patch13 + git format-patch --no-add-header --stdout master..side >patch13 && + sed -e "/^\$/q" patch13 >hdrs13 && + check_patch hdrs13 && + ! grep "^Header1: B E Cipient \$" hdrs13 ' test_expect_success 'multiple files' ' @@ -357,7 +369,7 @@ test_expect_success 'reroll count (-v)' ' check_threading () { expect="$1" && shift && - (git format-patch --stdout "$@"; echo $? > status.out) | + git format-patch --stdout "$@" >patch && # Prints everything between the Message-ID and In-Reply-To, # and replaces all Message-ID-lookalikes by a sequence number perl -ne ' @@ -372,12 +384,11 @@ check_threading () { print; } print "---\n" if /^From /i; - ' > actual && - test 0 = "$(cat status.out)" && + ' actual && test_cmp "$expect" actual } -cat >> expect.no-threading <>expect.no-threading < expect.thread <expect.thread < --- @@ -405,7 +416,7 @@ test_expect_success 'thread' ' check_threading expect.thread --thread master ' -cat > expect.in-reply-to <expect.in-reply-to < In-Reply-To: <1> @@ -425,7 +436,7 @@ test_expect_success 'thread in-reply-to' ' --thread master ' -cat > expect.cover-letter <expect.cover-letter < --- @@ -446,7 +457,7 @@ test_expect_success 'thread cover-letter' ' check_threading expect.cover-letter --cover-letter --thread master ' -cat > expect.cl-irt <expect.cl-irt < In-Reply-To: <1> @@ -478,7 +489,7 @@ test_expect_success 'thread explicit shallow' ' --in-reply-to="" --thread=shallow master ' -cat > expect.deep <expect.deep < --- @@ -496,7 +507,7 @@ test_expect_success 'thread deep' ' check_threading expect.deep --thread=deep master ' -cat > expect.deep-irt <expect.deep-irt < In-Reply-To: <1> @@ -519,7 +530,7 @@ test_expect_success 'thread deep in-reply-to' ' --in-reply-to="" master ' -cat > expect.deep-cl <expect.deep-cl < --- @@ -543,7 +554,7 @@ test_expect_success 'thread deep cover-letter' ' check_threading expect.deep-cl --cover-letter --thread=deep master ' -cat > expect.deep-cl-irt <expect.deep-cl-irt < In-Reply-To: <1> @@ -625,7 +636,7 @@ test_expect_success 'cover-letter inherits diff options' ' ' -cat > expect << EOF +cat >expect < output && + sed -e "1,/A U Thor/d" -e "/^\$/q" <0000-cover-letter.patch >output && test_cmp expect output ' -cat > expect << EOF +cat >expect < expect << EOF +cat >expect < 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 ' @@ -736,7 +747,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: " patch8 && grep "^References: " patch8 ' @@ -827,21 +838,24 @@ test_expect_success 'format-patch with multiple notes refs' ' ! 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 && - test 5 = $(grep "^diff --git a/" output | wc -l)' + git format-patch --numstat --stdout master..side >output && + grep "^diff --git a/" output >diff && + test_line_count = 5 diff +' test_expect_success 'format-patch -- ' ' git format-patch master..side -- file 2>error && @@ -852,20 +866,21 @@ test_expect_success 'format-patch --ignore-if-in-upstream HEAD' ' git format-patch --ignore-if-in-upstream HEAD ' -git_version="$(git --version | sed "s/.* //")" - signature() { + git_version="$(git --version >version && sed "s/.* //" version)" && printf "%s\n%s\n\n" "-- " "${1:-$git_version}" } test_expect_success 'format-patch default signature' ' - git format-patch --stdout -1 | tail -n 3 >output && + git format-patch --stdout -1 >patch && + tail -n 3 patch >output && signature >expect && test_cmp expect output ' test_expect_success 'format-patch --signature' ' - git format-patch --stdout --signature="my sig" -1 | tail -n 3 >output && + git format-patch --stdout --signature="my sig" -1 >patch && + tail -n 3 patch >output && signature "my sig" >expect && test_cmp expect output ' @@ -897,8 +912,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 && - test 2 = $(grep "my sig" output | wc -l) + grep "my sig" output >sig && + test_line_count = 2 sig ' test_expect_success 'format.signature="" suppresses signatures' ' @@ -1256,283 +1271,283 @@ append_signoff() test_expect_success 'signoff: commit with no body' ' append_signoff actual && - cat <<\EOF | sed "s/EOL$//" >expected && -4:Subject: [PATCH] EOL -8: -9:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + cat <<-\EOF | sed "s/EOL$//" >expect && + 4:Subject: [PATCH] EOL + 8: + 9:Signed-off-by: C O Mitter + EOF + test_cmp expect actual ' test_expect_success 'signoff: commit with only subject' ' echo subject | append_signoff >actual && - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -9:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 9:Signed-off-by: C O Mitter + EOF + test_cmp expect actual ' test_expect_success 'signoff: commit with only subject that does not end with NL' ' printf subject | append_signoff >actual && - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -9:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 9:Signed-off-by: C O Mitter + EOF + test_cmp expect actual ' test_expect_success 'signoff: no existing signoffs' ' - append_signoff <<\EOF >actual && -subject + append_signoff <<-\EOF >actual && + subject -body -EOF - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -10: -11:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + body + EOF + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 10: + 11:Signed-off-by: C O Mitter + EOF + test_cmp expect actual ' test_expect_success 'signoff: no existing signoffs and no trailing NL' ' printf "subject\n\nbody" | append_signoff >actual && - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -10: -11:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 10: + 11:Signed-off-by: C O Mitter + EOF + test_cmp expect 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 >expected <<\EOF && -4:Subject: [PATCH] subject -8: -10: -11:Signed-off-by: my@house -12:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + 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 + EOF + test_cmp expect 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 -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 -EOF - test_cmp expected actual + Signed-off-by: my@house + (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709) + Tested-by: Some One + 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 + EOF + test_cmp expect 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 >expected <<\EOF && -4:Subject: [PATCH] subject -8: -11: -12:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + body + Fooled-by-me: my@house + EOF + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 11: + 12:Signed-off-by: C O Mitter + EOF + test_cmp expect 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 >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 -EOF - test_cmp expected actual + 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 + EOF + test_cmp expect 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 >expected <<\EOF && -4:Subject: [PATCH] subject -8: -10:Signed-off-by: example happens to be wrapped here. -11:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + 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 + EOF + test_cmp expect 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 >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 -EOF - test_cmp expected actual + 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 + EOF + test_cmp expect 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 -EOF - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -10: -11:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + Signed-off-by: C O Mitter + EOF + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 10: + 11:Signed-off-by: C O Mitter + EOF + test_cmp expect actual ' test_expect_success 'signoff: the same signoff at the end, no trailing NL' ' printf "subject\n\nSigned-off-by: C O Mitter " | append_signoff >actual && - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -9:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 9:Signed-off-by: C O Mitter + EOF + test_cmp expect 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 -Signed-off-by: my@house -EOF - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -10: -11:Signed-off-by: C O Mitter -12:Signed-off-by: my@house -EOF - test_cmp expected actual + Signed-off-by: C O Mitter + Signed-off-by: my@house + EOF + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 10: + 11:Signed-off-by: C O Mitter + 12:Signed-off-by: my@house + EOF + test_cmp expect 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 -EOF - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -10: -13:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + Tested-by: my@house + Some Trash + Signed-off-by: C O Mitter + EOF + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 10: + 13:Signed-off-by: C O Mitter + EOF + test_cmp expect actual ' test_expect_success 'signoff: respect trailer config' ' - append_signoff <<\EOF >actual && -subject + append_signoff <<-\EOF >actual && + subject -Myfooter: x -Some Trash -EOF - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -11: -12:Signed-off-by: C O Mitter -EOF - test_cmp expected actual && + Myfooter: x + Some Trash + EOF + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 11: + 12:Signed-off-by: C O Mitter + EOF + test_cmp expect actual && test_config trailer.Myfooter.ifexists add && - append_signoff <<\EOF >actual && -subject + append_signoff <<-\EOF >actual && + subject -Myfooter: x -Some Trash -EOF - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -11:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + Myfooter: x + Some Trash + EOF + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 11:Signed-off-by: C O Mitter + EOF + test_cmp expect 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 -Bug: 1234 -EOF - cat >expected <<\EOF && -4:Subject: [PATCH] subject -8: -10: -14:Signed-off-by: C O Mitter -EOF - test_cmp expected actual + Reviewed-id: Noone + Tested-by: my@house + Change-id: Ideadbeef + Signed-off-by: C O Mitter + Bug: 1234 + EOF + cat >expect <<-\EOF && + 4:Subject: [PATCH] subject + 8: + 10: + 14:Signed-off-by: C O Mitter + EOF + test_cmp expect actual ' test_expect_success 'format patch ignores color.ui' ' @@ -1547,42 +1562,42 @@ 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 >/dev/null + grep hello actual ' 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 >/dev/null + grep hello actual ' 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 >/dev/null + grep hello actual ' 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 >/dev/null + grep hello actual ' 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 >/dev/null + grep hello actual ' 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 >/dev/null + grep hello actual ' test_expect_success 'cover letter with nothing' ' @@ -1636,7 +1651,8 @@ test_expect_success 'format-patch format.outputDirectory option' ' test_config format.outputDirectory patches && rm -fr patches && git format-patch master..side && - test $(git rev-list master..side | wc -l) -eq $(ls patches | wc -l) + git rev-list master..side >list && + test_line_count = $(ls patches | wc -l) list ' test_expect_success 'format-patch -o overrides format.outputDirectory' ' @@ -1649,20 +1665,41 @@ 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 | 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 && + + 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.id.raw && + awk "{print \"prerequisite-patch-id:\", \$1}" >expect && + + git show --patch HEAD~1 >patch && + git patch-id --stable patch.id.raw && + awk "{print \"prerequisite-patch-id:\", \$1}" >expect && + + signature >>expect && + test_cmp expect actual1 && + test_cmp expect actual2 && + echo >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 && + echo "base-commit: $(cat commit-id-base)" >>fail && + + git show --patch HEAD~2 >patch && + git patch-id --unstable patch.id.raw && + awk "{print \"prerequisite-patch-id:\", \$1}" >fail && + + git show --patch HEAD~1 >patch && + git patch-id --unstable patch.id.raw && + awk "{print \"prerequisite-patch-id:\", \$1}" >fail && + + signature >>fail && ! test_cmp fail actual1 && ! test_cmp fail actual2 ' @@ -1672,8 +1709,9 @@ 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 && - echo "base-commit: $(git rev-parse HEAD~2)" >expected && - test_cmp expected actual + git rev-parse HEAD~2 >commit-id-base && + echo "base-commit: $(cat commit-id-base)" >expect && + test_cmp expect actual ' test_expect_success 'format-patch --base errors out when base commit is not ancestor of revision list' ' @@ -1699,8 +1737,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)" >expected && - test_cmp expected actual + echo "base-commit: $(cat commit-id-base)" >expect && + test_cmp expect actual ' test_expect_success 'format-patch --base=auto' ' @@ -1711,8 +1749,9 @@ test_expect_success 'format-patch --base=auto' ' test_commit N2 && git format-patch --stdout --base=auto -2 >patch && grep "^base-commit:" patch >actual && - echo "base-commit: $(git rev-parse upstream)" >expected && - test_cmp expected actual + git rev-parse upstream >commit-id-base && + echo "base-commit: $(cat commit-id-base)" >expect && + test_cmp expect actual ' test_expect_success 'format-patch errors out when history involves criss-cross' ' @@ -1748,8 +1787,9 @@ test_expect_success 'format-patch format.useAutoBaseoption' ' git config format.useAutoBase true && git format-patch --stdout -1 >patch && grep "^base-commit:" patch >actual && - echo "base-commit: $(git rev-parse upstream)" >expected && - test_cmp expected actual + git rev-parse upstream >commit-id-base && + echo "base-commit: $(cat commit-id-base)" >expect && + test_cmp expect actual ' test_expect_success 'format-patch --base overrides format.useAutoBase' ' @@ -1757,8 +1797,9 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' ' git config format.useAutoBase true && git format-patch --stdout --base=HEAD~1 -1 >patch && grep "^base-commit:" patch >actual && - echo "base-commit: $(git rev-parse HEAD~1)" >expected && - test_cmp expected 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 --base with --attach' ' From patchwork Mon Aug 19 23:52:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11102361 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BFB9D1399 for ; Mon, 19 Aug 2019 23:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D8DA205F4 for ; Mon, 19 Aug 2019 23:52:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Kvl1hBKU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728841AbfHSXwz (ORCPT ); Mon, 19 Aug 2019 19:52:55 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:40185 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728836AbfHSXww (ORCPT ); Mon, 19 Aug 2019 19:52:52 -0400 Received: by mail-io1-f65.google.com with SMTP id t6so8238182ios.7 for ; Mon, 19 Aug 2019 16:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=4DbMXy2z1gLsyGdOTjULdsDq3aeWkjG0a6Lp3YIfLq8=; b=Kvl1hBKUdqVg0mloyQRJOi6XRFsMy2YPSNUM1pp2Vb02BN2WK5FjGS3iywiuZPRYwH 2dQ1xU2U/OTxd3gZUhqYv2ykSs3qC9VJg6YaOYDdaObF42daQM/ifOBKwfV3C7lTTKFL 4R/T10lttn1d1WumnJ4yhT1alvuDsyKhE+3yn5l4AUmsn3ehreW8b/SxwX1MsxhJTZCt LfYFPuwvzw3R5qBj1SrgCEkQzaMaE/nz/ljDGkfWgB1tmfAmRSY66joaC8tO8U5syckB XVW9slpx3vWe/uBJnzoB9wzS3AWWL9L8arybegaxW2u2T6uVZPjxfOq0w5yrfYKTaQBq aWIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=4DbMXy2z1gLsyGdOTjULdsDq3aeWkjG0a6Lp3YIfLq8=; b=IzXqFhifdVbKpTYQXT3rKClcdJxwaQakDuifK+2R6bvpDKigkfXMaBnqPA8lr/3cGu HnD8894DftnZf84ovDMOHPN3CBDYGCyl/oU8J+5azHy25gmqhPRiSei9x1n6bthiB0cD h/fiHJCySDZAzebtmGZjbxedB7JdIatAa5zCezmY7ycmntmSF3k5D/Puiz0Q6+aKp7Qp dOtf9EVblmwvK1OUvMkaRjf2MZeoNdKfsjBfXjk2lrGKv1iZAeDSkf+cUjsvB5HaiW4g JQcGo7lxVvY4qIpYGArNnACr6b5DU+ci0Ef5rv+6mXMwYWM8rUZGgW6rxKkKkRYGAP6S X4Aw== X-Gm-Message-State: APjAAAW8wZNrRgkOgKTxiJUluDi4N7f8/n4kJe+GIe5CporpIdZ2oKe8 GWPKIz5C6F5EjovFlByhDyiXpyNA X-Google-Smtp-Source: APXvYqzuMzNm45oLXoKcGefggu4zLcDw1d4bALqF7BqevnA7ZW0Tw1WdkAqVdrZ3M1hMlf1O7kPm/g== X-Received: by 2002:a5e:d70a:: with SMTP id v10mr7825706iom.19.1566258770791; Mon, 19 Aug 2019 16:52:50 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.89.95]) by smtp.gmail.com with ESMTPSA id n21sm9804863iom.69.2019.08.19.16.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 16:52:50 -0700 (PDT) Date: Mon, 19 Aug 2019 19:52:48 -0400 From: Denton Liu To: Git Mailing List Cc: =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Junio C Hamano , Eric Sunshine Subject: [PATCH v2 2/4] Doc: add more detail for git-format-patch Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In git-format-patch.txt, we were missing some key user information. First of all, using the `--to` and `--cc` options don't override `format.to` and `format.cc` variables, respectively. They add on to each other. Document this. In addition, document the special value of `--base=auto`. Next, while we're at it, surround option arguments with <>. Finally, document the `format.outputDirectory` config and change `format.coverletter` to use camel case. Signed-off-by: Denton Liu --- Documentation/git-format-patch.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index b9b97e63ae..95bc4d53ca 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -17,9 +17,9 @@ SYNOPSIS [--signature-file=] [-n | --numbered | -N | --no-numbered] [--start-number ] [--numbered-files] - [--in-reply-to=Message-Id] [--suffix=.] + [--in-reply-to=] [--suffix=.] [--ignore-if-in-upstream] - [--rfc] [--subject-prefix=Subject-Prefix] + [--rfc] [--subject-prefix=] [(--reroll-count|-v) ] [--to=] [--cc=] [--[no-]cover-letter] [--quiet] @@ -159,7 +159,7 @@ Beware that the default for 'git send-email' is to thread emails itself. If you want `git format-patch` to take care of threading, you will want to ensure that threading is disabled for `git send-email`. ---in-reply-to=Message-Id:: +--in-reply-to=:: Make the first mail (or all the mails with `--no-thread`) appear as a reply to the given Message-Id, which avoids breaking threads to provide a new patch series. @@ -314,7 +314,8 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`. --base=:: Record the base tree information to identify the state the patch series applies to. See the BASE TREE INFORMATION section - below for details. + below for details. If is "auto", a base commit is + automatically chosen. --root:: Treat the revision argument as a , even if it @@ -330,8 +331,9 @@ CONFIGURATION ------------- You can specify extra mail header lines to be added to each message, defaults for the subject prefix and file suffix, number patches when -outputting more than one patch, add "To" or "Cc:" headers, configure -attachments, and sign off patches with configuration variables. +outputting more than one patch, add "To:" or "Cc:" headers, configure +attachments, change the patch output directory, and sign off patches +with configuration variables. ------------ [format] @@ -343,7 +345,8 @@ attachments, and sign off patches with configuration variables. cc = attach [ = mime-boundary-string ] signOff = true - coverletter = auto + outputDirectory = + coverLetter = auto ------------ From patchwork Mon Aug 19 23:52:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11102363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A88D14DB for ; Mon, 19 Aug 2019 23:52:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7901A206C1 for ; Mon, 19 Aug 2019 23:52:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fqQEq1Hg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728849AbfHSXwz (ORCPT ); Mon, 19 Aug 2019 19:52:55 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:39626 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728761AbfHSXwy (ORCPT ); Mon, 19 Aug 2019 19:52:54 -0400 Received: by mail-io1-f65.google.com with SMTP id l7so7511650ioj.6 for ; Mon, 19 Aug 2019 16:52:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RmbJmGwcbrez7IYtDTPKJWe+HKlSRxeFuEJIgp3F9xs=; b=fqQEq1HgRnAM+R98utmKkC+Hxz3PQlMaY121o7trgyRsyMspC4ZM29KmnJTj+C0XV/ sPq9lm4iqUBRsg+XkSm1QN8iLQneZFU9zqP2dP1iQ7EjMnycxHJUn6x2NL7nQBvSctre PM1vRjys0HYWFehAjyDjCHy61A2RcfUivErR0BJZOFeLvFcnFBDxUoVG/RbWyyskUe9f FLQ0+A+KsfG6PMOZny/gmF+BGC20g35G7Yu6F6STAav3fJRzAF/T+Mwxskow80nFDF02 lWf8DNPR/W4VZaXLrm41LtKuH+ImEhNmgmTyMU8QBtlLnSkTwzoW51z0QPve4+nomp7d Pv4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=RmbJmGwcbrez7IYtDTPKJWe+HKlSRxeFuEJIgp3F9xs=; b=rua9VBq4B0I0woKajd0hCbZkRGUBUJzTm/4jO2y2KWiHgkN/M4Iv0836AWNI0/PvIB S5rrtL2noomlPgcOrEDKMUDqIryotwUH0SJaQ3z0gjQRbcMTWeXUn7xWIbT4st8q+G0f KHcFUdpely652CYRkPr6qeYtyA9uSl5Di3TswQIvIHgjWzOHHrEle26/6TIoCat8hYOI iXTfK2A8KphQDsYjsIpn7CiEPb3VeaSmgdMR//4Lk4h8kNsG8TD9lgL87/bIuAAI4O13 Zqzj/Fcee/lFM7y//qrA+2bsTWPoECR6nrAIbIYTvP/xrc2rlAQTctwe/CBZEMzuL+nF 9ybw== X-Gm-Message-State: APjAAAXFBmer6fAJ17QDJDaaMkpWsu6wl6OsEhR9td0C7tBqSouNVKKK y8ZmnPmDXhybtjLdzinl55iRR5p1 X-Google-Smtp-Source: APXvYqwDwCgU98MCAi9DQL7qMpjs08QXgAsVeEkGIZVzgk06aGsEgTbv1lxui+H4T6/uHAZq8Ts5PA== X-Received: by 2002:a05:6638:35a:: with SMTP id x26mr538022jap.104.1566258773199; Mon, 19 Aug 2019 16:52:53 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.89.95]) by smtp.gmail.com with ESMTPSA id o3sm15427739ioo.74.2019.08.19.16.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 16:52:52 -0700 (PDT) Date: Mon, 19 Aug 2019 19:52:51 -0400 From: Denton Liu To: Git Mailing List Cc: =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Junio C Hamano , Eric Sunshine Subject: [PATCH v2 3/4] config/format.txt: make clear the default value of format.coverLetter Message-ID: <94a778c9aa561c8cbe5ef39e21695db3124611b4.1566258525.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Denton Liu --- Documentation/config/format.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt index 414a5a8a9d..60e4e92885 100644 --- a/Documentation/config/format.txt +++ b/Documentation/config/format.txt @@ -74,7 +74,8 @@ format.signOff:: Please see the 'SubmittingPatches' document for further discussion. format.coverLetter:: - A boolean that controls whether to generate a cover-letter when + A boolean which lets you enable the `--cover-letter` option by + default when format-patch is invoked, but in addition can be set to "auto", to generate a cover-letter only when there's more than one patch. From patchwork Mon Aug 19 23:52:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11102365 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D71FA1399 for ; Mon, 19 Aug 2019 23:52:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6757206C1 for ; Mon, 19 Aug 2019 23:52:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U+SD03pV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728615AbfHSXw6 (ORCPT ); Mon, 19 Aug 2019 19:52:58 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:46202 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728761AbfHSXw5 (ORCPT ); Mon, 19 Aug 2019 19:52:57 -0400 Received: by mail-io1-f65.google.com with SMTP id x4so8205913iog.13 for ; Mon, 19 Aug 2019 16:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wXe4/5Hz+B97xPxxhwNgMq0jGCYBKTyjj+Ol+4az0nE=; b=U+SD03pVjEgve6KHrIlH0Ny+NvkR+BAmDNsM/uF8ZWcIbIOGXejpQysQM5hpWDGOam k+e5qizPv+cA0zov81Q4HzxhtBxcGhdhYkZDGbhvgM6XjhPd1UJhP1cCRV+LTfX/Jrjq VK2raXUHkCAKAvrsGnkJB3HW+4IYrhxEE8BRrU4t/GqKX0mmIiMF94V2ydqvhvoTPf8l 0MzeuMqBON7nAUoW+ogYajVns+PWk1kyjeM/FCWibmVBOOPCUTkD4ExkOl1/pNOjoOvR SLYkHOtct1nhMiMP1DcCpXwrDqJGXwSnLn+/tuvTSUpICWrzfwTxJVk0WfdhKbIP0tPt mgtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wXe4/5Hz+B97xPxxhwNgMq0jGCYBKTyjj+Ol+4az0nE=; b=si45MAlz5otyU2jxbUTy8BA919CmlrnTwCZwEcj7GC6oO9hvjR8am97+QwNXjLJEkv wNc4MLTAom1BgkqSvvPQhRqFscZIHKi5d84bdZvU4LuxzQbuq87X4+5xZ5X99wGu8W2r 2/WGUnrx1T8nmzF3P9VzttvPCx66H+fyiLceI/mAFHb/lGmcQ86uycrQIpV7Rb/QxNAI G3moGmeQGPtdXwWj3vSAhXAwiTuZ5IPLGhCKEqdk7Q+7zU+VuhvkOmCskgKhJEjJGSIl scOlSWLeCfzYt+ogh9eCgKHWVPwdm74E4tgIVN3aCiUnfydLY0diWXFM9fYMzMm+ANFU skeg== X-Gm-Message-State: APjAAAU8GxDowyasGVj88tek43XEqQa0gtCnbYcXPAQUOKsofS7UQ1aG 1cbkGWSq555qNo/6KH72LBfdDEoO X-Google-Smtp-Source: APXvYqxFoeq8+xqi5l+GBj148JyvtWtSjP+BV9dbK8WzHF/CpVa/EtD1jHyniWt9GFwabF2vZPqRFQ== X-Received: by 2002:a02:cb51:: with SMTP id k17mr542097jap.4.1566258775607; Mon, 19 Aug 2019 16:52:55 -0700 (PDT) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.89.95]) by smtp.gmail.com with ESMTPSA id 6sm16154828iog.40.2019.08.19.16.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 16:52:55 -0700 (PDT) Date: Mon, 19 Aug 2019 19:52:53 -0400 From: Denton Liu To: Git Mailing List Cc: =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Junio C Hamano , Eric Sunshine Subject: [PATCH v2 4/4] format-patch: learn --infer-cover-letter option Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We used to populate the subject of the cover letter generated by git-format-patch with "*** SUBJECT HERE ***". However, if a user submits multiple patchsets, they may want to keep a consistent subject between rerolls. If git-format-patch is run with `--infer-cover-letter` or `format.inferCoverSubject`, infer the subject for the cover letter from the top line(s) of a branch description, similar to how a subject is read from a commit message. Signed-off-by: Denton Liu --- Documentation/config/format.txt | 4 +++ Documentation/git-format-patch.txt | 10 ++++++ builtin/log.c | 56 +++++++++++++++++++----------- t/t4014-format-patch.sh | 33 ++++++++++++++++++ 4 files changed, 82 insertions(+), 21 deletions(-) diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt index 60e4e92885..9cd6a64e3e 100644 --- a/Documentation/config/format.txt +++ b/Documentation/config/format.txt @@ -36,6 +36,10 @@ format.subjectPrefix:: The default for format-patch is to output files with the '[PATCH]' subject prefix. Use this variable to change that prefix. +format.inferCoverSubject:: + A boolean value which lets you enable the + `--infer-cover-subject` option of format-patch by default. + format.signature:: The default for format-patch is to output a signature containing the Git version number. Use this variable to change that default. diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 95bc4d53ca..00ccfb51e7 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -19,6 +19,7 @@ SYNOPSIS [--start-number ] [--numbered-files] [--in-reply-to=] [--suffix=.] [--ignore-if-in-upstream] + [--[no-]infer-cover-subject] [--rfc] [--subject-prefix=] [(--reroll-count|-v) ] [--to=] [--cc=] @@ -171,6 +172,14 @@ will want to ensure that threading is disabled for `git send-email`. patches being generated, and any patch that matches is ignored. +--[no-]infer-cover-subject:: + Instead of using the default "*** SUBJECT HERE ***" subject for + the cover letter, infer the subject from the branch's + description. ++ +Similar to a commit message, the subject is inferred as the beginning of +the description up to and excluding the first blank line. + --subject-prefix=:: Instead of the standard '[PATCH]' prefix in the subject line, instead use '[]'. This @@ -347,6 +356,7 @@ with configuration variables. signOff = true outputDirectory = coverLetter = auto + inferCoverSubject = true ------------ diff --git a/builtin/log.c b/builtin/log.c index 44b10b3415..b15754e282 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -774,6 +774,7 @@ static const char *signature = git_version_string; static const char *signature_file; static int config_cover_letter; static const char *config_output_directory; +static int infer_cover_subject; enum { COVER_UNSET, @@ -887,6 +888,10 @@ static int git_format_config(const char *var, const char *value, void *cb) } return 0; } + if (!strcmp(var, "format.infercoversubject")) { + infer_cover_subject = git_config_bool(var, value); + return 0; + } return git_log_config(var, value, cb); } @@ -993,20 +998,6 @@ static void print_signature(FILE *file) putc('\n', file); } -static void add_branch_description(struct strbuf *buf, const char *branch_name) -{ - struct strbuf desc = STRBUF_INIT; - if (!branch_name || !*branch_name) - return; - read_branch_desc(&desc, branch_name); - if (desc.len) { - strbuf_addch(buf, '\n'); - strbuf_addbuf(buf, &desc); - strbuf_addch(buf, '\n'); - } - strbuf_release(&desc); -} - static char *find_branch_name(struct rev_info *rev) { int i, positive = -1; @@ -1057,13 +1048,17 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, struct commit *origin, int nr, struct commit **list, const char *branch_name, + int infer_subject, int quiet) { const char *committer; - const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n"; - const char *msg; + const char *subject = "*** SUBJECT HERE ***"; + const char *body = "*** BLURB HERE ***"; + const char *description = NULL; struct shortlog log; struct strbuf sb = STRBUF_INIT; + struct strbuf description_sb = STRBUF_INIT; + struct strbuf subject_sb = STRBUF_INIT; int i; const char *encoding = "UTF-8"; int need_8bit_cte = 0; @@ -1091,17 +1086,34 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, if (!branch_name) branch_name = find_branch_name(rev); - msg = body; + if (branch_name && *branch_name) + read_branch_desc(&description_sb, branch_name); + + if (description_sb.len) { + if (infer_subject) { + description = format_subject(&subject_sb, description_sb.buf, " "); + subject = subject_sb.buf; + } else { + description = description_sb.buf; + } + } + pp.fmt = CMIT_FMT_EMAIL; pp.date_mode.type = DATE_RFC2822; pp.rev = rev; pp.print_email_subject = 1; pp_user_info(&pp, NULL, &sb, committer, encoding); - pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte); - pp_remainder(&pp, &msg, &sb, 0); - add_branch_description(&sb, branch_name); + pp_title_line(&pp, &subject, &sb, encoding, need_8bit_cte); + pp_remainder(&pp, &body, &sb, 0); + if (description) { + strbuf_addch(&sb, '\n'); + strbuf_addstr(&sb, description); + strbuf_addch(&sb, '\n'); + } fprintf(rev->diffopt.file, "%s\n", sb.buf); + strbuf_release(&description_sb); + strbuf_release(&subject_sb); strbuf_release(&sb); shortlog_init(&log); @@ -1577,6 +1589,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) { OPTION_CALLBACK, 0, "rfc", &rev, NULL, N_("Use [RFC PATCH] instead of [PATCH]"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, rfc_callback }, + OPT_BOOL(0, "infer-cover-subject", &infer_cover_subject, + N_("infer a cover letter subject from the branch description")), { OPTION_CALLBACK, 0, "subject-prefix", &rev, N_("prefix"), N_("Use [] instead of [PATCH]"), PARSE_OPT_NONEG, subject_prefix_callback }, @@ -1916,7 +1930,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (thread) gen_message_id(&rev, "cover"); make_cover_letter(&rev, use_stdout, - origin, nr, list, branch_name, quiet); + origin, nr, list, branch_name, infer_cover_subject, quiet); print_bases(&bases, rev.diffopt.file); print_signature(rev.diffopt.file); total++; diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 0114608b1f..ad920bb063 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1558,6 +1558,39 @@ test_expect_success 'format patch ignores color.ui' ' test_cmp expect actual ' +test_expect_success 'cover letter with config subject' ' + test_config branch.rebuild-1.description "config subject + +body" && + test_config format.inferCoverSubject true && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter master >actual && + grep "^Subject: \[PATCH 0/2\] config subject$" actual && + grep "^body" actual +' + +test_expect_success 'cover letter with command-line subject' ' + test_config branch.rebuild-1.description "command-line subject + +body" && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter --infer-cover-subject master >actual && + grep "^Subject: \[PATCH 0/2\] command-line subject$" actual && + grep "^body" actual +' + +test_expect_success 'cover letter with command-line --no-infer-cover-subject overrides config' ' + test_config branch.rebuild-1.description "config subject + +body" && + test_config format.inferCoverSubject true && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter --no-infer-cover-subject master >actual && + grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT 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 &&