Skip to content

Commit bf42b38

Browse files
jlehmanngitster
authored andcommitted
Submodules: Add 'on-demand' value for the 'fetchRecurseSubmodule' option
Now the behavior of fetch and pull can be configured to the recently added 'on-demand' mode separately for each submodule too. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1fb2550 commit bf42b38

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

Documentation/config.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ submodule.<name>.update::
18231823
linkgit:git-submodule[1] and linkgit:gitmodules[5] for details.
18241824

18251825
submodule.<name>.fetchRecurseSubmodules::
1826-
This option can be used to enable/disable recursive fetching of this
1826+
This option can be used to control recursive fetching of this
18271827
submodule. It can be overridden by using the --[no-]recurse-submodules
18281828
command line option to "git fetch" and "git pull".
18291829
This setting will override that from in the linkgit:gitmodules[5]

Documentation/gitmodules.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ submodule.<name>.update::
4545
the '--merge' or '--rebase' options.
4646

4747
submodule.<name>.fetchRecurseSubmodules::
48-
This option can be used to enable/disable recursive fetching of this
48+
This option can be used to control recursive fetching of this
4949
submodule. If this option is also present in the submodules entry in
5050
.git/config of the superproject, the setting there will override the
5151
one found in .gitmodules.
5252
Both settings can be overridden on the command line by using the
53-
"--[no-]recurse-submodules" option to "git fetch" and "git pull"..
53+
"--[no-]recurse-submodules" option to "git fetch" and "git pull".
5454

5555
submodule.<name>.ignore::
5656
Defines under what circumstances "git status" and the diff family show

submodule.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int parse_submodule_config_option(const char *var, const char *value)
113113
if (!config)
114114
config = string_list_append(&config_fetch_recurse_submodules_for_name,
115115
strbuf_detach(&submodname, NULL));
116-
config->util = git_config_bool(var, value) ? (void *)1 : NULL;
116+
config->util = (void *)(intptr_t)parse_fetch_recurse_submodules_arg(var, value);
117117
strbuf_release(&submodname);
118118
} else if ((len > 7) && !strcmp(var + len - 7, ".ignore")) {
119119
if (strcmp(value, "untracked") && strcmp(value, "dirty") &&
@@ -380,8 +380,13 @@ int fetch_populated_submodules(int num_options, const char **options,
380380
struct string_list_item *fetch_recurse_submodules_option;
381381
fetch_recurse_submodules_option = unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name, name);
382382
if (fetch_recurse_submodules_option) {
383-
if (!fetch_recurse_submodules_option->util)
383+
if ((intptr_t)fetch_recurse_submodules_option->util == RECURSE_SUBMODULES_OFF)
384384
continue;
385+
if ((intptr_t)fetch_recurse_submodules_option->util == RECURSE_SUBMODULES_ON_DEMAND) {
386+
if (!unsorted_string_list_lookup(&changed_submodule_paths, ce->name))
387+
continue;
388+
default_argv = "on-demand";
389+
}
385390
} else {
386391
if (config_fetch_recurse_submodules == RECURSE_SUBMODULES_OFF)
387392
continue;

t/t5526-fetch-submodules.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,32 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config
400400
test_cmp expect.err.2 actual.err
401401
'
402402

403+
test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
404+
(
405+
cd downstream &&
406+
git fetch --recurse-submodules
407+
) &&
408+
add_upstream_commit &&
409+
git config fetch.recurseSubmodules false &&
410+
head1=$(git rev-parse --short HEAD) &&
411+
git add submodule &&
412+
git commit -m "new submodule" &&
413+
head2=$(git rev-parse --short HEAD) &&
414+
echo "From $pwd/." > expect.err.2 &&
415+
echo " $head1..$head2 master -> origin/master" >> expect.err.2
416+
head -2 expect.err >> expect.err.2 &&
417+
(
418+
cd downstream &&
419+
git config submodule.submodule.fetchRecurseSubmodules on-demand &&
420+
git fetch >../actual.out 2>../actual.err
421+
) &&
422+
git config --unset fetch.recurseSubmodules &&
423+
(
424+
cd downstream &&
425+
git config --unset submodule.submodule.fetchRecurseSubmodules
426+
) &&
427+
test_cmp expect.out.sub actual.out &&
428+
test_cmp expect.err.2 actual.err
429+
'
430+
403431
test_done

0 commit comments

Comments
 (0)