Skip to content

Commit c426003

Browse files
bebarinogitster
authored andcommitted
format-patch: add --no-cc, --no-to, and --no-add-headers
These new options allow users to override their config settings for format.cc, format.to and format.headers respectively. These options only make git ignore the config settings and any previous command line options, so you'll still have to add more command line options to add extra headers. For example, $ cat .git/config [format] to = Someone <[email protected]> $ git format-patch -1 --no-to --to="Someone Else <[email protected]>" would format a patch addressed to "Someone Else" and not "Someone". Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca9e0a1 commit c426003

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

builtin-log.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,19 +869,31 @@ static int inline_callback(const struct option *opt, const char *arg, int unset)
869869

870870
static int header_callback(const struct option *opt, const char *arg, int unset)
871871
{
872-
add_header(arg);
872+
if (unset) {
873+
string_list_clear(&extra_hdr, 0);
874+
string_list_clear(&extra_to, 0);
875+
string_list_clear(&extra_cc, 0);
876+
} else {
877+
add_header(arg);
878+
}
873879
return 0;
874880
}
875881

876882
static int to_callback(const struct option *opt, const char *arg, int unset)
877883
{
878-
string_list_append(arg, &extra_to);
884+
if (unset)
885+
string_list_clear(&extra_to, 0);
886+
else
887+
string_list_append(arg, &extra_to);
879888
return 0;
880889
}
881890

882891
static int cc_callback(const struct option *opt, const char *arg, int unset)
883892
{
884-
string_list_append(arg, &extra_cc);
893+
if (unset)
894+
string_list_clear(&extra_cc, 0);
895+
else
896+
string_list_append(arg, &extra_cc);
885897
return 0;
886898
}
887899

@@ -940,12 +952,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
940952
PARSE_OPT_NONEG | PARSE_OPT_NOARG },
941953
OPT_GROUP("Messaging"),
942954
{ OPTION_CALLBACK, 0, "add-header", NULL, "header",
943-
"add email header", PARSE_OPT_NONEG,
944-
header_callback },
955+
"add email header", 0, header_callback },
945956
{ OPTION_CALLBACK, 0, "to", NULL, "email", "add To: header",
946-
PARSE_OPT_NONEG, to_callback },
957+
0, to_callback },
947958
{ OPTION_CALLBACK, 0, "cc", NULL, "email", "add Cc: header",
948-
PARSE_OPT_NONEG, cc_callback },
959+
0, cc_callback },
949960
OPT_STRING(0, "in-reply-to", &in_reply_to, "message-id",
950961
"make first mail a reply to <message-id>"),
951962
{ OPTION_CALLBACK, 0, "attach", &rev, "boundary",

t/t4014-format-patch.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,44 @@ test_expect_success 'configuration To: header' '
157157
grep "^To: R. E. Cipient <[email protected]>\$" patch9
158158
'
159159

160+
test_expect_success '--no-to overrides config.to' '
161+
162+
git config --replace-all format.to \
163+
"R. E. Cipient <[email protected]>" &&
164+
git format-patch --no-to --stdout master..side |
165+
sed -e "/^\$/q" >patch10 &&
166+
! grep "^To: R. E. Cipient <[email protected]>\$" patch10
167+
'
168+
169+
test_expect_success '--no-to and --to replaces config.to' '
170+
171+
git config --replace-all format.to \
172+
"Someone <[email protected]>" &&
173+
git format-patch --no-to --to="Someone Else <[email protected]>" \
174+
--stdout master..side |
175+
sed -e "/^\$/q" >patch11 &&
176+
! grep "^To: Someone <[email protected]>\$" patch11 &&
177+
grep "^To: Someone Else <[email protected]>\$" patch11
178+
'
179+
180+
test_expect_success '--no-cc overrides config.cc' '
181+
182+
git config --replace-all format.cc \
183+
"C. E. Cipient <[email protected]>" &&
184+
git format-patch --no-cc --stdout master..side |
185+
sed -e "/^\$/q" >patch12 &&
186+
! grep "^Cc: C. E. Cipient <[email protected]>\$" patch12
187+
'
188+
189+
test_expect_success '--no-add-headers overrides config.headers' '
190+
191+
git config --replace-all format.headers \
192+
"Header1: B. E. Cipient <[email protected]>" &&
193+
git format-patch --no-add-headers --stdout master..side |
194+
sed -e "/^\$/q" >patch13 &&
195+
! grep "^Header1: B. E. Cipient <[email protected]>\$" patch13
196+
'
197+
160198
test_expect_success 'multiple files' '
161199
162200
rm -rf patches/ &&

0 commit comments

Comments
 (0)