summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJameson Miller <jamill@microsoft.com>2014-10-20 18:07:32 -0400
committerJameson Miller <jamill@microsoft.com>2014-12-22 16:35:45 -0500
commitb2ab887e1137207edb286812a3237b351ab39506 (patch)
tree38f060dd5fbe37fc6f1f7f0a34b3cc331b806930 /src
parent0bb237ed89a6700a1b6b884444ff044fd1467535 (diff)
downloadlibgit2-b2ab887e1137207edb286812a3237b351ab39506.tar.gz
submodule init should resolve relative url paths
Submodule init should handle relative paths in .gitmodules files and resolve these urls when updating the git config file.
Diffstat (limited to 'src')
-rw-r--r--src/submodule.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/submodule.c b/src/submodule.c
index 8dca0ae73..d2af1440a 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -381,10 +381,6 @@ int git_submodule_add_setup(
return GIT_EEXISTS;
}
- /* resolve parameters */
- if ((error = git_submodule_resolve_url(&real_url, repo, url)) < 0)
- goto cleanup;
-
/* validate and normalize path */
if (git__prefixcmp(path, git_repository_workdir(repo)) == 0)
@@ -409,7 +405,7 @@ int git_submodule_add_setup(
goto cleanup;
if ((error = submodule_config_key_trunc_puts(&name, "url")) < 0 ||
- (error = git_config_file_set_string(mods, name.ptr, real_url.ptr)) < 0)
+ (error = git_config_file_set_string(mods, name.ptr, url)) < 0)
goto cleanup;
git_buf_clear(&name);
@@ -425,7 +421,12 @@ int git_submodule_add_setup(
*/
if (!(git_path_exists(name.ptr) &&
git_path_contains(&name, DOT_GIT))) {
- if ((error = submodule_repo_init(&subrepo, repo, path, real_url.ptr, use_gitlink)) < 0)
+
+ /* resolve the actual URL to use */
+ if ((error = git_submodule_resolve_url(&real_url, repo, url)) < 0)
+ goto cleanup;
+
+ if ((error = submodule_repo_init(&subrepo, repo, path, real_url.ptr, use_gitlink)) < 0)
goto cleanup;
}
@@ -466,13 +467,24 @@ int git_submodule_repo_init(
{
int error;
git_repository *sub_repo = NULL;
+ const char *configured_url;
+ git_config *cfg = NULL;
+ git_buf buf = GIT_BUF_INIT;
assert(out && sm);
- error = submodule_repo_init(&sub_repo, sm->repo, sm->path, sm->url, use_gitlink);
+ /* get the configured remote url of the submodule */
+ if ((error = git_buf_printf(&buf, "submodule.%s.url", sm->name)) < 0 ||
+ (error = git_repository_config(&cfg, sm->repo)) < 0 ||
+ (error = git_config_get_string(&configured_url, cfg, buf.ptr)) < 0 ||
+ (error = submodule_repo_init(&sub_repo, sm->repo, sm->path, configured_url, use_gitlink)) < 0)
+ goto done;
*out = sub_repo;
+done:
+ git_config_free(cfg);
+ git_buf_free(&buf);
return error;
}
@@ -827,7 +839,7 @@ int git_submodule_init(git_submodule *sm, int overwrite)
{
int error;
const char *val;
- git_buf key = GIT_BUF_INIT;
+ git_buf key = GIT_BUF_INIT, effective_submodule_url = GIT_BUF_INIT;
git_config *cfg = NULL;
if (!sm->url) {
@@ -841,9 +853,10 @@ int git_submodule_init(git_submodule *sm, int overwrite)
/* write "submodule.NAME.url" */
- if ((error = git_buf_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
+ if ((git_submodule_resolve_url(&effective_submodule_url, sm->repo, sm->url)) < 0 ||
+ (error = git_buf_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
(error = git_config__update_entry(
- cfg, key.ptr, sm->url, overwrite != 0, false)) < 0)
+ cfg, key.ptr, effective_submodule_url.ptr, overwrite != 0, false)) < 0)
goto cleanup;
/* write "submodule.NAME.update" if not default */
@@ -861,6 +874,7 @@ int git_submodule_init(git_submodule *sm, int overwrite)
cleanup:
git_config_free(cfg);
git_buf_free(&key);
+ git_buf_free(&effective_submodule_url);
return error;
}