@matheusbsbs / matheus-bagliano / commits / 6622d9c710
Fork 0

format-patch: Add a signature option (--signature)

By default, git uses the version string as the signature for all patches output by format-patch. Many employers (mine included) require the use of a signature on all outgoing mails. In a format-patch | send-email workflow there isn't an easy way to modify the signature without breaking the pipe and manually replacing the version string with the signature required. Instead of doing all that work, add an option (--signature) and a config variable (format.signature) to replace the default git version signature when formatting patches. This does modify the original behavior of format-patch a bit. First off the version string is now placed in the cover letter by default. Secondly, once the configuration variable format.signature is added to the .config file there is no way to revert back to the default git version signature. Instead, specifying the --no-signature option will remove the signature from the patches entirely. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen Boyd committed Jun 15, 2010 at 22:59 UTC 6622d9c7103525bb8673f93df4104ab2a46cb174
5 files changed +83 -3
Documentation/config.txt
+6
@@ -880,6 +880,12 @@ format.subjectprefix::
880 The default for format-patch is to output files with the '[PATCH]'
881 subject prefix. Use this variable to change that prefix.
882
883 +format.signature::
884 + The default for format-patch is to output a signature containing
885 + the git version number. Use this variable to change that default.
886 + Set this variable to the empty string ("") to suppress
887 + signature generation.
888 +
889 format.suffix::
890 The default for format-patch is to output files with the suffix
891 `.patch`. Use this variable to change that suffix (make sure to
Documentation/git-format-patch.txt
+7
@@ -13,6 +13,7 @@ SYNOPSIS
13 [--no-thread | --thread[=<style>]]
14 [(--attach|--inline)[=<boundary>] | --no-attach]
15 [-s | --signoff]
16 + [--signature=<signature> | --no-signature]
17 [-n | --numbered | -N | --no-numbered]
18 [--start-number <n>] [--numbered-files]
19 [--in-reply-to=Message-Id] [--suffix=.<sfx>]
@@ -180,6 +181,12 @@ will want to ensure that threading is disabled for `git send-email`.
181 containing the shortlog and the overall diffstat. You can
182 fill in a description in the file before sending it out.
183
184 +--[no]-signature=<signature>::
185 + Add a signature to each message produced. Per RFC 3676 the signature
186 + is separated from the body by a line with '-- ' on it. If the
187 + signature option is omitted the signature defaults to the git version
188 + number.
189 +
190 --suffix=.<sfx>::
191 Instead of using `.patch` as the suffix for generated
192 filenames, use specified suffix. A common alternative is
builtin/log.c
+15 -3
@@ -549,8 +549,9 @@ static void add_header(const char *value)
549
550 #define THREAD_SHALLOW 1
551 #define THREAD_DEEP 2
552 -static int thread = 0;
553 -static int do_signoff = 0;
552 +static int thread;
553 +static int do_signoff;
554 +static const char *signature = git_version_string;
555
556 static int git_format_config(const char *var, const char *value, void *cb)
557 {
@@ -609,6 +610,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
610 do_signoff = git_config_bool(var, value);
611 return 0;
612 }
613 + if (!strcmp(var, "format.signature"))
614 + return git_config_string(&signature, var, value);
615
616 return git_log_config(var, value, cb);
617 }
@@ -703,6 +706,12 @@ static void gen_message_id(struct rev_info *info, char *base)
706 info->message_id = strbuf_detach(&buf, NULL);
707 }
708
709 +static void print_signature(void)
710 +{
711 + if (signature && *signature)
712 + printf("-- \n%s\n\n", signature);
713 +}
714 +
715 static void make_cover_letter(struct rev_info *rev, int use_stdout,
716 int numbered, int numbered_files,
717 struct commit *origin,
@@ -796,6 +805,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
805 diff_flush(&opts);
806
807 printf("\n");
808 + print_signature();
809 }
810
811 static const char *clean_message_id(const char *msg_id)
@@ -1035,6 +1045,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1045 { OPTION_CALLBACK, 0, "thread", &thread, "style",
1046 "enable message threading, styles: shallow, deep",
1047 PARSE_OPT_OPTARG, thread_callback },
1048 + OPT_STRING(0, "signature", &signature, "signature",
1049 + "add a signature"),
1050 OPT_END()
1051 };
1052
@@ -1313,7 +1325,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1325 mime_boundary_leader,
1326 rev.mime_boundary);
1327 else
1316 - printf("-- \n%s\n\n", git_version_string);
1328 + print_signature();
1329 }
1330 if (!use_stdout)
1331 fclose(stdout);
t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^
+3
@@ -18,6 +18,9 @@ A U Thor (2):
18 create mode 100644 file1
19 delete mode 100644 file2
20
21 +--
22 +g-i-t--v-e-r-s-i-o-n
23 +
24 From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
25 From: A U Thor <author@example.com>
26 Date: Mon, 26 Jun 2006 00:01:00 +0000
t/t4014-format-patch.sh
+52
@@ -613,4 +613,56 @@ test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
613 git format-patch --ignore-if-in-upstream HEAD
614 '
615
616 +test_expect_success 'format-patch --signature' '
617 + git format-patch --stdout --signature="my sig" -1 >output &&
618 + grep "my sig" output
619 +'
620 +
621 +test_expect_success 'format-patch with format.signature config' '
622 + git config format.signature "config sig" &&
623 + git format-patch --stdout -1 >output &&
624 + grep "config sig" output
625 +'
626 +
627 +test_expect_success 'format-patch --signature overrides format.signature' '
628 + git config format.signature "config sig" &&
629 + git format-patch --stdout --signature="overrides" -1 >output &&
630 + ! grep "config sig" output &&
631 + grep "overrides" output
632 +'
633 +
634 +test_expect_success 'format-patch --no-signature ignores format.signature' '
635 + git config format.signature "config sig" &&
636 + git format-patch --stdout --signature="my sig" --no-signature \
637 + -1 >output &&
638 + ! grep "config sig" output &&
639 + ! grep "my sig" output &&
640 + ! grep "^-- \$" output
641 +'
642 +
643 +test_expect_success 'format-patch --signature --cover-letter' '
644 + git config --unset-all format.signature &&
645 + git format-patch --stdout --signature="my sig" --cover-letter \
646 + -1 >output &&
647 + grep "my sig" output &&
648 + test 2 = $(grep "my sig" output | wc -l)
649 +'
650 +
651 +test_expect_success 'format.signature="" supresses signatures' '
652 + git config format.signature "" &&
653 + git format-patch --stdout -1 >output &&
654 + ! grep "^-- \$" output
655 +'
656 +
657 +test_expect_success 'format-patch --no-signature supresses signatures' '
658 + git config --unset-all format.signature &&
659 + git format-patch --stdout --no-signature -1 >output &&
660 + ! grep "^-- \$" output
661 +'
662 +
663 +test_expect_success 'format-patch --signature="" supresses signatures' '
664 + git format-patch --signature="" -1 >output &&
665 + ! grep "^-- \$" output
666 +'
667 +
668 test_done