Skip to content

Commit 1fb2550

Browse files
jlehmanngitster
authored andcommitted
config: teach the fetch.recurseSubmodules option the 'on-demand' value
To enable the user to change the default behavior of "git fetch" and "git pull" regarding submodule recursion add the new "on-demand" value which has just been added to the "--recurse-submodules" command line option. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f0700d commit 1fb2550

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

Documentation/config.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,13 @@ diff.wordRegex::
900900
characters are *ignorable* whitespace.
901901

902902
fetch.recurseSubmodules::
903-
A boolean value which changes the behavior for fetch and pull, the
904-
default is to not recursively fetch populated submodules unless
905-
configured otherwise.
903+
This option can be either set to a boolean value or to 'on-demand'.
904+
Setting it to a boolean changes the behavior of fetch and pull to
905+
unconditionally recurse into submodules when set to true or to not
906+
recurse at all when set to false. When set to 'on-demand' (the default
907+
value), fetch and pull will only recurse into a populated submodule
908+
when its superproject retrieves a commit that updates the submodule's
909+
reference.
906910

907911
fetch.unpackLimit::
908912
If the number of objects fetched over the git native

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int submodule_config(const char *var, const char *value, void *cb)
7171
if (!prefixcmp(var, "submodule."))
7272
return parse_submodule_config_option(var, value);
7373
else if (!strcmp(var, "fetch.recursesubmodules")) {
74-
config_fetch_recurse_submodules = git_config_bool(var, value);
74+
config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
7575
return 0;
7676
}
7777
return 0;

t/t5526-fetch-submodules.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,32 @@ test_expect_success "'--recurse-submodules=on-demand' stops when no new submodul
372372
test_cmp expect.err.file actual.err
373373
'
374374

375+
test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
376+
(
377+
cd downstream &&
378+
git fetch --recurse-submodules
379+
) &&
380+
add_upstream_commit &&
381+
git config --global fetch.recurseSubmodules false &&
382+
head1=$(git rev-parse --short HEAD) &&
383+
git add submodule &&
384+
git commit -m "new submodule" &&
385+
head2=$(git rev-parse --short HEAD) &&
386+
echo "From $pwd/." > expect.err.2 &&
387+
echo " $head1..$head2 master -> origin/master" >> expect.err.2
388+
head -2 expect.err >> expect.err.2 &&
389+
(
390+
cd downstream &&
391+
git config fetch.recurseSubmodules on-demand &&
392+
git fetch >../actual.out 2>../actual.err
393+
) &&
394+
git config --global --unset fetch.recurseSubmodules &&
395+
(
396+
cd downstream &&
397+
git config --unset fetch.recurseSubmodules
398+
) &&
399+
test_cmp expect.out.sub actual.out &&
400+
test_cmp expect.err.2 actual.err
401+
'
402+
375403
test_done

0 commit comments

Comments
 (0)