{"thread":{"id":"36688","subject":"[PATCH v4] format-patch --signature-file <file>","startedAt":"2014-05-18T20:22:01Z","lastAt":"2014-05-19T10:48:11Z","messageCount":3,"participants":["Jeremiah Mahler","Jeff King"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"242088","messageId":"1400444522-15523-1-git-send-email-jmmahler@gmail.com","threadId":"36688","inReplyTo":null,"subject":"[PATCH v4] format-patch --signature-file <file>","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-18T20:22:01Z","receivedAt":"2014-05-18T20:22:01Z","isPatch":true,"sender":{"key":"jmmahler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/154028?v=4"},"body":"v4 of patch to add format-patch --signature-file <file> option.\n\nThis revision includes more suggestions from Jeff King:\n\n  - Added a format.signaturefile config option.\n\n  - Fixed error messages, --signature and format.signature\n\n  - Fixed error checking, dies if strbuf_read_file fails.\n\n  - style: \"cat > expect << EOF\" to \"cat >expect <<-\\EOF\"\n\n  - Eliminated use of fgrep, which is not used anywhere else\n\tin the project.  Possibility of portability problems.\n    Replaced with sed which is commonly used.\n\n  - Eliminated use of diff in favor of test_cmp.\n\n  - Removed redundant test, \"--foo=bar\" and \"--foo bar\"\n\n  - Changed to use test_must_fail instead of \"!\"\n\nJeremiah Mahler (1):\n  format-patch --signature-file <file>\n\n Documentation/config.txt           |  4 ++++\n Documentation/git-format-patch.txt |  4 ++++\n builtin/log.c                      | 16 ++++++++++++++++\n t/t4014-format-patch.sh            | 33 +++++++++++++++++++++++++++++++++\n 4 files changed, 57 insertions(+)\n\n-- \nJeremiah Mahler\njmmahler@gmail.com\nhttp://github.com/jmahler\n"},{"id":"242089","messageId":"1400444522-15523-2-git-send-email-jmmahler@gmail.com","threadId":"36688","inReplyTo":"1400444522-15523-1-git-send-email-jmmahler@gmail.com","subject":"[PATCH v4] format-patch --signature-file <file>","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-18T20:22:02Z","receivedAt":"2014-05-18T20:22:02Z","isPatch":true,"sender":{"key":"jmmahler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/154028?v=4"},"body":"Added option that allows a signature file to be used with format-patch\nso that signatures with newlines and other special characters can be\neasily included.\n\n  $ git format-patch --signature-file ~/.signature -1\n\nThe config variable format.signaturefile is also provided so that it\ncan be added by default.\n\n  $ git config format.signaturefile ~/.signature\n\n  $ git format-patch -1\n\nSigned-off-by: Jeremiah Mahler <jmmahler@gmail.com>\n---\n Documentation/config.txt           |  4 ++++\n Documentation/git-format-patch.txt |  4 ++++\n builtin/log.c                      | 16 ++++++++++++++++\n t/t4014-format-patch.sh            | 33 +++++++++++++++++++++++++++++++++\n 4 files changed, 57 insertions(+)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 1932e9b..140ed77 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1114,6 +1114,10 @@ format.signature::\n \tSet this variable to the empty string (\"\") to suppress\n \tsignature generation.\n \n+format.signaturefile::\n+\tWorks just like format.signature except the contents of the\n+\tfile specified by this variable will be used as the signature.\n+\n format.suffix::\n \tThe default for format-patch is to output files with the suffix\n \t`.patch`. Use this variable to change that suffix (make sure to\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 5c0a4ab..c0fd470 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -14,6 +14,7 @@ SYNOPSIS\n \t\t   [(--attach|--inline)[=<boundary>] | --no-attach]\n \t\t   [-s | --signoff]\n \t\t   [--signature=<signature> | --no-signature]\n+\t\t   [--signature-file=<file>]\n \t\t   [-n | --numbered | -N | --no-numbered]\n \t\t   [--start-number <n>] [--numbered-files]\n \t\t   [--in-reply-to=Message-Id] [--suffix=.<sfx>]\n@@ -233,6 +234,9 @@ configuration options in linkgit:git-notes[1] to use this workflow).\n \tsignature option is omitted the signature defaults to the Git version\n \tnumber.\n \n+--signature-file=<file>::\n+\tWorks just like --signature except the signature is read from a file.\n+\n --suffix=.<sfx>::\n \tInstead of using `.patch` as the suffix for generated\n \tfilenames, use specified suffix.  A common alternative is\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 39e8836..0a8f417 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -673,6 +673,7 @@ static void add_header(const char *value)\n static int thread;\n static int do_signoff;\n static const char *signature = git_version_string;\n+static const char *signature_file;\n static int config_cover_letter;\n \n enum {\n@@ -742,6 +743,8 @@ static int git_format_config(const char *var, const char *value, void *cb)\n \t}\n \tif (!strcmp(var, \"format.signature\"))\n \t\treturn git_config_string(&signature, var, value);\n+\tif (!strcmp(var, \"format.signaturefile\"))\n+\t\treturn git_config_string(&signature_file, var, value);\n \tif (!strcmp(var, \"format.coverletter\")) {\n \t\tif (value && !strcasecmp(value, \"auto\")) {\n \t\t\tconfig_cover_letter = COVER_AUTO;\n@@ -1230,6 +1233,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t    PARSE_OPT_OPTARG, thread_callback },\n \t\tOPT_STRING(0, \"signature\", &signature, N_(\"signature\"),\n \t\t\t    N_(\"add a signature\")),\n+\t\tOPT_FILENAME(0, \"signature-file\", &signature_file,\n+\t\t\t\tN_(\"add a signature from a file\")),\n \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n \t\tOPT_END()\n \t};\n@@ -1447,6 +1452,17 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\tcover_letter = (config_cover_letter == COVER_ON);\n \t}\n \n+\tif (signature_file) {\n+\t\tif (signature && signature != git_version_string)\n+\t\t\tdie(_(\"cannot specify both signature and signature-file\"));\n+\n+\t\tstruct strbuf buf = STRBUF_INIT;\n+\n+\t\tif (strbuf_read_file(&buf, signature_file, 128) < 0)\n+\t\t\tdie_errno(_(\"unable to read signature file '%s'\"), signature_file);\n+\t\tsignature = strbuf_detach(&buf, NULL);\n+\t}\n+\n \tif (in_reply_to || thread || cover_letter)\n \t\trev.ref_message_ids = xcalloc(1, sizeof(struct string_list));\n \tif (in_reply_to) {\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 9c80633..c6d44b8 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -762,6 +762,39 @@ test_expect_success 'format-patch --signature=\"\" suppresses signatures' '\n \t! grep \"^-- \\$\" output\n '\n \n+cat >expect <<-\\EOF\n+\n+Test User <test.email@kernel.org>\n+http://git.kernel.org/cgit/git/git.git\n+\n+git.kernel.org/?p=git/git.git;a=summary\n+\n+EOF\n+\n+test_expect_success 'format-patch --signature-file=file' '\n+\tgit format-patch --stdout --signature-file=expect -1 >output &&\n+\tcheck_patch output &&\n+\tsed -n \"/^-- $/,\\$p\" <output | head --lines=-2 | tail --lines=+2 >output2 &&\n+\ttest_cmp expect output2\n+'\n+\n+test_expect_success 'format-patch --signature and --signature-file die' '\n+\ttest_must_fail git format-patch --stdout --signature=\"foo\" --signature-file=expect -1 >output\n+'\n+\n+test_expect_success 'format-patch --no-signature and --signature-file OK' '\n+\tgit format-patch --stdout --no-signature --signature-file=expect -1\n+'\n+\n+test_expect_success 'format-patch with format.signaturefile config' '\n+\tgit config format.signaturefile expect &&\n+\tgit format-patch --stdout -1 >output &&\n+\tcheck_patch output &&\n+\tsed -n \"/^-- $/,\\$p\" <output | head --lines=-2 | tail --lines=+2 >output2 &&\n+\ttest_cmp expect output2 &&\n+\tgit config --unset-all format.signaturefile\n+'\n+\n test_expect_success TTY 'format-patch --stdout paginates' '\n \trm -f pager_used &&\n \ttest_terminal env GIT_PAGER=\"wc >pager_used\" git format-patch --stdout --all &&\n-- \nJeremiah Mahler\njmmahler@gmail.com\nhttp://github.com/jmahler\n"},{"id":"242155","messageId":"20140519104810.GA17492@sigill.intra.peff.net","threadId":"36688","inReplyTo":"1400444522-15523-2-git-send-email-jmmahler@gmail.com","subject":"Re: [PATCH v4] format-patch --signature-file <file>","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-05-19T10:48:11Z","receivedAt":"2014-05-19T10:48:11Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, May 18, 2014 at 01:22:02PM -0700, Jeremiah Mahler wrote:\n\n> @@ -742,6 +743,8 @@ static int git_format_config(const char *var, const char *value, void *cb)\n>  \t}\n>  \tif (!strcmp(var, \"format.signature\"))\n>  \t\treturn git_config_string(&signature, var, value);\n> +\tif (!strcmp(var, \"format.signaturefile\"))\n> +\t\treturn git_config_string(&signature_file, var, value);\n\nShould this be git_config_pathname? That would handle tilde-expansion.\n\n> +test_expect_success 'format-patch --signature-file=file' '\n> +\tgit format-patch --stdout --signature-file=expect -1 >output &&\n> +\tcheck_patch output &&\n> +\tsed -n \"/^-- $/,\\$p\" <output | head --lines=-2 | tail --lines=+2 >output2 &&\n> +\ttest_cmp expect output2\n> +'\n\nI don't think --lines is portable (it's not even POSIX), nor is a\nnegative value for head (but a \"+\" form for tail is). You can replace\nthe \"head\" call with a \"$d\" sed command, and tail should be fine with\n\"-n +2\". Like:\n\n  sed -n '$d; /^-- $/,$p' | tail -n +2\n\nYou can also do it in one sed like:\n\n  sed -n '$d; /^-- $/,${//!p}'\n\nbut that is starting to look a bit like line-noise. ;)\n\n> +test_expect_success 'format-patch with format.signaturefile config' '\n> +\tgit config format.signaturefile expect &&\n> +\tgit format-patch --stdout -1 >output &&\n> +\tcheck_patch output &&\n> +\tsed -n \"/^-- $/,\\$p\" <output | head --lines=-2 | tail --lines=+2 >output2 &&\n> +\ttest_cmp expect output2 &&\n> +\tgit config --unset-all format.signaturefile\n> +'\n\nYou might want to use \"test_config format.signaturefile expect\" here,\nwhich handles unsetting after the test. Besides being one line shorter,\nit also cleans up when the middle part of the test fails.\n\nYou could also use \"git -c\", but I think setting the actual config in a\nfile is a more realistic test.\n\n-Peff\n"}]}