Skip to content

Commit bb58286

Browse files
committed
Merge branch 'en/submodule-insteadof-remote-match' into seen
The remote-matching logic for submodules has been corrected to resolve 'url.*.insteadOf' aliases before comparing the inventoried URL from '.gitmodules' with the URLs of configured remotes. * en/submodule-insteadof-remote-match: submodule: resolve insteadOf aliases when matching remote
2 parents 7954206 + 2dbd1c8 commit bb58286

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

remote.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,17 +1832,25 @@ const char *repo_default_remote(struct repository *repo)
18321832

18331833
const char *repo_remote_from_url(struct repository *repo, const char *url)
18341834
{
1835+
char *rewritten_url;
1836+
const char *remote_name = NULL;
1837+
18351838
read_config(repo, 0);
1839+
if ((rewritten_url = alias_url(url, &repo->remote_state->rewrites)))
1840+
url = rewritten_url;
18361841

18371842
for (int i = 0; i < repo->remote_state->remotes_nr; i++) {
18381843
struct remote *remote = repo->remote_state->remotes[i];
18391844
if (!remote)
18401845
continue;
18411846

1842-
if (remote_has_url(remote, url))
1843-
return remote->name;
1847+
if (remote_has_url(remote, url)) {
1848+
remote_name = remote->name;
1849+
break;
1850+
}
18441851
}
1845-
return NULL;
1852+
free(rewritten_url);
1853+
return remote_name;
18461854
}
18471855

18481856
int branch_has_merge_config(struct branch *branch)

t/t7406-submodule-update.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,25 @@ test_expect_success 'submodule update --remote should fetch upstream changes' '
256256
)
257257
'
258258

259+
test_expect_success 'submodule update --remote resolves URL rewrites' '
260+
test_config_global "url.$(pwd)/.insteadOf" local: &&
261+
mkdir alias-super alias-submodule &&
262+
(
263+
cd alias-submodule &&
264+
git init &&
265+
git commit --allow-empty --message "Initial commit"
266+
) &&
267+
(
268+
cd alias-super &&
269+
git init &&
270+
git submodule add local:alias-submodule submodule &&
271+
git submodule update --force &&
272+
git -C submodule remote rename origin upstream &&
273+
git -C submodule remote add fork user@host &&
274+
git submodule update --remote
275+
)
276+
'
277+
259278
test_expect_success 'submodule update --remote should fetch upstream changes with .' '
260279
(
261280
cd super &&

0 commit comments

Comments
 (0)