submodule: correct remote name with fetch
The code fetches the submodules remote based on the superproject remote name instead of the submodule remote name[1]. Instead of grabbing the default remote of the superproject repository, ask the default remote of the submodule we are going to run 'git fetch' in. 1. https://lore.kernel.org/git/ZJR5SPDj4Wt_gmRO@pweza/ Signed-off-by: Daniel Black <daniel@mariadb.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Daniel Black committed
Oct 9, 2024 at 14:32 UTC
0c1a9987da0507050d9dba2adba208d14b944b3a
2 files changed
+28
-1
builtin/submodule--helper.c
+8
-1
@@ -2333,7 +2333,14 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet,
2333
strvec_pushf(&cp.args, "--depth=%d", depth);
2334
if (oid) {
2335
char *hex = oid_to_hex(oid);
2336
- char *remote = get_default_remote();
2336
+ char *remote;
2337
+ int code;
2338
+
2339
+ code = get_default_remote_submodule(module_path, &remote);
2340
+ if (code) {
2341
+ child_process_clear(&cp);
2342
+ return code;
2343
+ }
2344
2345
strvec_pushl(&cp.args, remote, hex, NULL);
2346
free(remote);
t/t5572-pull-submodule.sh
+20
@@ -230,6 +230,7 @@ test_expect_success 'branch has no merge base with remote-tracking counterpart'
230
231
test_create_repo a-submodule &&
232
test_commit -C a-submodule foo &&
233
+ test_commit -C a-submodule bar &&
234
235
test_create_repo parent &&
236
git -C parent submodule add "$(pwd)/a-submodule" &&
@@ -246,4 +247,23 @@ test_expect_success 'branch has no merge base with remote-tracking counterpart'
247
git -C child pull --recurse-submodules --rebase
248
'
249
250
+test_expect_success 'fetch submodule remote of different name from superproject' '
251
+ git -C child remote rename origin o1 &&
252
+ git -C child submodule update --init &&
253
+
254
+ # Needs to create unreachable commit from current master branch.
255
+ git -C a-submodule checkout -b newmain HEAD^ &&
256
+ test_commit -C a-submodule echo &&
257
+ test_commit -C a-submodule moreecho &&
258
+ subc=$(git -C a-submodule rev-parse --short HEAD) &&
259
+
260
+ git -C parent/a-submodule fetch &&
261
+ git -C parent/a-submodule checkout "$subc" &&
262
+ git -C parent commit -m "update submodule" a-submodule &&
263
+ git -C a-submodule reset --hard HEAD^^ &&
264
+
265
+ git -C child pull --no-recurse-submodules &&
266
+ git -C child submodule update
267
+'
268
+
269
test_done