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:
Jens Lehmann 2010-11-11 00:55:02 +01:00 committed by Junio C Hamano
parent 7dce19d374
commit be254a0ea9
7 changed files with 83 additions and 9 deletions

View File

@ -862,6 +862,11 @@ diff.wordRegex::
sequences that match the regular expression are "words", all other sequences that match the regular expression are "words", all other
characters are *ignorable* whitespace. 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:: fetch.unpackLimit::
If the number of objects fetched over the git native If the number of objects fetched over the git native
transfer is below this transfer is below this

View File

@ -60,8 +60,9 @@ endif::git-pull[]
flag lets all tags and their associated objects be flag lets all tags and their associated objects be
downloaded. downloaded.
--recurse-submodules:: --[no-]recurse-submodules::
Use this option to fetch new commits of all populated submodules too. This option controls if new commits of all populated submodules should
be fetched too (see linkgit:git-config[1]).
ifndef::git-pull[] ifndef::git-pull[]
--submodule-prefix=<path>:: --submodule-prefix=<path>::

View File

@ -28,8 +28,14 @@ enum {
TAGS_SET = 2 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 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 int tags = TAGS_DEFAULT;
static const char *depth; static const char *depth;
static const char *upload_pack; static const char *upload_pack;
@ -55,8 +61,9 @@ static struct option builtin_fetch_options[] = {
"do not fetch all tags (--no-tags)", TAGS_UNSET), "do not fetch all tags (--no-tags)", TAGS_UNSET),
OPT_BOOLEAN('p', "prune", &prune, OPT_BOOLEAN('p', "prune", &prune,
"prune tracking branches no longer on remote"), "prune tracking branches no longer on remote"),
OPT_BOOLEAN(0, "recurse-submodules", &recurse_submodules, OPT_SET_INT(0, "recurse-submodules", &recurse_submodules,
"control recursive fetching of submodules"), "control recursive fetching of submodules",
RECURSE_SUBMODULES_ON),
OPT_BOOLEAN(0, "dry-run", &dry_run, OPT_BOOLEAN(0, "dry-run", &dry_run,
"dry run"), "dry run"),
OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"), 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"; argv[(*argc)++] = "--force";
if (keep) if (keep)
argv[(*argc)++] = "--keep"; argv[(*argc)++] = "--keep";
if (recurse_submodules) if (recurse_submodules == RECURSE_SUBMODULES_ON)
argv[(*argc)++] = "--recurse-submodules"; argv[(*argc)++] = "--recurse-submodules";
if (verbosity >= 2) if (verbosity >= 2)
argv[(*argc)++] = "-v"; 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]; const char *options[10];
int num_options = 0; 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(); gitmodules_config();
git_config(submodule_config, NULL); git_config(submodule_config, NULL);
add_options_to_argv(&num_options, options); add_options_to_argv(&num_options, options);
result = fetch_populated_submodules(num_options, options, result = fetch_populated_submodules(num_options, options,
submodule_prefix, submodule_prefix,
recurse_submodules == RECURSE_SUBMODULES_ON,
verbosity < 0); verbosity < 0);
} }

View File

@ -108,6 +108,9 @@ do
--recurse-submodules) --recurse-submodules)
recurse_submodules=--recurse-submodules recurse_submodules=--recurse-submodules
;; ;;
--no-recurse-submodules)
recurse_submodules=--no-recurse-submodules
;;
--d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run) --d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run)
dry_run=--dry-run dry_run=--dry-run
;; ;;

View File

@ -11,6 +11,7 @@
struct string_list config_name_for_path; struct string_list config_name_for_path;
struct string_list config_ignore_for_name; struct string_list config_ignore_for_name;
static int config_fetch_recurse_submodules;
static int add_submodule_odb(const char *path) 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.")) if (!prefixcmp(var, "submodule."))
return parse_submodule_config_option(var, value); 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; return 0;
} }
@ -229,8 +234,14 @@ void show_submodule_summary(FILE *f, const char *path,
strbuf_release(&sb); 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, 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; int i, result = 0, argc = 0;
struct child_process cp; struct child_process cp;
@ -271,6 +282,11 @@ int fetch_populated_submodules(int num_options, const char **options,
if (name_for_path) if (name_for_path)
name = name_for_path->util; 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_path, "%s/%s", work_tree, ce->name);
strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf); strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
strbuf_addf(&submodule_prefix, "%s%s/", prefix, ce->name); strbuf_addf(&submodule_prefix, "%s%s/", prefix, ce->name);

View File

@ -13,8 +13,10 @@ void show_submodule_summary(FILE *f, const char *path,
unsigned char one[20], unsigned char two[20], unsigned char one[20], unsigned char two[20],
unsigned dirty_submodule, unsigned dirty_submodule,
const char *del, const char *add, const char *reset); 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, 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); 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], 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]); const unsigned char a[20], const unsigned char b[20]);

View File

@ -106,4 +106,40 @@ test_expect_success "--dry-run propagates to submodules" '
test_cmp expect.err actual.err 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 test_done