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>
This commit is contained in:
parent
1d789d0892
commit
046b48239e
@ -3065,6 +3065,11 @@ submodule.active::
|
||||
submodule's path to determine if the submodule is of interest to git
|
||||
commands.
|
||||
|
||||
submodule.recurse::
|
||||
Specifies if commands recurse into submodules by default. This
|
||||
applies to all commands that have a `--recurse-submodules` option.
|
||||
Defaults to false.
|
||||
|
||||
submodule.fetchJobs::
|
||||
Specifies how many submodules are fetched/cloned at the same time.
|
||||
A positive integer allows up to that number of submodules fetched
|
||||
|
@ -855,7 +855,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
|
||||
}
|
||||
|
||||
if (starts_with(var, "submodule."))
|
||||
return parse_submodule_config_option(var, value);
|
||||
return submodule_config(var, value, NULL);
|
||||
|
||||
return git_xmerge_config(var, value, NULL);
|
||||
}
|
||||
|
@ -98,6 +98,14 @@ static int debug_merge(const struct cache_entry * const *stages,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int git_read_tree_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
if (!strcmp(var, "submodule.recurse"))
|
||||
return git_default_submodule_config(var, value, cb);
|
||||
|
||||
return git_default_config(var, value, cb);
|
||||
}
|
||||
|
||||
static struct lock_file lock_file;
|
||||
|
||||
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)
|
||||
opts.src_index = &the_index;
|
||||
opts.dst_index = &the_index;
|
||||
|
||||
git_config(git_default_config, NULL);
|
||||
git_config(git_read_tree_config, NULL);
|
||||
|
||||
argc = parse_options(argc, argv, unused_prefix, read_tree_options,
|
||||
read_tree_usage, 0);
|
||||
|
@ -266,6 +266,14 @@ static int reset_refs(const char *rev, const struct object_id *oid)
|
||||
return update_ref_status;
|
||||
}
|
||||
|
||||
static int git_reset_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
if (!strcmp(var, "submodule.recurse"))
|
||||
return git_default_submodule_config(var, value, cb);
|
||||
|
||||
return git_default_config(var, value, cb);
|
||||
}
|
||||
|
||||
int cmd_reset(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
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)
|
||||
OPT_END()
|
||||
};
|
||||
|
||||
git_config(git_default_config, NULL);
|
||||
git_config(git_reset_config, NULL);
|
||||
|
||||
argc = parse_options(argc, argv, prefix, options, git_reset_usage,
|
||||
PARSE_OPT_KEEP_DASHDASH);
|
||||
|
23
submodule.c
23
submodule.c
@ -16,6 +16,7 @@
|
||||
#include "quote.h"
|
||||
#include "remote.h"
|
||||
#include "worktree.h"
|
||||
#include "parse-options.h"
|
||||
|
||||
static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
|
||||
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)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Loads all submodule settings from the config */
|
||||
/* Loads all submodule settings from the config. */
|
||||
int submodule_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
return git_modules_config(var, value, cb);
|
||||
if (!strcmp(var, "submodule.recurse")) {
|
||||
int v = git_config_bool(var, value) ?
|
||||
RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
|
||||
config_update_recurse_submodules = v;
|
||||
return 0;
|
||||
} else {
|
||||
return git_modules_config(var, value, cb);
|
||||
}
|
||||
}
|
||||
|
||||
/* Cheap function that only determines if we're interested in submodules at all */
|
||||
int git_default_submodule_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
if (!strcmp(var, "submodule.recurse")) {
|
||||
int v = git_config_bool(var, value) ?
|
||||
RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
|
||||
config_update_recurse_submodules = v;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
|
||||
|
@ -39,6 +39,7 @@ extern void stage_updated_gitmodules(void);
|
||||
extern void set_diffopt_flags_from_submodule_config(struct diff_options *,
|
||||
const char *path);
|
||||
extern int submodule_config(const char *var, const char *value, void *cb);
|
||||
extern int git_default_submodule_config(const char *var, const char *value, void *cb);
|
||||
|
||||
struct option;
|
||||
int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
|
||||
|
@ -990,6 +990,18 @@ test_submodule_switch_recursing_with_args () {
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success "git -c submodule.recurse=true $cmd_args: modified submodule updates submodule work tree" '
|
||||
prolog &&
|
||||
reset_work_tree_to_interested add_sub1 &&
|
||||
(
|
||||
cd submodule_update &&
|
||||
git branch -t modify_sub1 origin/modify_sub1 &&
|
||||
git -c submodule.recurse=true $cmd_args modify_sub1 &&
|
||||
test_superproject_content origin/modify_sub1 &&
|
||||
test_submodule_content sub1 origin/modify_sub1
|
||||
)
|
||||
'
|
||||
|
||||
# Updating a submodule to an invalid sha1 doesn't update the
|
||||
# superproject nor the submodule's work tree.
|
||||
test_expect_success "$command: updating to a missing submodule commit fails" '
|
||||
|
Loading…
Reference in New Issue
Block a user