Skip to content

Commit fa61b77

Browse files
committed
Merge branch 'jc/avoid-redundant-submodule-fetch'
"git fetch --recurse-submodules" from multiple remotes (either from a remote group, or "--all") used to make one extra "git fetch" in the submodules, which has been corrected. * jc/avoid-redundant-submodule-fetch: fetch: do not run a redundant fetch from submodule
2 parents 5ed49a7 + 0353c68 commit fa61b77

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

builtin/fetch.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
21882188
else if (argc > 1)
21892189
die(_("fetch --all does not make sense with refspecs"));
21902190
(void) for_each_remote(get_one_remote_for_fetch, &list);
2191+
2192+
/* do not do fetch_multiple() of one */
2193+
if (list.nr == 1)
2194+
remote = remote_get(list.items[0].string);
21912195
} else if (argc == 0) {
21922196
/* No arguments -- use default remote */
21932197
remote = remote_get(NULL);
@@ -2262,7 +2266,17 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
22622266
result = fetch_multiple(&list, max_children);
22632267
}
22642268

2265-
if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) {
2269+
2270+
/*
2271+
* This is only needed after fetch_one(), which does not fetch
2272+
* submodules by itself.
2273+
*
2274+
* When we fetch from multiple remotes, fetch_multiple() has
2275+
* already updated submodules to grab commits necessary for
2276+
* the fetched history from each remote, so there is no need
2277+
* to fetch submodules from here.
2278+
*/
2279+
if (!result && remote && (recurse_submodules != RECURSE_SUBMODULES_OFF)) {
22662280
struct strvec options = STRVEC_INIT;
22672281
int max_children = max_jobs;
22682282

t/t5526-fetch-submodules.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,4 +1125,31 @@ test_expect_success 'fetch --recurse-submodules updates name-conflicted, unpopul
11251125
)
11261126
'
11271127

1128+
test_expect_success 'fetch --all with --recurse-submodules' '
1129+
test_when_finished "rm -fr src_clone" &&
1130+
git clone --recurse-submodules src src_clone &&
1131+
(
1132+
cd src_clone &&
1133+
git config submodule.recurse true &&
1134+
git config fetch.parallel 0 &&
1135+
git fetch --all 2>../fetch-log
1136+
) &&
1137+
grep "^Fetching submodule sub$" fetch-log >fetch-subs &&
1138+
test_line_count = 1 fetch-subs
1139+
'
1140+
1141+
test_expect_success 'fetch --all with --recurse-submodules with multiple' '
1142+
test_when_finished "rm -fr src_clone" &&
1143+
git clone --recurse-submodules src src_clone &&
1144+
(
1145+
cd src_clone &&
1146+
git remote add secondary ../src &&
1147+
git config submodule.recurse true &&
1148+
git config fetch.parallel 0 &&
1149+
git fetch --all 2>../fetch-log
1150+
) &&
1151+
grep "Fetching submodule sub" fetch-log >fetch-subs &&
1152+
test_line_count = 2 fetch-subs
1153+
'
1154+
11281155
test_done

0 commit comments

Comments
 (0)