Add the 'fetch.recurseSubmodules' config setting
This new boolean option can be used to override the default for "git fetch" and "git pull", which is to not recurse into populated submodules and fetch all new commits there too. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7dce19d374
commit
be254a0ea9
@ -862,6 +862,11 @@ diff.wordRegex::
|
||||
sequences that match the regular expression are "words", all other
|
||||
characters are *ignorable* whitespace.
|
||||
|
||||
fetch.recurseSubmodules::
|
||||
A boolean value which changes the behavior for fetch and pull, the
|
||||
default is to not recursively fetch populated sumodules unless
|
||||
configured otherwise.
|
||||
|
||||
fetch.unpackLimit::
|
||||
If the number of objects fetched over the git native
|
||||
transfer is below this
|
||||
|
@ -60,8 +60,9 @@ endif::git-pull[]
|
||||
flag lets all tags and their associated objects be
|
||||
downloaded.
|
||||
|
||||
--recurse-submodules::
|
||||
Use this option to fetch new commits of all populated submodules too.
|
||||
--[no-]recurse-submodules::
|
||||
This option controls if new commits of all populated submodules should
|
||||
be fetched too (see linkgit:git-config[1]).
|
||||
|
||||
ifndef::git-pull[]
|
||||
--submodule-prefix=<path>::
|
||||
|
@ -28,8 +28,14 @@ enum {
|
||||
TAGS_SET = 2
|
||||
};
|
||||
|
||||
enum {
|
||||
RECURSE_SUBMODULES_OFF = 0,
|
||||
RECURSE_SUBMODULES_DEFAULT = 1,
|
||||
RECURSE_SUBMODULES_ON = 2
|
||||
};
|
||||
|
||||
static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, verbosity;
|
||||
static int progress, recurse_submodules;
|
||||
static int progress, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
|
||||
static int tags = TAGS_DEFAULT;
|
||||
static const char *depth;
|
||||
static const char *upload_pack;
|
||||
@ -55,8 +61,9 @@ static struct option builtin_fetch_options[] = {
|
||||
"do not fetch all tags (--no-tags)", TAGS_UNSET),
|
||||
OPT_BOOLEAN('p', "prune", &prune,
|
||||
"prune tracking branches no longer on remote"),
|
||||
OPT_BOOLEAN(0, "recurse-submodules", &recurse_submodules,
|
||||
"control recursive fetching of submodules"),
|
||||
OPT_SET_INT(0, "recurse-submodules", &recurse_submodules,
|
||||
"control recursive fetching of submodules",
|
||||
RECURSE_SUBMODULES_ON),
|
||||
OPT_BOOLEAN(0, "dry-run", &dry_run,
|
||||
"dry run"),
|
||||
OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
|
||||
@ -795,7 +802,7 @@ static void add_options_to_argv(int *argc, const char **argv)
|
||||
argv[(*argc)++] = "--force";
|
||||
if (keep)
|
||||
argv[(*argc)++] = "--keep";
|
||||
if (recurse_submodules)
|
||||
if (recurse_submodules == RECURSE_SUBMODULES_ON)
|
||||
argv[(*argc)++] = "--recurse-submodules";
|
||||
if (verbosity >= 2)
|
||||
argv[(*argc)++] = "-v";
|
||||
@ -933,14 +940,18 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
|
||||
}
|
||||
}
|
||||
|
||||
if (!result && recurse_submodules) {
|
||||
if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) {
|
||||
const char *options[10];
|
||||
int num_options = 0;
|
||||
/* Set recursion as default when we already are recursing */
|
||||
if (submodule_prefix[0])
|
||||
set_config_fetch_recurse_submodules(1);
|
||||
gitmodules_config();
|
||||
git_config(submodule_config, NULL);
|
||||
add_options_to_argv(&num_options, options);
|
||||
result = fetch_populated_submodules(num_options, options,
|
||||
submodule_prefix,
|
||||
recurse_submodules == RECURSE_SUBMODULES_ON,
|
||||
verbosity < 0);
|
||||
}
|
||||
|
||||
|
@ -108,6 +108,9 @@ do
|
||||
--recurse-submodules)
|
||||
recurse_submodules=--recurse-submodules
|
||||
;;
|
||||
--no-recurse-submodules)
|
||||
recurse_submodules=--no-recurse-submodules
|
||||
;;
|
||||
--d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run)
|
||||
dry_run=--dry-run
|
||||
;;
|
||||
|
18
submodule.c
18
submodule.c
@ -11,6 +11,7 @@
|
||||
|
||||
struct string_list config_name_for_path;
|
||||
struct string_list config_ignore_for_name;
|
||||
static int config_fetch_recurse_submodules;
|
||||
|
||||
static int add_submodule_odb(const char *path)
|
||||
{
|
||||
@ -67,6 +68,10 @@ int submodule_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
if (!prefixcmp(var, "submodule."))
|
||||
return parse_submodule_config_option(var, value);
|
||||
else if (!strcmp(var, "fetch.recursesubmodules")) {
|
||||
config_fetch_recurse_submodules = git_config_bool(var, value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -229,8 +234,14 @@ void show_submodule_summary(FILE *f, const char *path,
|
||||
strbuf_release(&sb);
|
||||
}
|
||||
|
||||
void set_config_fetch_recurse_submodules(int value)
|
||||
{
|
||||
config_fetch_recurse_submodules = value;
|
||||
}
|
||||
|
||||
int fetch_populated_submodules(int num_options, const char **options,
|
||||
const char *prefix, int quiet)
|
||||
const char *prefix, int ignore_config,
|
||||
int quiet)
|
||||
{
|
||||
int i, result = 0, argc = 0;
|
||||
struct child_process cp;
|
||||
@ -271,6 +282,11 @@ int fetch_populated_submodules(int num_options, const char **options,
|
||||
if (name_for_path)
|
||||
name = name_for_path->util;
|
||||
|
||||
if (!ignore_config) {
|
||||
if (!config_fetch_recurse_submodules)
|
||||
continue;
|
||||
}
|
||||
|
||||
strbuf_addf(&submodule_path, "%s/%s", work_tree, ce->name);
|
||||
strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
|
||||
strbuf_addf(&submodule_prefix, "%s%s/", prefix, ce->name);
|
||||
|
@ -13,8 +13,10 @@ void show_submodule_summary(FILE *f, const char *path,
|
||||
unsigned char one[20], unsigned char two[20],
|
||||
unsigned dirty_submodule,
|
||||
const char *del, const char *add, const char *reset);
|
||||
void set_config_fetch_recurse_submodules(int value);
|
||||
int fetch_populated_submodules(int num_options, const char **options,
|
||||
const char *prefix, int quiet);
|
||||
const char *prefix, int ignore_config,
|
||||
int quiet);
|
||||
unsigned is_submodule_modified(const char *path, int ignore_untracked);
|
||||
int merge_submodule(unsigned char result[20], const char *path, const unsigned char base[20],
|
||||
const unsigned char a[20], const unsigned char b[20]);
|
||||
|
@ -106,4 +106,40 @@ test_expect_success "--dry-run propagates to submodules" '
|
||||
test_cmp expect.err actual.err
|
||||
'
|
||||
|
||||
test_expect_success "recurseSubmodules=true propagates into submodules" '
|
||||
add_upstream_commit &&
|
||||
(
|
||||
cd downstream &&
|
||||
git config fetch.recurseSubmodules true
|
||||
git fetch >../actual.out 2>../actual.err
|
||||
) &&
|
||||
test_cmp expect.out actual.out &&
|
||||
test_cmp expect.err actual.err
|
||||
'
|
||||
|
||||
test_expect_success "--recurse-submodules overrides config in submodule" '
|
||||
add_upstream_commit &&
|
||||
(
|
||||
cd downstream &&
|
||||
(
|
||||
cd submodule &&
|
||||
git config fetch.recurseSubmodules false
|
||||
) &&
|
||||
git fetch --recurse-submodules >../actual.out 2>../actual.err
|
||||
) &&
|
||||
test_cmp expect.out actual.out &&
|
||||
test_cmp expect.err actual.err
|
||||
'
|
||||
|
||||
test_expect_success "--no-recurse-submodules overrides config setting" '
|
||||
add_upstream_commit &&
|
||||
(
|
||||
cd downstream &&
|
||||
git config fetch.recurseSubmodules true
|
||||
git fetch --no-recurse-submodules >../actual.out 2>../actual.err
|
||||
) &&
|
||||
! test -s actual.out &&
|
||||
! test -s actual.err
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Loading…
Reference in New Issue
Block a user