Skip to content

Commit e91f65d

Browse files
committed
Merge branch 'dl/format-patch-notes-config'
"git format-patch" learns a configuration to set the default for its --notes=<ref> option. * dl/format-patch-notes-config: format-patch: teach format.notes config option git-format-patch.txt: document --no-notes option
2 parents c4a38d1 + 13cdf78 commit e91f65d

File tree

4 files changed

+110
-2
lines changed

4 files changed

+110
-2
lines changed

Documentation/config/format.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,18 @@ 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+
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

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: 19 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,22 @@ 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+
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+
}
867885

868886
return git_log_config(var, value, cb);
869887
}
@@ -1617,8 +1635,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
16171635
extra_to.strdup_strings = 1;
16181636
extra_cc.strdup_strings = 1;
16191637
init_log_defaults();
1620-
git_config(git_format_config, NULL);
16211638
repo_init_revisions(the_repository, &rev, prefix);
1639+
git_config(git_format_config, &rev);
16221640
rev.commit_format = CMIT_FMT_EMAIL;
16231641
rev.expand_tabs_in_log_default = 0;
16241642
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 true &&
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)