Skip to content

Commit 71d6f42

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 83d9db7 commit 71d6f42

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

Documentation/config/format.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,16 @@ format.outputDirectory::
8585
format.useAutoBase::
8686
A boolean value which lets you enable the `--base=auto` option of
8787
format-patch by default.
88+
89+
format.notes::
90+
A ref which specifies where to get the notes (see
91+
linkgit:git-notes[1]) that are appended for the commit after the
92+
three-dash line.
93+
+
94+
If the special value of "standard" is specified, then the standard notes
95+
ref is used (i.e. the notes ref used by `git notes` when no `--ref`
96+
argument is specified). If one wishes to use the ref
97+
`ref/notes/standard`, please use that literal instead.
98+
+
99+
This configuration can be specified multiple times in order to allow
100+
multiple notes refs to be included.

Documentation/git-format-patch.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ these explanations after `format-patch` has run but before sending,
275275
keeping them as Git notes allows them to be maintained between versions
276276
of the patch series (but see the discussion of the `notes.rewrite`
277277
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.
278281

279282
--[no-]signature=<signature>::
280283
Add a signature to each message produced. Per RFC 3676 the signature

builtin/log.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,8 @@ enum {
779779

780780
static int git_format_config(const char *var, const char *value, void *cb)
781781
{
782+
struct rev_info *rev = cb;
783+
782784
if (!strcmp(var, "format.headers")) {
783785
if (!value)
784786
die(_("format.headers without value"));
@@ -864,6 +866,20 @@ static int git_format_config(const char *var, const char *value, void *cb)
864866
from = NULL;
865867
return 0;
866868
}
869+
if (!strcmp(var, "format.notes")) {
870+
struct strbuf buf = STRBUF_INIT;
871+
872+
rev->show_notes = 1;
873+
if (!strcmp(value, "standard")) {
874+
rev->notes_opt.use_default_notes = 1;
875+
} else {
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+
}
881+
return 0;
882+
}
867883

868884
return git_log_config(var, value, cb);
869885
}
@@ -1617,8 +1633,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
16171633
extra_to.strdup_strings = 1;
16181634
extra_cc.strdup_strings = 1;
16191635
init_log_defaults();
1620-
git_config(git_format_config, NULL);
16211636
repo_init_revisions(the_repository, &rev, prefix);
1637+
git_config(git_format_config, &rev);
16221638
rev.commit_format = CMIT_FMT_EMAIL;
16231639
rev.expand_tabs_in_log_default = 0;
16241640
rev.verbose_header = 1;

t/t4014-format-patch.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,76 @@ test_expect_success 'format-patch --notes --signoff' '
738738
sed "1,/^---$/d" out | grep "test message"
739739
'
740740

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 standard &&
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+
741811
echo "fatal: --name-only does not make sense" > expect.name-only
742812
echo "fatal: --name-status does not make sense" > expect.name-status
743813
echo "fatal: --check does not make sense" > expect.check

0 commit comments

Comments
 (0)