]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: add --no-cc, --no-to, and --no-add-headers
authorStephen Boyd <bebarino@gmail.com>
Sun, 7 Mar 2010 22:46:47 +0000 (14:46 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Mar 2010 23:55:41 +0000 (15:55 -0800)
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>
builtin-log.c
t/t4014-format-patch.sh

index 207dd1fa90f120a88c45eb739c2197015007d188..e14c0a2a0191ca8b74ec76cf84b84c9b6b6d6ef5 100644 (file)
@@ -869,19 +869,31 @@ static int inline_callback(const struct option *opt, const char *arg, int unset)
 
 static int header_callback(const struct option *opt, const char *arg, int unset)
 {
-       add_header(arg);
+       if (unset) {
+               string_list_clear(&extra_hdr, 0);
+               string_list_clear(&extra_to, 0);
+               string_list_clear(&extra_cc, 0);
+       } else {
+           add_header(arg);
+       }
        return 0;
 }
 
 static int to_callback(const struct option *opt, const char *arg, int unset)
 {
-       string_list_append(arg, &extra_to);
+       if (unset)
+               string_list_clear(&extra_to, 0);
+       else
+               string_list_append(arg, &extra_to);
        return 0;
 }
 
 static int cc_callback(const struct option *opt, const char *arg, int unset)
 {
-       string_list_append(arg, &extra_cc);
+       if (unset)
+               string_list_clear(&extra_cc, 0);
+       else
+               string_list_append(arg, &extra_cc);
        return 0;
 }
 
@@ -940,12 +952,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                  PARSE_OPT_NONEG | PARSE_OPT_NOARG },
                OPT_GROUP("Messaging"),
                { OPTION_CALLBACK, 0, "add-header", NULL, "header",
-                           "add email header", PARSE_OPT_NONEG,
-                           header_callback },
+                           "add email header", 0, header_callback },
                { OPTION_CALLBACK, 0, "to", NULL, "email", "add To: header",
-                           PARSE_OPT_NONEG, to_callback },
+                           0, to_callback },
                { OPTION_CALLBACK, 0, "cc", NULL, "email", "add Cc: header",
-                           PARSE_OPT_NONEG, cc_callback },
+                           0, cc_callback },
                OPT_STRING(0, "in-reply-to", &in_reply_to, "message-id",
                            "make first mail a reply to <message-id>"),
                { OPTION_CALLBACK, 0, "attach", &rev, "boundary",
index 830ddb0cbe6749154a74d6e8d255ff4a8659f221..c7b625642dd57f4bcb6f7c5aa240cc9c32e15af8 100755 (executable)
@@ -157,6 +157,44 @@ test_expect_success 'configuration To: header' '
        grep "^To: R. E. Cipient <rcipient@example.com>\$" patch9
 '
 
+test_expect_success '--no-to overrides config.to' '
+
+       git config --replace-all format.to \
+               "R. E. Cipient <rcipient@example.com>" &&
+       git format-patch --no-to --stdout master..side |
+       sed -e "/^\$/q" >patch10 &&
+       ! grep "^To: R. E. Cipient <rcipient@example.com>\$" patch10
+'
+
+test_expect_success '--no-to and --to replaces config.to' '
+
+       git config --replace-all format.to \
+               "Someone <someone@out.there>" &&
+       git format-patch --no-to --to="Someone Else <else@out.there>" \
+               --stdout master..side |
+       sed -e "/^\$/q" >patch11 &&
+       ! grep "^To: Someone <someone@out.there>\$" patch11 &&
+       grep "^To: Someone Else <else@out.there>\$" patch11
+'
+
+test_expect_success '--no-cc overrides config.cc' '
+
+       git config --replace-all format.cc \
+               "C. E. Cipient <rcipient@example.com>" &&
+       git format-patch --no-cc --stdout master..side |
+       sed -e "/^\$/q" >patch12 &&
+       ! grep "^Cc: C. E. Cipient <rcipient@example.com>\$" patch12
+'
+
+test_expect_success '--no-add-headers overrides config.headers' '
+
+       git config --replace-all format.headers \
+               "Header1: B. E. Cipient <rcipient@example.com>" &&
+       git format-patch --no-add-headers --stdout master..side |
+       sed -e "/^\$/q" >patch13 &&
+       ! grep "^Header1: B. E. Cipient <rcipient@example.com>\$" patch13
+'
+
 test_expect_success 'multiple files' '
 
        rm -rf patches/ &&