git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv2 2/3] format-patch: add --no-cc, --no-to, and --no-add-headers

From
Stephen Boyd <bebarino@gmail.com>
Date
Mar 7, 2010, 22:46 UTC
Message-ID
<1268002008-13426-3-git-send-email-bebarino@gmail.com>
In-Reply-To
<1267997598-20815-1-git-send-email-bebarino@gmail.com>

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>
---
 builtin-log.c           |   25 ++++++++++++++++++-------
 t/t4014-format-patch.sh |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 7 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index ca241af..08e2ff0 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -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",
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 830ddb0..c7b6256 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -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/ &&
-- 
1.7.0.1.171.geb5ee
Previous: Stephen BoydNext: Stephen Boyd
Message 27 of 38 in “What's cooking in git.git (Mar 2010, #01; Wed, 03)”
  1. Junio C HamanoMar 4, 2010
  2. Adam SimpkinsMar 4, 2010
  3. Björn GustavssonMar 4, 2010
  4. Junio C HamanoMar 4, 2010
  5. Tay Ray ChuanMar 4, 2010
  6. Junio C HamanoMar 4, 2010
  7. Junio C HamanoMar 4, 2010
  8. Junio C HamanoMar 5, 2010
  9. git reset --keep (Re: What's cooking in git.git (Mar 2010, #01; Wed, 03))Jonathan Nieder, Mar 5, 2010
  10. Christian CouderMar 5, 2010
  11. Christian CouderMar 5, 2010
  12. Thomas RastMar 4, 2010
  13. Mark LodatoMar 5, 2010
  14. Mark LodatoMar 5, 2010
  15. Junio C HamanoMar 5, 2010
  16. Add tests for git format-patch --to and format.to config optionMiklos Vajna, Mar 6, 2010
  17. Junio C HamanoMar 6, 2010
  18. format-patch --to: overwrite format.to contents, don't append itMiklos Vajna, Mar 6, 2010
  19. Stephen BoydMar 7, 2010
  20. Miklos VajnaMar 7, 2010
  21. Junio C HamanoMar 7, 2010
  22. Stephen BoydMar 7, 2010
  23. Junio C HamanoMar 7, 2010
  24. 0/4 format-patch and send-email ignoring config settingsStephen Boyd, Mar 7, 2010
  25. 0/3 format-patch and send-email ignoring config settingsStephen Boyd, Mar 7, 2010
  26. 1/3 format-patch: use a string_list for headersStephen Boyd, Mar 7, 2010
  27. 2/3 format-patch: add --no-cc, --no-to, and --no-add-headersStephen Boyd, Mar 7, 2010
  28. 3/3 send-email: add --no-cc, --no-to, and --no-bccStephen Boyd, Mar 7, 2010
  29. Junio C HamanoMar 9, 2010
  30. 1/4 send-email: actually add bcc headersStephen Boyd, Mar 7, 2010
  31. Stephen BoydMar 7, 2010
  32. 2/4 format-patch: use a string_list for headersStephen Boyd, Mar 7, 2010
  33. Erik Faye-LundMar 7, 2010
  34. Stephen BoydMar 7, 2010
  35. Johannes SchindelinMar 7, 2010
  36. 3/4 format-patch: add --no-cc, --no-to, and --no-add-headersStephen Boyd, Mar 7, 2010
  37. 4/4 send-email: add --no-cc, --no-to, and --no-bccStephen Boyd, Mar 7, 2010
  38. Steven DrakeMar 10, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.