@matheusbsbs / matheus-bagliano / commits / c42600346b
Fork 0

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 <someone@out.there> $ git format-patch -1 --no-to --to="Someone Else <else@out.there>" would format a patch addressed to "Someone Else" and not "Someone". Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen Boyd committed Mar 7, 2010 at 14:46 UTC c42600346bb6c3427df7ea1c5a33d723ec02d731
2 files changed +56 -7
builtin-log.c
+18 -7
@@ -869,19 +869,31 @@ static int inline_callback(const struct option *opt, const char *arg, int unset)
869
870 static int header_callback(const struct option *opt, const char *arg, int unset)
871 {
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 + }
879 return 0;
880 }
881
882 static int to_callback(const struct option *opt, const char *arg, int unset)
883 {
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);
888 return 0;
889 }
890
891 static int cc_callback(const struct option *opt, const char *arg, int unset)
892 {
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);
897 return 0;
898 }
899
@@ -940,12 +952,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
952 PARSE_OPT_NONEG | PARSE_OPT_NOARG },
953 OPT_GROUP("Messaging"),
954 { OPTION_CALLBACK, 0, "add-header", NULL, "header",
943 - "add email header", PARSE_OPT_NONEG,
944 - header_callback },
955 + "add email header", 0, header_callback },
956 { OPTION_CALLBACK, 0, "to", NULL, "email", "add To: header",
946 - PARSE_OPT_NONEG, to_callback },
957 + 0, to_callback },
958 { OPTION_CALLBACK, 0, "cc", NULL, "email", "add Cc: header",
948 - PARSE_OPT_NONEG, cc_callback },
959 + 0, cc_callback },
960 OPT_STRING(0, "in-reply-to", &in_reply_to, "message-id",
961 "make first mail a reply to <message-id>"),
962 { OPTION_CALLBACK, 0, "attach", &rev, "boundary",
t/t4014-format-patch.sh
+38
@@ -157,6 +157,44 @@ test_expect_success 'configuration To: header' '
157 grep "^To: R. E. Cipient <rcipient@example.com>\$" patch9
158 '
159
160 +test_expect_success '--no-to overrides config.to' '
161 +
162 + git config --replace-all format.to \
163 + "R. E. Cipient <rcipient@example.com>" &&
164 + git format-patch --no-to --stdout master..side |
165 + sed -e "/^\$/q" >patch10 &&
166 + ! grep "^To: R. E. Cipient <rcipient@example.com>\$" patch10
167 +'
168 +
169 +test_expect_success '--no-to and --to replaces config.to' '
170 +
171 + git config --replace-all format.to \
172 + "Someone <someone@out.there>" &&
173 + git format-patch --no-to --to="Someone Else <else@out.there>" \
174 + --stdout master..side |
175 + sed -e "/^\$/q" >patch11 &&
176 + ! grep "^To: Someone <someone@out.there>\$" patch11 &&
177 + grep "^To: Someone Else <else@out.there>\$" patch11
178 +'
179 +
180 +test_expect_success '--no-cc overrides config.cc' '
181 +
182 + git config --replace-all format.cc \
183 + "C. E. Cipient <rcipient@example.com>" &&
184 + git format-patch --no-cc --stdout master..side |
185 + sed -e "/^\$/q" >patch12 &&
186 + ! grep "^Cc: C. E. Cipient <rcipient@example.com>\$" 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 <rcipient@example.com>" &&
193 + git format-patch --no-add-headers --stdout master..side |
194 + sed -e "/^\$/q" >patch13 &&
195 + ! grep "^Header1: B. E. Cipient <rcipient@example.com>\$" patch13
196 +'
197 +
198 test_expect_success 'multiple files' '
199
200 rm -rf patches/ &&