Skip to content

Commit 6e0b224

Browse files
grooverdandscho
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b303d03 commit 6e0b224

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

builtin/submodule--helper.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,14 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet,
23332333
strvec_pushf(&cp.args, "--depth=%d", depth);
23342334
if (oid) {
23352335
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+
}
23372344

23382345
strvec_pushl(&cp.args, remote, hex, NULL);
23392346
free(remote);

t/t5572-pull-submodule.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ test_expect_success 'branch has no merge base with remote-tracking counterpart'
230230
231231
test_create_repo a-submodule &&
232232
test_commit -C a-submodule foo &&
233+
test_commit -C a-submodule bar &&
233234
234235
test_create_repo parent &&
235236
git -C parent submodule add "$(pwd)/a-submodule" &&
@@ -246,4 +247,23 @@ test_expect_success 'branch has no merge base with remote-tracking counterpart'
246247
git -C child pull --recurse-submodules --rebase
247248
'
248249

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+
249269
test_done

0 commit comments

Comments
 (0)