Commit 42e0bed26ea62cbd3b69ba6d31686c21aa5bb12d

kdj0c 2019-12-05T10:43:17

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.

diff --git a/src/submodule.c b/src/submodule.c
index d12dbcf..78ce7c7 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1422,7 +1422,7 @@ int git_submodule_sync(git_submodule *sm)
 {
 	int error = 0;
 	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;
 
 	if (!sm->url) {
@@ -1434,8 +1434,9 @@ int git_submodule_sync(git_submodule *sm)
 	/* copy URL over to config only if it already exists */
 
 	if (!(error = git_repository_config__weakptr(&cfg, sm->repo)) &&
-		!(error = git_buf_printf(&key, "submodule.%s.url", sm->name)))
-		error = git_config__update_entry(cfg, key.ptr, sm->url, true, true);
+		!(error = git_buf_printf(&key, "submodule.%s.url", sm->name)) &&
+		!(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 */
 
@@ -1457,12 +1458,13 @@ int git_submodule_sync(git_submodule *sm)
 		}
 
 		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_buf_dispose(&key);
+	git_buf_dispose(&effective_submodule_url);
 
 	return error;
 }