]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: add "--signature-file=<file>" option
authorJeremiah Mahler <jmmahler@gmail.com>
Sat, 24 May 2014 04:08:14 +0000 (21:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 May 2014 19:38:32 +0000 (12:38 -0700)
Add an option to format-patch for reading a signature from a file.

  $ git format-patch -1 --signature-file=$HOME/.signature

The config variable `format.signaturefile` can also be used to make
this the default.

  $ git config format.signaturefile $HOME/.signature

  $ git format-patch -1

Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
Documentation/git-format-patch.txt
builtin/log.c
t/t4014-format-patch.sh

index 1932e9b9a2be5437dd467f91472318a5bf1bb992..140ed771efc1e664262809d804ea7b9100cd049c 100644 (file)
@@ -1114,6 +1114,10 @@ format.signature::
        Set this variable to the empty string ("") to suppress
        signature generation.
 
+format.signaturefile::
+       Works just like format.signature except the contents of the
+       file specified by this variable will be used as the signature.
+
 format.suffix::
        The default for format-patch is to output files with the suffix
        `.patch`. Use this variable to change that suffix (make sure to
index 5c0a4ab2d6d4c123899fa32e8f147a8c077f2130..c0fd470da42991404c722f45ee7ac48cd774287b 100644 (file)
@@ -14,6 +14,7 @@ SYNOPSIS
                   [(--attach|--inline)[=<boundary>] | --no-attach]
                   [-s | --signoff]
                   [--signature=<signature> | --no-signature]
+                  [--signature-file=<file>]
                   [-n | --numbered | -N | --no-numbered]
                   [--start-number <n>] [--numbered-files]
                   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
@@ -233,6 +234,9 @@ configuration options in linkgit:git-notes[1] to use this workflow).
        signature option is omitted the signature defaults to the Git version
        number.
 
+--signature-file=<file>::
+       Works just like --signature except the signature is read from a file.
+
 --suffix=.<sfx>::
        Instead of using `.patch` as the suffix for generated
        filenames, use specified suffix.  A common alternative is
index 5acc0481e2f4c2096da02502c3026786a0460c34..e6dcd19278abacadc748ed5b05b0e6c8296280bc 100644 (file)
@@ -673,6 +673,7 @@ static void add_header(const char *value)
 static int thread;
 static int do_signoff;
 static const char *signature = git_version_string;
+static const char *signature_file;
 static int config_cover_letter;
 
 enum {
@@ -742,6 +743,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
        }
        if (!strcmp(var, "format.signature"))
                return git_config_string(&signature, var, value);
+       if (!strcmp(var, "format.signaturefile"))
+               return git_config_pathname(&signature_file, var, value);
        if (!strcmp(var, "format.coverletter")) {
                if (value && !strcasecmp(value, "auto")) {
                        config_cover_letter = COVER_AUTO;
@@ -1235,6 +1238,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                            PARSE_OPT_OPTARG, thread_callback },
                OPT_STRING(0, "signature", &signature, N_("signature"),
                            N_("add a signature")),
+               OPT_FILENAME(0, "signature-file", &signature_file,
+                               N_("add a signature from a file")),
                OPT__QUIET(&quiet, N_("don't print the patch filenames")),
                OPT_END()
        };
@@ -1452,6 +1457,18 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                        cover_letter = (config_cover_letter == COVER_ON);
        }
 
+       if (!signature) {
+               ; /* --no-signature inhibits all signatures */
+       } else if (signature && signature != git_version_string) {
+               ; /* non-default signature already set */
+       } else if (signature_file) {
+               struct strbuf buf = STRBUF_INIT;
+
+               if (strbuf_read_file(&buf, signature_file, 128) < 0)
+                       die_errno(_("unable to read signature file '%s'"), signature_file);
+               signature = strbuf_detach(&buf, NULL);
+       }
+
        if (in_reply_to || thread || cover_letter)
                rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
        if (in_reply_to) {
index 9c8063314688ec0c03d3fb2099379cbbf4ff2e19..ae25353a14234b2f7471bfdcafb0a0cd4bbec909 100755 (executable)
@@ -762,6 +762,67 @@ 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 &&
        test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all &&