/* When looking at the short name for a submodule, we need to prevent * people from overwriting the `.git` file in the submodule working * directory itself. We don't want to look at the actual repository * path, since it will be in the super's repository above us, and * typically named with the name of our subrepository. Consequently, * preventing access to the short name of the actual repository path * would prevent us from creating files with the same name as the * subrepo. (Eg, a submodule named "libgit2" could not contain a file * named "libgit2", which would be unfortunate.) */ void test_repo_reservedname__submodule_pointer(void) { #ifdef GIT_WIN32 git_repository *super_repo, *sub_repo; git_submodule *sub; git_buf *sub_reserved; size_t sub_reserved_len; if (!cl_sandbox_supports_8dot3()) clar__skip(); super_repo = setup_fixture_submod2(); assert_submodule_exists(super_repo, "sm_unchanged"); cl_git_pass(git_submodule_lookup(&sub, super_repo, "sm_unchanged")); cl_git_pass(git_submodule_open(&sub_repo, sub)); cl_assert(git_repository__reserved_names(&sub_reserved, &sub_reserved_len, sub_repo, true)); cl_assert_equal_i(2, sub_reserved_len); cl_assert_equal_s(".git", sub_reserved[0].ptr); cl_assert_equal_s("GIT~1", sub_reserved[1].ptr); git_submodule_free(sub); git_repository_free(sub_repo); #endif }
static void add_submodule_with_commit(const char *name) { git_submodule *sm; git_repository *smrepo; git_index *idx; git_buf p = GIT_BUF_INIT; cl_git_pass(git_submodule_add_setup(&sm, g_repo, "https://github.com/libgit2/libgit2.git", name, 1)); assert_submodule_exists(g_repo, name); cl_git_pass(git_submodule_open(&smrepo, sm)); cl_git_pass(git_repository_index(&idx, smrepo)); cl_git_pass(git_buf_joinpath(&p, git_repository_workdir(smrepo), "file")); cl_git_mkfile(p.ptr, "new file"); git_buf_free(&p); cl_git_pass(git_index_add_bypath(idx, "file")); cl_git_pass(git_index_write(idx)); git_index_free(idx); cl_repo_commit_from_index(NULL, smrepo, NULL, 0, "initial commit"); git_repository_free(smrepo); cl_git_pass(git_submodule_add_finalize(sm)); git_submodule_free(sm); }
static int checksum_submodule (struct TreeWalkData *parent_twdata, git_submodule *sub) { int r = 1; const git_oid *sub_head; struct TreeWalkData child_twdata = { FALSE, parent_twdata->evtag, NULL, NULL, parent_twdata->cancellable, parent_twdata->error }; parent_twdata->evtag->n_submodules++; r = git_submodule_open (&child_twdata.repo, sub); if (!handle_libgit_ret (r, child_twdata.error)) goto out; r = git_repository_odb (&child_twdata.odb, child_twdata.repo); if (!handle_libgit_ret (r, child_twdata.error)) goto out; sub_head = git_submodule_wd_id (sub); if (!checksum_commit_contents (&child_twdata, sub_head, child_twdata.cancellable, child_twdata.error)) goto out; r = 0; out: if (r > 0) child_twdata.caught_error = TRUE; if (child_twdata.repo) git_repository_free (child_twdata.repo); if (child_twdata.odb) git_odb_free (child_twdata.odb); return r; }
static int just_return_repo(git_repository **out, const char *path, int bare, void *payload) { git_submodule *sm = payload; GIT_UNUSED(path); GIT_UNUSED(bare); return git_submodule_open(out, sm); }
static void assert_submodule_url_is_synced( git_submodule *sm, const char *parent_key, const char *child_key) { git_repository *smrepo; assert_config_entry_value(g_repo, parent_key, git_submodule_url(sm)); cl_git_pass(git_submodule_open(&smrepo, sm)); assert_config_entry_value(smrepo, child_key, git_submodule_url(sm)); git_repository_free(smrepo); }
static void assert_submodule_url_is_synced( git_submodule *sm, const char *parent_key, const char *child_key) { git_config *cfg; const char *str; git_repository *smrepo; cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_pass(git_config_get_string(&str, cfg, parent_key)); cl_assert_equal_s(git_submodule_url(sm), str); git_config_free(cfg); cl_git_pass(git_submodule_open(&smrepo, sm)); cl_git_pass(git_repository_config(&cfg, smrepo)); cl_git_pass(git_config_get_string(&str, cfg, child_key)); cl_assert_equal_s(git_submodule_url(sm), str); git_config_free(cfg); git_repository_free(smrepo); }
void test_submodule_open__opening_via_lookup_succeeds(void) { cl_git_pass(git_submodule_lookup(&g_module, g_parent, "sm_unchanged")); cl_git_pass(git_submodule_open(&g_child, g_module)); assert_sm_valid(g_parent, g_child, "sm_unchanged"); }