@matheusbsbs / matheus-bagliano / commits / bf42b38405
Fork 0

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 <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Mar 6, 2011 at 23:12 UTC bf42b384058ee2b34f587426d0788353ffa9012a
4 files changed +38 -5
Documentation/config.txt
+1 -1
@@ -1823,7 +1823,7 @@ submodule.<name>.update::
1823 linkgit:git-submodule[1] and linkgit:gitmodules[5] for details.
1824
1825 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
1827 submodule. It can be overridden by using the --[no-]recurse-submodules
1828 command line option to "git fetch" and "git pull".
1829 This setting will override that from in the linkgit:gitmodules[5]
Documentation/gitmodules.txt
+2 -2
@@ -45,12 +45,12 @@ submodule.<name>.update::
45 the '--merge' or '--rebase' options.
46
47 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
49 submodule. If this option is also present in the submodules entry in
50 .git/config of the superproject, the setting there will override the
51 one found in .gitmodules.
52 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".
54
55 submodule.<name>.ignore::
56 Defines under what circumstances "git status" and the diff family show
submodule.c
+7 -2
@@ -113,7 +113,7 @@ int parse_submodule_config_option(const char *var, const char *value)
113 if (!config)
114 config = string_list_append(&config_fetch_recurse_submodules_for_name,
115 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);
117 strbuf_release(&submodname);
118 } else if ((len > 7) && !strcmp(var + len - 7, ".ignore")) {
119 if (strcmp(value, "untracked") && strcmp(value, "dirty") &&
@@ -380,8 +380,13 @@ int fetch_populated_submodules(int num_options, const char **options,
380 struct string_list_item *fetch_recurse_submodules_option;
381 fetch_recurse_submodules_option = unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name, name);
382 if (fetch_recurse_submodules_option) {
383 - if (!fetch_recurse_submodules_option->util)
383 + if ((intptr_t)fetch_recurse_submodules_option->util == RECURSE_SUBMODULES_OFF)
384 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 + }
390 } else {
391 if (config_fetch_recurse_submodules == RECURSE_SUBMODULES_OFF)
392 continue;
t/t5526-fetch-submodules.sh
+28
@@ -400,4 +400,32 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config
400 test_cmp expect.err.2 actual.err
401 '
402
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 +
431 test_done