Skip to content

Commit

Permalink
Merge branch 'db/submodule-fetch-with-remote-name-fix' into next
Browse files Browse the repository at this point in the history
A "git fetch" from the superproject going down to a submodule used
a wrong remote when the default remote names are set differently
between them.

* db/submodule-fetch-with-remote-name-fix:
  submodule: correct remote name with fetch
  • Loading branch information
ttaylorr authored and dscho committed Oct 21, 2024
2 parents ffd5653 + 758abb9 commit fe0f4bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion builtin/submodule--helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,14 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet,
strvec_pushf(&cp.args, "--depth=%d", depth);
if (oid) {
char *hex = oid_to_hex(oid);
char *remote = get_default_remote();
char *remote;
int code;

code = get_default_remote_submodule(module_path, &remote);
if (code) {
child_process_clear(&cp);
return code;
}

strvec_pushl(&cp.args, remote, hex, NULL);
free(remote);
Expand Down
20 changes: 20 additions & 0 deletions t/t5572-pull-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ test_expect_success 'branch has no merge base with remote-tracking counterpart'
test_create_repo a-submodule &&
test_commit -C a-submodule foo &&
test_commit -C a-submodule bar &&
test_create_repo parent &&
git -C parent submodule add "$(pwd)/a-submodule" &&
Expand All @@ -246,4 +247,23 @@ test_expect_success 'branch has no merge base with remote-tracking counterpart'
git -C child pull --recurse-submodules --rebase
'

test_expect_success 'fetch submodule remote of different name from superproject' '
git -C child remote rename origin o1 &&
git -C child submodule update --init &&
# Needs to create unreachable commit from current master branch.
git -C a-submodule checkout -b newmain HEAD^ &&
test_commit -C a-submodule echo &&
test_commit -C a-submodule moreecho &&
subc=$(git -C a-submodule rev-parse --short HEAD) &&
git -C parent/a-submodule fetch &&
git -C parent/a-submodule checkout "$subc" &&
git -C parent commit -m "update submodule" a-submodule &&
git -C a-submodule reset --hard HEAD^^ &&
git -C child pull --no-recurse-submodules &&
git -C child submodule update
'

test_done

0 comments on commit fe0f4bc

Please sign in to comment.