Skip to content

Commit 046b482

Browse files
stefanbellergitster
authored andcommitted
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>
1 parent 1d789d0 commit 046b482

File tree

7 files changed

+58
-5
lines changed

7 files changed

+58
-5
lines changed

Documentation/config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,6 +3065,11 @@ submodule.active::
30653065
submodule's path to determine if the submodule is of interest to git
30663066
commands.
30673067

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+
30683073
submodule.fetchJobs::
30693074
Specifies how many submodules are fetched/cloned at the same time.
30703075
A positive integer allows up to that number of submodules fetched

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
855855
}
856856

857857
if (starts_with(var, "submodule."))
858-
return parse_submodule_config_option(var, value);
858+
return submodule_config(var, value, NULL);
859859

860860
return git_xmerge_config(var, value, NULL);
861861
}

builtin/read-tree.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ static int debug_merge(const struct cache_entry * const *stages,
9898
return 0;
9999
}
100100

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+
101109
static struct lock_file lock_file;
102110

103111
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)
150158
opts.src_index = &the_index;
151159
opts.dst_index = &the_index;
152160

153-
git_config(git_default_config, NULL);
161+
git_config(git_read_tree_config, NULL);
154162

155163
argc = parse_options(argc, argv, unused_prefix, read_tree_options,
156164
read_tree_usage, 0);

builtin/reset.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ static int reset_refs(const char *rev, const struct object_id *oid)
266266
return update_ref_status;
267267
}
268268

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+
269277
int cmd_reset(int argc, const char **argv, const char *prefix)
270278
{
271279
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)
294302
OPT_END()
295303
};
296304

297-
git_config(git_default_config, NULL);
305+
git_config(git_reset_config, NULL);
298306

299307
argc = parse_options(argc, argv, prefix, options, git_reset_usage,
300308
PARSE_OPT_KEEP_DASHDASH);

submodule.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "quote.h"
1717
#include "remote.h"
1818
#include "worktree.h"
19+
#include "parse-options.h"
1920

2021
static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
2122
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)
170171
return 0;
171172
}
172173

173-
/* Loads all submodule settings from the config */
174+
/* Loads all submodule settings from the config. */
174175
int submodule_config(const char *var, const char *value, void *cb)
175176
{
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;
177196
}
178197

179198
int option_parse_recurse_submodules_worktree_updater(const struct option *opt,

submodule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern void stage_updated_gitmodules(void);
3939
extern void set_diffopt_flags_from_submodule_config(struct diff_options *,
4040
const char *path);
4141
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);
4243

4344
struct option;
4445
int option_parse_recurse_submodules_worktree_updater(const struct option *opt,

t/lib-submodule-update.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,18 @@ test_submodule_switch_recursing_with_args () {
990990
)
991991
'
992992

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+
9931005
# Updating a submodule to an invalid sha1 doesn't update the
9941006
# superproject nor the submodule's work tree.
9951007
test_expect_success "$command: updating to a missing submodule commit fails" '

0 commit comments

Comments
 (0)