format-patch: teach format.notes config option

In git-format-patch, notes can be appended with the `--notes` option. However, this must be specified by the user on an invocation-by-invocation basis. If a user is not careful, it's possible that they may forget to include it and generate a patch series without notes. Teach git-format-patch the `format.notes` config option. Its value is a notes ref that will be automatically appended. The special value of "standard" can be used to specify the standard notes. This option is overridable with the `--no-notes` option in case a user wishes not to append notes. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed May 16, 2019 at 19:14 UTC 13cdf78094a5ba2968adb90707d27b98f53db1f7
4 files changed +107 -1
Documentation/config/format.txt
+15
@@ -85,3 +85,18 @@ format.outputDirectory::
85 format.useAutoBase::
86 A boolean value which lets you enable the `--base=auto` option of
87 format-patch by default.
88 +
89 +format.notes::
90 + Provides the default value for the `--notes` option to
91 + format-patch. Accepts a boolean value, or a ref which specifies
92 + where to get notes. If false, format-patch defaults to
93 + `--no-notes`. If true, format-patch defaults to `--notes`. If
94 + set to a non-boolean value, format-patch defaults to
95 + `--notes=<ref>`, where `ref` is the non-boolean value. Defaults
96 + to false.
97 ++
98 +If one wishes to use the ref `ref/notes/true`, please use that literal
99 +instead.
100 ++
101 +This configuration can be specified multiple times in order to allow
102 +multiple notes refs to be included.
Documentation/git-format-patch.txt
+3
@@ -275,6 +275,9 @@ these explanations after `format-patch` has run but before sending,
275 keeping them as Git notes allows them to be maintained between versions
276 of the patch series (but see the discussion of the `notes.rewrite`
277 configuration options in linkgit:git-notes[1] to use this workflow).
278 ++
279 +The default is `--no-notes`, unless the `format.notes` configuration is
280 +set.
281
282 --[no-]signature=<signature>::
283 Add a signature to each message produced. Per RFC 3676 the signature
builtin/log.c
+19 -1
@@ -779,6 +779,8 @@ enum {
779
780 static int git_format_config(const char *var, const char *value, void *cb)
781 {
782 + struct rev_info *rev = cb;
783 +
784 if (!strcmp(var, "format.headers")) {
785 if (!value)
786 die(_("format.headers without value"));
@@ -864,6 +866,22 @@ static int git_format_config(const char *var, const char *value, void *cb)
866 from = NULL;
867 return 0;
868 }
869 + if (!strcmp(var, "format.notes")) {
870 + struct strbuf buf = STRBUF_INIT;
871 + int b = git_parse_maybe_bool(value);
872 + if (!b)
873 + return 0;
874 + rev->show_notes = 1;
875 + if (b < 0) {
876 + strbuf_addstr(&buf, value);
877 + expand_notes_ref(&buf);
878 + string_list_append(&rev->notes_opt.extra_notes_refs,
879 + strbuf_detach(&buf, NULL));
880 + } else {
881 + rev->notes_opt.use_default_notes = 1;
882 + }
883 + return 0;
884 + }
885
886 return git_log_config(var, value, cb);
887 }
@@ -1617,8 +1635,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1635 extra_to.strdup_strings = 1;
1636 extra_cc.strdup_strings = 1;
1637 init_log_defaults();
1620 - git_config(git_format_config, NULL);
1638 repo_init_revisions(the_repository, &rev, prefix);
1639 + git_config(git_format_config, &rev);
1640 rev.commit_format = CMIT_FMT_EMAIL;
1641 rev.expand_tabs_in_log_default = 0;
1642 rev.verbose_header = 1;
t/t4014-format-patch.sh
+70
@@ -738,6 +738,76 @@ test_expect_success 'format-patch --notes --signoff' '
738 sed "1,/^---$/d" out | grep "test message"
739 '
740
741 +test_expect_success 'format-patch notes output control' '
742 + git notes add -m "notes config message" HEAD &&
743 + test_when_finished git notes remove HEAD &&
744 +
745 + git format-patch -1 --stdout >out &&
746 + ! grep "notes config message" out &&
747 + git format-patch -1 --stdout --notes >out &&
748 + grep "notes config message" out &&
749 + git format-patch -1 --stdout --no-notes >out &&
750 + ! grep "notes config message" out &&
751 + git format-patch -1 --stdout --notes --no-notes >out &&
752 + ! grep "notes config message" out &&
753 + git format-patch -1 --stdout --no-notes --notes >out &&
754 + grep "notes config message" out &&
755 +
756 + test_config format.notes true &&
757 + git format-patch -1 --stdout >out &&
758 + grep "notes config message" out &&
759 + git format-patch -1 --stdout --notes >out &&
760 + grep "notes config message" out &&
761 + git format-patch -1 --stdout --no-notes >out &&
762 + ! grep "notes config message" out &&
763 + git format-patch -1 --stdout --notes --no-notes >out &&
764 + ! grep "notes config message" out &&
765 + git format-patch -1 --stdout --no-notes --notes >out &&
766 + grep "notes config message" out
767 +'
768 +
769 +test_expect_success 'format-patch with multiple notes refs' '
770 + git notes --ref note1 add -m "this is note 1" HEAD &&
771 + test_when_finished git notes --ref note1 remove HEAD &&
772 + git notes --ref note2 add -m "this is note 2" HEAD &&
773 + test_when_finished git notes --ref note2 remove HEAD &&
774 +
775 + git format-patch -1 --stdout >out &&
776 + ! grep "this is note 1" out &&
777 + ! grep "this is note 2" out &&
778 + git format-patch -1 --stdout --notes=note1 >out &&
779 + grep "this is note 1" out &&
780 + ! grep "this is note 2" out &&
781 + git format-patch -1 --stdout --notes=note2 >out &&
782 + ! grep "this is note 1" out &&
783 + grep "this is note 2" out &&
784 + git format-patch -1 --stdout --notes=note1 --notes=note2 >out &&
785 + grep "this is note 1" out &&
786 + grep "this is note 2" out &&
787 +
788 + test_config format.notes note1 &&
789 + git format-patch -1 --stdout >out &&
790 + grep "this is note 1" out &&
791 + ! grep "this is note 2" out &&
792 + git format-patch -1 --stdout --no-notes >out &&
793 + ! grep "this is note 1" out &&
794 + ! grep "this is note 2" out &&
795 + git format-patch -1 --stdout --notes=note2 >out &&
796 + grep "this is note 1" out &&
797 + grep "this is note 2" out &&
798 + git format-patch -1 --stdout --no-notes --notes=note2 >out &&
799 + ! grep "this is note 1" out &&
800 + grep "this is note 2" out &&
801 +
802 + git config --add format.notes note2 &&
803 + git format-patch -1 --stdout >out &&
804 + grep "this is note 1" out &&
805 + grep "this is note 2" out &&
806 + git format-patch -1 --stdout --no-notes >out &&
807 + ! grep "this is note 1" out &&
808 + ! grep "this is note 2" out
809 +'
810 +
811 echo "fatal: --name-only does not make sense" > expect.name-only
812 echo "fatal: --name-status does not make sense" > expect.name-status
813 echo "fatal: --check does not make sense" > expect.check