Commit 42e0bed2 by kdj0c Committed by Patrick Steinhardt

Fix git_submodule_sync with relative url

git_submodule_sync should resolve submodule before writing to .git/config
to have the same behavior as git_submodule_init, which does the right thing.
parent 2f6f10bb
...@@ -1422,7 +1422,7 @@ int git_submodule_sync(git_submodule *sm) ...@@ -1422,7 +1422,7 @@ int git_submodule_sync(git_submodule *sm)
{ {
int error = 0; int error = 0;
git_config *cfg = NULL; git_config *cfg = NULL;
git_buf key = GIT_BUF_INIT; git_buf key = GIT_BUF_INIT, effective_submodule_url = GIT_BUF_INIT;
git_repository *smrepo = NULL; git_repository *smrepo = NULL;
if (!sm->url) { if (!sm->url) {
...@@ -1434,8 +1434,9 @@ int git_submodule_sync(git_submodule *sm) ...@@ -1434,8 +1434,9 @@ int git_submodule_sync(git_submodule *sm)
/* copy URL over to config only if it already exists */ /* copy URL over to config only if it already exists */
if (!(error = git_repository_config__weakptr(&cfg, sm->repo)) && if (!(error = git_repository_config__weakptr(&cfg, sm->repo)) &&
!(error = git_buf_printf(&key, "submodule.%s.url", sm->name))) !(error = git_buf_printf(&key, "submodule.%s.url", sm->name)) &&
error = git_config__update_entry(cfg, key.ptr, sm->url, true, true); !(error = git_submodule_resolve_url(&effective_submodule_url, sm->repo, sm->url)))
error = git_config__update_entry(cfg, key.ptr, effective_submodule_url.ptr, true, true);
/* if submodule exists in the working directory, update remote url */ /* if submodule exists in the working directory, update remote url */
...@@ -1457,12 +1458,13 @@ int git_submodule_sync(git_submodule *sm) ...@@ -1457,12 +1458,13 @@ int git_submodule_sync(git_submodule *sm)
} }
if (!error) if (!error)
error = git_config__update_entry(cfg, key.ptr, sm->url, true, false); error = git_config__update_entry(cfg, key.ptr, effective_submodule_url.ptr, true, false);
git_repository_free(smrepo); git_repository_free(smrepo);
} }
git_buf_dispose(&key); git_buf_dispose(&key);
git_buf_dispose(&effective_submodule_url);
return error; return error;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment