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

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>

Jens Lehmann committed Nov 11, 2010 at 00:55 UTC be254a0ea99b441a6c514cb8b25cd72357383700
7 files changed +83 -9
Documentation/config.txt
+5
@@ -862,6 +862,11 @@ diff.wordRegex::
862 sequences that match the regular expression are "words", all other
863 characters are *ignorable* whitespace.
864
865 +fetch.recurseSubmodules::
866 + A boolean value which changes the behavior for fetch and pull, the
867 + default is to not recursively fetch populated sumodules unless
868 + configured otherwise.
869 +
870 fetch.unpackLimit::
871 If the number of objects fetched over the git native
872 transfer is below this
Documentation/fetch-options.txt
+3 -2
@@ -60,8 +60,9 @@ endif::git-pull[]
60 flag lets all tags and their associated objects be
61 downloaded.
62
63 ---recurse-submodules::
64 - Use this option to fetch new commits of all populated submodules too.
63 +--[no-]recurse-submodules::
64 + This option controls if new commits of all populated submodules should
65 + be fetched too (see linkgit:git-config[1]).
66
67 ifndef::git-pull[]
68 --submodule-prefix=<path>::
builtin/fetch.c
+16 -5
@@ -28,8 +28,14 @@ enum {
28 TAGS_SET = 2
29 };
30
31 +enum {
32 + RECURSE_SUBMODULES_OFF = 0,
33 + RECURSE_SUBMODULES_DEFAULT = 1,
34 + RECURSE_SUBMODULES_ON = 2
35 +};
36 +
37 static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, verbosity;
32 -static int progress, recurse_submodules;
38 +static int progress, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
39 static int tags = TAGS_DEFAULT;
40 static const char *depth;
41 static const char *upload_pack;
@@ -55,8 +61,9 @@ static struct option builtin_fetch_options[] = {
61 "do not fetch all tags (--no-tags)", TAGS_UNSET),
62 OPT_BOOLEAN('p', "prune", &prune,
63 "prune tracking branches no longer on remote"),
58 - OPT_BOOLEAN(0, "recurse-submodules", &recurse_submodules,
59 - "control recursive fetching of submodules"),
64 + OPT_SET_INT(0, "recurse-submodules", &recurse_submodules,
65 + "control recursive fetching of submodules",
66 + RECURSE_SUBMODULES_ON),
67 OPT_BOOLEAN(0, "dry-run", &dry_run,
68 "dry run"),
69 OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
@@ -795,7 +802,7 @@ static void add_options_to_argv(int *argc, const char **argv)
802 argv[(*argc)++] = "--force";
803 if (keep)
804 argv[(*argc)++] = "--keep";
798 - if (recurse_submodules)
805 + if (recurse_submodules == RECURSE_SUBMODULES_ON)
806 argv[(*argc)++] = "--recurse-submodules";
807 if (verbosity >= 2)
808 argv[(*argc)++] = "-v";
@@ -933,14 +940,18 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
940 }
941 }
942
936 - if (!result && recurse_submodules) {
943 + if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) {
944 const char *options[10];
945 int num_options = 0;
946 + /* Set recursion as default when we already are recursing */
947 + if (submodule_prefix[0])
948 + set_config_fetch_recurse_submodules(1);
949 gitmodules_config();
950 git_config(submodule_config, NULL);
951 add_options_to_argv(&num_options, options);
952 result = fetch_populated_submodules(num_options, options,
953 submodule_prefix,
954 + recurse_submodules == RECURSE_SUBMODULES_ON,
955 verbosity < 0);
956 }
957
git-pull.sh
+3
@@ -108,6 +108,9 @@ do
108 --recurse-submodules)
109 recurse_submodules=--recurse-submodules
110 ;;
111 + --no-recurse-submodules)
112 + recurse_submodules=--no-recurse-submodules
113 + ;;
114 --d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run)
115 dry_run=--dry-run
116 ;;
submodule.c
+17 -1
@@ -11,6 +11,7 @@
11
12 struct string_list config_name_for_path;
13 struct string_list config_ignore_for_name;
14 +static int config_fetch_recurse_submodules;
15
16 static int add_submodule_odb(const char *path)
17 {
@@ -67,6 +68,10 @@ int submodule_config(const char *var, const char *value, void *cb)
68 {
69 if (!prefixcmp(var, "submodule."))
70 return parse_submodule_config_option(var, value);
71 + else if (!strcmp(var, "fetch.recursesubmodules")) {
72 + config_fetch_recurse_submodules = git_config_bool(var, value);
73 + return 0;
74 + }
75 return 0;
76 }
77
@@ -229,8 +234,14 @@ void show_submodule_summary(FILE *f, const char *path,
234 strbuf_release(&sb);
235 }
236
237 +void set_config_fetch_recurse_submodules(int value)
238 +{
239 + config_fetch_recurse_submodules = value;
240 +}
241 +
242 int fetch_populated_submodules(int num_options, const char **options,
233 - const char *prefix, int quiet)
243 + const char *prefix, int ignore_config,
244 + int quiet)
245 {
246 int i, result = 0, argc = 0;
247 struct child_process cp;
@@ -271,6 +282,11 @@ int fetch_populated_submodules(int num_options, const char **options,
282 if (name_for_path)
283 name = name_for_path->util;
284
285 + if (!ignore_config) {
286 + if (!config_fetch_recurse_submodules)
287 + continue;
288 + }
289 +
290 strbuf_addf(&submodule_path, "%s/%s", work_tree, ce->name);
291 strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
292 strbuf_addf(&submodule_prefix, "%s%s/", prefix, ce->name);
submodule.h
+3 -1
@@ -13,8 +13,10 @@ void show_submodule_summary(FILE *f, const char *path,
13 unsigned char one[20], unsigned char two[20],
14 unsigned dirty_submodule,
15 const char *del, const char *add, const char *reset);
16 +void set_config_fetch_recurse_submodules(int value);
17 int fetch_populated_submodules(int num_options, const char **options,
17 - const char *prefix, int quiet);
18 + const char *prefix, int ignore_config,
19 + int quiet);
20 unsigned is_submodule_modified(const char *path, int ignore_untracked);
21 int merge_submodule(unsigned char result[20], const char *path, const unsigned char base[20],
22 const unsigned char a[20], const unsigned char b[20]);
t/t5526-fetch-submodules.sh
+36
@@ -106,4 +106,40 @@ test_expect_success "--dry-run propagates to submodules" '
106 test_cmp expect.err actual.err
107 '
108
109 +test_expect_success "recurseSubmodules=true propagates into submodules" '
110 + add_upstream_commit &&
111 + (
112 + cd downstream &&
113 + git config fetch.recurseSubmodules true
114 + git fetch >../actual.out 2>../actual.err
115 + ) &&
116 + test_cmp expect.out actual.out &&
117 + test_cmp expect.err actual.err
118 +'
119 +
120 +test_expect_success "--recurse-submodules overrides config in submodule" '
121 + add_upstream_commit &&
122 + (
123 + cd downstream &&
124 + (
125 + cd submodule &&
126 + git config fetch.recurseSubmodules false
127 + ) &&
128 + git fetch --recurse-submodules >../actual.out 2>../actual.err
129 + ) &&
130 + test_cmp expect.out actual.out &&
131 + test_cmp expect.err actual.err
132 +'
133 +
134 +test_expect_success "--no-recurse-submodules overrides config setting" '
135 + add_upstream_commit &&
136 + (
137 + cd downstream &&
138 + git config fetch.recurseSubmodules true
139 + git fetch --no-recurse-submodules >../actual.out 2>../actual.err
140 + ) &&
141 + ! test -s actual.out &&
142 + ! test -s actual.err
143 +'
144 +
145 test_done