Introduce 'submodule.recurse' option for worktree manipulators

Any command that understands '--recurse-submodules' can have its default changed to true, by setting the new 'submodule.recurse' option. This patch includes read-tree/checkout/reset for working tree manipulating commands. Later patches will cover other commands. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed May 31, 2017 at 17:30 UTC 046b48239eca34425909330e59da57f5fd421bdc
7 files changed +58 -5
Documentation/config.txt
+5
@@ -3065,6 +3065,11 @@ submodule.active::
3065 submodule's path to determine if the submodule is of interest to git
3066 commands.
3067
3068 +submodule.recurse::
3069 + Specifies if commands recurse into submodules by default. This
3070 + applies to all commands that have a `--recurse-submodules` option.
3071 + Defaults to false.
3072 +
3073 submodule.fetchJobs::
3074 Specifies how many submodules are fetched/cloned at the same time.
3075 A positive integer allows up to that number of submodules fetched
builtin/checkout.c
+1 -1
@@ -855,7 +855,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
855 }
856
857 if (starts_with(var, "submodule."))
858 - return parse_submodule_config_option(var, value);
858 + return submodule_config(var, value, NULL);
859
860 return git_xmerge_config(var, value, NULL);
861 }
builtin/read-tree.c
+9 -1
@@ -98,6 +98,14 @@ static int debug_merge(const struct cache_entry * const *stages,
98 return 0;
99 }
100
101 +static int git_read_tree_config(const char *var, const char *value, void *cb)
102 +{
103 + if (!strcmp(var, "submodule.recurse"))
104 + return git_default_submodule_config(var, value, cb);
105 +
106 + return git_default_config(var, value, cb);
107 +}
108 +
109 static struct lock_file lock_file;
110
111 int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
@@ -150,7 +158,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
158 opts.src_index = &the_index;
159 opts.dst_index = &the_index;
160
153 - git_config(git_default_config, NULL);
161 + git_config(git_read_tree_config, NULL);
162
163 argc = parse_options(argc, argv, unused_prefix, read_tree_options,
164 read_tree_usage, 0);
builtin/reset.c
+9 -1
@@ -266,6 +266,14 @@ static int reset_refs(const char *rev, const struct object_id *oid)
266 return update_ref_status;
267 }
268
269 +static int git_reset_config(const char *var, const char *value, void *cb)
270 +{
271 + if (!strcmp(var, "submodule.recurse"))
272 + return git_default_submodule_config(var, value, cb);
273 +
274 + return git_default_config(var, value, cb);
275 +}
276 +
277 int cmd_reset(int argc, const char **argv, const char *prefix)
278 {
279 int reset_type = NONE, update_ref_status = 0, quiet = 0;
@@ -294,7 +302,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
302 OPT_END()
303 };
304
297 - git_config(git_default_config, NULL);
305 + git_config(git_reset_config, NULL);
306
307 argc = parse_options(argc, argv, prefix, options, git_reset_usage,
308 PARSE_OPT_KEEP_DASHDASH);
submodule.c
+21 -2
@@ -16,6 +16,7 @@
16 #include "quote.h"
17 #include "remote.h"
18 #include "worktree.h"
19 +#include "parse-options.h"
20
21 static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
22 static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
@@ -170,10 +171,28 @@ static int git_modules_config(const char *var, const char *value, void *cb)
171 return 0;
172 }
173
173 -/* Loads all submodule settings from the config */
174 +/* Loads all submodule settings from the config. */
175 int submodule_config(const char *var, const char *value, void *cb)
176 {
176 - return git_modules_config(var, value, cb);
177 + if (!strcmp(var, "submodule.recurse")) {
178 + int v = git_config_bool(var, value) ?
179 + RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
180 + config_update_recurse_submodules = v;
181 + return 0;
182 + } else {
183 + return git_modules_config(var, value, cb);
184 + }
185 +}
186 +
187 +/* Cheap function that only determines if we're interested in submodules at all */
188 +int git_default_submodule_config(const char *var, const char *value, void *cb)
189 +{
190 + if (!strcmp(var, "submodule.recurse")) {
191 + int v = git_config_bool(var, value) ?
192 + RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
193 + config_update_recurse_submodules = v;
194 + }
195 + return 0;
196 }
197
198 int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
submodule.h
+1
@@ -39,6 +39,7 @@ extern void stage_updated_gitmodules(void);
39 extern void set_diffopt_flags_from_submodule_config(struct diff_options *,
40 const char *path);
41 extern int submodule_config(const char *var, const char *value, void *cb);
42 +extern int git_default_submodule_config(const char *var, const char *value, void *cb);
43
44 struct option;
45 int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
t/lib-submodule-update.sh
+12
@@ -990,6 +990,18 @@ test_submodule_switch_recursing_with_args () {
990 )
991 '
992
993 + test_expect_success "git -c submodule.recurse=true $cmd_args: modified submodule updates submodule work tree" '
994 + prolog &&
995 + reset_work_tree_to_interested add_sub1 &&
996 + (
997 + cd submodule_update &&
998 + git branch -t modify_sub1 origin/modify_sub1 &&
999 + git -c submodule.recurse=true $cmd_args modify_sub1 &&
1000 + test_superproject_content origin/modify_sub1 &&
1001 + test_submodule_content sub1 origin/modify_sub1
1002 + )
1003 + '
1004 +
1005 # Updating a submodule to an invalid sha1 doesn't update the
1006 # superproject nor the submodule's work tree.
1007 test_expect_success "$command: updating to a missing submodule commit fails" '