Skip to content

Commit 70abaa9

Browse files
committed
Merge branch 'dl/format-patch-notes-config' into jch
"git format-patch" learns a configuration to set the default for its --notes=<ref> option. The interaction between config and option may be a little iffy. cf. <[email protected]> * dl/format-patch-notes-config: format-patch: teach format.notes config option git-format-patch.txt: document --no-notes option
2 parents 0a5325f + 71d6f42 commit 70abaa9

File tree

4 files changed

+106
-2
lines changed

4 files changed

+106
-2
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ SYNOPSIS
2222
[--rfc] [--subject-prefix=Subject-Prefix]
2323
[(--reroll-count|-v) <n>]
2424
[--to=<email>] [--cc=<email>]
25-
[--[no-]cover-letter] [--quiet] [--notes[=<ref>]]
25+
[--[no-]cover-letter] [--quiet]
26+
[--no-notes | --notes[=<ref>]]
2627
[--interdiff=<previous>]
2728
[--range-diff=<previous> [--creation-factor=<percent>]]
2829
[--progress]
@@ -263,6 +264,7 @@ material (this may change in the future).
263264
for details.
264265

265266
--notes[=<ref>]::
267+
--no-notes::
266268
Append the notes (see linkgit:git-notes[1]) for the commit
267269
after the three-dash line.
268270
+
@@ -273,6 +275,9 @@ these explanations after `format-patch` has run but before sending,
273275
keeping them as Git notes allows them to be maintained between versions
274276
of the patch series (but see the discussion of the `notes.rewrite`
275277
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.
276281

277282
--[no-]signature=<signature>::
278283
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
@@ -757,6 +757,76 @@ test_expect_success 'format-patch --notes --signoff' '
757757
sed "1,/^---$/d" out | grep "test message"
758758
'
759759

760+
test_expect_success 'format-patch notes output control' '
761+
git notes add -m "notes config message" HEAD &&
762+
test_when_finished git notes remove HEAD &&
763+
764+
git format-patch -1 --stdout >out &&
765+
! grep "notes config message" out &&
766+
git format-patch -1 --stdout --notes >out &&
767+
grep "notes config message" out &&
768+
git format-patch -1 --stdout --no-notes >out &&
769+
! grep "notes config message" out &&
770+
git format-patch -1 --stdout --notes --no-notes >out &&
771+
! grep "notes config message" out &&
772+
git format-patch -1 --stdout --no-notes --notes >out &&
773+
grep "notes config message" out &&
774+
775+
test_config format.notes standard &&
776+
git format-patch -1 --stdout >out &&
777+
grep "notes config message" out &&
778+
git format-patch -1 --stdout --notes >out &&
779+
grep "notes config message" out &&
780+
git format-patch -1 --stdout --no-notes >out &&
781+
! grep "notes config message" out &&
782+
git format-patch -1 --stdout --notes --no-notes >out &&
783+
! grep "notes config message" out &&
784+
git format-patch -1 --stdout --no-notes --notes >out &&
785+
grep "notes config message" out
786+
'
787+
788+
test_expect_success 'format-patch with multiple notes refs' '
789+
git notes --ref note1 add -m "this is note 1" HEAD &&
790+
test_when_finished git notes --ref note1 remove HEAD &&
791+
git notes --ref note2 add -m "this is note 2" HEAD &&
792+
test_when_finished git notes --ref note2 remove HEAD &&
793+
794+
git format-patch -1 --stdout >out &&
795+
! grep "this is note 1" out &&
796+
! grep "this is note 2" out &&
797+
git format-patch -1 --stdout --notes=note1 >out &&
798+
grep "this is note 1" out &&
799+
! grep "this is note 2" out &&
800+
git format-patch -1 --stdout --notes=note2 >out &&
801+
! grep "this is note 1" out &&
802+
grep "this is note 2" out &&
803+
git format-patch -1 --stdout --notes=note1 --notes=note2 >out &&
804+
grep "this is note 1" out &&
805+
grep "this is note 2" out &&
806+
807+
test_config format.notes note1 &&
808+
git format-patch -1 --stdout >out &&
809+
grep "this is note 1" out &&
810+
! grep "this is note 2" out &&
811+
git format-patch -1 --stdout --no-notes >out &&
812+
! grep "this is note 1" out &&
813+
! grep "this is note 2" out &&
814+
git format-patch -1 --stdout --notes=note2 >out &&
815+
grep "this is note 1" out &&
816+
grep "this is note 2" out &&
817+
git format-patch -1 --stdout --no-notes --notes=note2 >out &&
818+
! grep "this is note 1" out &&
819+
grep "this is note 2" out &&
820+
821+
git config --add format.notes note2 &&
822+
git format-patch -1 --stdout >out &&
823+
grep "this is note 1" out &&
824+
grep "this is note 2" out &&
825+
git format-patch -1 --stdout --no-notes >out &&
826+
! grep "this is note 1" out &&
827+
! grep "this is note 2" out
828+
'
829+
760830
echo "fatal: --name-only does not make sense" > expect.name-only
761831
echo "fatal: --name-status does not make sense" > expect.name-status
762832
echo "fatal: --check does not make sense" > expect.check

0 commit comments

Comments
 (0)