summaryrefslogtreecommitdiff
path: root/tests/submodule/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/submodule/init.c')
-rw-r--r--tests/submodule/init.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/submodule/init.c b/tests/submodule/init.c
index c03bf4610..d07bc9a5b 100644
--- a/tests/submodule/init.c
+++ b/tests/submodule/init.c
@@ -71,3 +71,41 @@ void test_submodule_init__relative_url(void)
git_buf_free(&absolute_url);
git_config_free(cfg);
}
+
+void test_submodule_init__relative_url_detached_head(void)
+{
+ git_submodule *sm;
+ git_config *cfg;
+ git_buf absolute_url = GIT_BUF_INIT;
+ const char *config_url;
+ git_reference *head_ref = NULL;
+ git_object *head_commit = NULL;
+
+ g_repo = setup_fixture_submodule_simple();
+
+ /* Put the parent repository into a detached head state. */
+ cl_git_pass(git_repository_head(&head_ref, g_repo));
+ cl_git_pass(git_reference_peel(&head_commit, head_ref, GIT_OBJ_COMMIT));
+
+ cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit), NULL, NULL));
+
+ cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
+ cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
+ /* verify that the .gitmodules is set with an absolute path*/
+ cl_assert_equal_s("../testrepo.git", git_submodule_url(sm));
+
+ /* init and verify that absolute path is written to .git/config */
+ cl_git_pass(git_submodule_init(sm, false));
+
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+
+ git_config_get_string(&config_url, cfg, "submodule.testrepo.url");
+ cl_assert_equal_s(absolute_url.ptr, config_url);
+
+ git_buf_free(&absolute_url);
+ git_config_free(cfg);
+
+}