Subject: [WIP/PATCH 4/9] Teach merge the --[no-]recurse-submodules option

From: Jens Lehmann <[email-masked]>
Date: Mon, 03 Feb 2014 20:50:41 +0100

This new option will allow the user to not only update the work tree of
the superproject according to the merge result but to also update the
work tree of all initialized submodules (so they match the SHA-1 recorded
in the superproject). But this commit only adds the option without any
functionality, that will be added to unpack_trees() in subsequent commits.

Signed-off-by: Jens Lehmann <[email-masked]>
---
 Documentation/git-merge.txt |  2 ++
 builtin/merge.c             | 14 ++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index 4395459..9ed1655 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -96,6 +96,8 @@ commit or stash your changes before running 'git merge'.
 'git merge --abort' is equivalent to 'git reset --merge' when
 `MERGE_HEAD` is present.

+include::recurse-submodules-update.txt[]
+
 <commit>...::
 	Commits, usually other branch heads, to merge into our branch.
 	Specifying more than one commit will create a merge with
diff --git a/builtin/merge.c b/builtin/merge.c
index 4941a6c..a0eb665 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -28,6 +28,7 @@
 #include "remote.h"
 #include "fmt-merge-msg.h"
 #include "gpg-interface.h"
+#include "submodule.h"

 #define DEFAULT_TWOHEAD (1<<0)
 #define DEFAULT_OCTOPUS (1<<1)
@@ -65,6 +66,8 @@ static int abort_current_merge;
 static int show_progress = -1;
 static int default_to_upstream;
 static const char *sign_commit;
+static const char *recurse_submodules_default = "off";
+static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;

 static struct strategy all_strategy[] = {
 	{ "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -223,6 +226,12 @@ static struct option builtin_merge_options[] = {
 	{ OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key id"),
 	  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
 	OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
+	{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
+		"checkout", "control recursive updating of submodules",
+		PARSE_OPT_OPTARG, option_parse_update_submodules },
+	{ OPTION_STRING, 0, "recurse-submodules-default",
+		&recurse_submodules_default, NULL,
+		"default mode for recursion", PARSE_OPT_HIDDEN },
 	OPT_END()
 };

@@ -1113,6 +1122,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	else
 		head_commit = lookup_commit_or_die(head_sha1, "HEAD");

+	gitmodules_config();
 	git_config(git_merge_config, NULL);

 	if (branch_mergeoptions)
@@ -1121,6 +1131,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 			builtin_merge_usage, 0);
 	if (shortlog_len < 0)
 		shortlog_len = (merge_log_config > 0) ? merge_log_config : 0;
+	set_config_update_recurse_submodules(
+		parse_update_recurse_submodules_arg("--recurse-submodules-default",
+						    recurse_submodules_default),
+		recurse_submodules);

 	if (verbosity < 0 && show_progress == -1)
 		show_progress = 0;
-- 
1.9.rc0.28.ge3363ff