void test_submodule_repository_init__basic(void) { git_submodule *sm; git_repository *repo; git_buf dot_git_content = GIT_BUF_INIT; g_repo = setup_fixture_submod2(); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only")); cl_git_pass(git_submodule_init(sm, 0)); cl_git_pass(git_submodule_repo_init(&repo, sm, 1)); /* Verify worktree */ assert_config_entry_value(repo, "core.worktree", "../../../sm_gitmodules_only/"); /* Verify gitlink */ cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_gitmodules_only" "/.git")); cl_assert_equal_s("gitdir: ../.git/modules/sm_gitmodules_only/", dot_git_content.ptr); cl_assert(git_path_isfile("submod2/" "sm_gitmodules_only" "/.git")); cl_assert(git_path_isdir("submod2/.git/modules")); cl_assert(git_path_isdir("submod2/.git/modules/" "sm_gitmodules_only")); cl_assert(git_path_isfile("submod2/.git/modules/" "sm_gitmodules_only" "/HEAD")); git_submodule_free(sm); git_repository_free(repo); git_buf_free(&dot_git_content); }
static int init_one_submodule( git_submodule *sm, const char *name, void *payload) { GIT_UNUSED(name); GIT_UNUSED(payload); return git_submodule_init(sm, false); }
void test_submodule_init__relative_url(void) { git_submodule *sm; git_config *cfg; git_buf absolute_url = GIT_BUF_INIT; const char *config_url; g_repo = setup_fixture_submodule_simple(); 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_snapshot(&cfg, g_repo)); cl_git_pass(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); git_submodule_free(sm); }
void test_submodule_update__update_submodule(void) { git_submodule *sm; git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; unsigned int submodule_status = 0; struct update_submodule_cb_payload update_payload = { 0 }; g_repo = setup_fixture_submodule_simple(); update_options.checkout_opts.progress_cb = checkout_progress_cb; update_options.checkout_opts.progress_payload = &update_payload; update_options.remote_callbacks.update_tips = update_tips; update_options.remote_callbacks.payload = &update_payload; /* get the submodule */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); /* verify the initial state of the submodule */ cl_git_pass(git_submodule_status(&submodule_status, sm)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_WD_UNINITIALIZED); /* initialize and update the submodule */ cl_git_pass(git_submodule_init(sm, 0)); cl_git_pass(git_submodule_update(sm, 0, &update_options)); /* verify state */ cl_git_pass(git_submodule_status(&submodule_status, sm)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_IN_WD); cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); /* verify that the expected callbacks have been called. */ cl_assert_equal_i(1, update_payload.checkout_progress_called); cl_assert_equal_i(1, update_payload.update_tips_called); git_submodule_free(sm); }
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))); 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_snapshot(&cfg, g_repo)); cl_git_pass(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); git_object_free(head_commit); git_reference_free(head_ref); git_submodule_free(sm); }