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

[PATCH 3/3] builtin-merge: add support for default merge options

From
Jay Soffian <jaysoffian@gmail.com>
Date
Mar 6, 2009, 22:15 UTC
Message-ID
<9f755b5bae0b02c5cb3e01680acf71fe7153be04.1236377358.git.jaysoffian@gmail.com>
In-Reply-To
<13f0016028b195541b8b5d9149292150cbb13ab7.1236377358.git.jaysoffian@gmail.com>

This patch teaches merge a new setting, merge.options, which is processed before any of the other merge configuration settings. It may be used to establish a default which can then be overridden by more specific branch.<name>.mergeoptions (or, obviously, command-line switches).

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
 Documentation/git-merge.txt |   11 +++++--
 builtin-merge.c             |   10 ++++++
 t/t7600-merge.sh            |   69 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index f7be584..3cb06e7 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -47,10 +47,15 @@ CONFIGURATION
 -------------
 include::merge-config.txt[]
 
+merge.options::
+	Sets default options for merging. The syntax and supported options are
+	equal to that of 'git-merge'. Arguments are split by spaces, and may be
+	quoted in the same way as alias.* config options.
+
 branch.<name>.mergeoptions::
-	Sets default options for merging into branch <name>. The syntax and
-	supported options are equal to that of 'git-merge', but option values
-	containing whitespace characters are currently not supported.
+	Sets default options for merging into branch <name>. This setting is
+	handled after `merge.options`, so it may be used to override any
+	settings appearing there. The syntax is identical to `merge.options`.
 
 HOW MERGE WORKS
 ---------------
diff --git a/builtin-merge.c b/builtin-merge.c
index 504f2be..1f124b3 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -447,6 +447,15 @@ cleanup:
 	strbuf_release(&bname);
 }
 
+static int git_merge_config_default(const char *k, const char *v, void *cb)
+{
+	if (!strcmp(k, "merge.options")) {
+		if (git_config_option_string(builtin_merge_options, 0, k, v))
+			die("Bad merge.options string");
+	}
+	return 0;
+}
+
 static int git_merge_config(const char *k, const char *v, void *cb)
 {
 	if (branch && !prefixcmp(k, "branch.") &&
@@ -838,6 +847,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	if (is_null_sha1(head))
 		head_invalid = 1;
 
+	git_config(git_merge_config_default, NULL);
 	git_config(git_merge_config, NULL);
 
 	/* for color.ui */
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 9db8bb4..aaecdab 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -367,6 +367,16 @@ test_expect_success 'merge c1 with c2 (no-commit in config)' '
 
 test_debug 'gitk --all'
 
+test_expect_success 'merge c1 with c2 (no-commit in merge.options)' '
+	git reset --hard c1 &&
+	with_config merge.options --no-commit -- merge c2 &&
+	verify_merge file result.1-5 &&
+	verify_head $c1 &&
+	verify_mergeheads $c2
+'
+
+test_debug 'gitk --all'
+
 test_expect_success 'merge c1 with c2 (squash in config)' '
 	git reset --hard c1 &&
 	with_config branch.master.mergeoptions --squash -- \
@@ -379,6 +389,17 @@ test_expect_success 'merge c1 with c2 (squash in config)' '
 
 test_debug 'gitk --all'
 
+test_expect_success 'merge c1 with c2 (squash in merge.options)' '
+	git reset --hard c1 &&
+	with_config merge.options --squash -- merge c2 &&
+	verify_merge file result.1-5 &&
+	verify_head $c1 &&
+	verify_no_mergehead &&
+	verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
+'
+
+test_debug 'gitk --all'
+
 test_expect_success 'override config option -n with --summary' '
 	git reset --hard c1 &&
 	test_tick &&
@@ -425,6 +446,54 @@ test_expect_success 'override config option --stat' '
 
 test_debug 'gitk --all'
 
+test_expect_success 'override merge.options -n with branch mergeoptions --summary' '
+	git reset --hard c1 &&
+	test_tick &&
+	with_config merge.options -n branch.master.mergeoptions --summary -- \
+		merge c2 >diffstat.txt &&
+	verify_merge file result.1-5 msg.1-5 &&
+	verify_parents $c1 $c2 &&
+	if ! grep "^ file |  *2 +-$" diffstat.txt
+	then
+		echo "[OOPS] diffstat was not generated with --summary"
+		false
+	fi
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'override merge.options -n with branch mergeoptions --stat' '
+	git reset --hard c1 &&
+	test_tick &&
+	with_config merge.options -n branch.master.mergeoptions --stat -- \
+		merge c2 >diffstat.txt &&
+	verify_merge file result.1-5 msg.1-5 &&
+	verify_parents $c1 $c2 &&
+	if ! grep "^ file |  *2 +-$" diffstat.txt
+	then
+		echo "[OOPS] diffstat was not generated with --stat"
+		false
+	fi
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'override merge.options --stat' '
+	git reset --hard c1 &&
+	test_tick &&
+	with_config merge.options --stat branch.master.mergeoptions -n -- \
+		merge c2 >diffstat.txt &&
+	verify_merge file result.1-5 msg.1-5 &&
+	verify_parents $c1 $c2 &&
+	if grep "^ file |  *2 +-$" diffstat.txt
+	then
+		echo "[OOPS] diffstat was generated"
+		false
+	fi
+'
+
+test_debug 'gitk --all'
+
 test_expect_success 'merge c1 with c2 (override --no-commit)' '
 	git reset --hard c1 &&
 	test_tick &&
-- 
1.6.2.rc2.332.g5d21b
Previous: Jay SoffianNext: Junio C Hamano
Message 4 of 15 in “Re: how to have --no-ff be the default for all branch”
  1. 0/3 Re: how to have --no-ff be the default for all branchJay Soffian, Mar 6, 2009
  2. 1/3 config: add git_config_option_string()Jay Soffian, Mar 6, 2009
  3. 2/3 builtin-merge: refactor to use git_config_option_stringJay Soffian, Mar 6, 2009
  4. 3/3 builtin-merge: add support for default merge optionsJay Soffian, Mar 6, 2009
  5. Junio C HamanoMar 6, 2009
  6. Jay SoffianMar 6, 2009
  7. 3/3 builtin-merge: add support for default merge optionsJay Soffian, Mar 7, 2009
  8. Junio C HamanoMar 7, 2009
  9. Jay SoffianMar 7, 2009
  10. Junio C HamanoMar 7, 2009
  11. Jay SoffianMar 7, 2009
  12. jean-luc maletMar 7, 2009
  13. jean-luc maletMar 19, 2010
  14. Jay SoffianMar 19, 2010
  15. jean-luc maletApr 2, 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.