static void setup_submodules(void) { g_repo = cl_git_sandbox_init("submodules"); cl_fixture_sandbox("testrepo.git"); rewrite_gitmodules(git_repository_workdir(g_repo)); p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git"); }
static const char *template_sandbox(const char *name) { git_buf hooks_path = GIT_BUF_INIT, link_path = GIT_BUF_INIT, dotfile_path = GIT_BUF_INIT; const char *path = cl_fixture(name); cl_fixture_sandbox(name); /* create a symlink from link.sample to update.sample if the filesystem * supports it. */ cl_git_pass(git_buf_joinpath(&hooks_path, name, "hooks")); cl_git_pass(git_buf_joinpath(&link_path, hooks_path.ptr, "link.sample")); #ifdef GIT_WIN32 cl_git_mkfile(link_path.ptr, "#!/bin/sh\necho hello, world\n"); #else cl_must_pass(symlink("update.sample", link_path.ptr)); #endif /* create a file starting with a dot */ cl_git_pass(git_buf_joinpath(&dotfile_path, hooks_path.ptr, ".dotfile")); cl_git_mkfile(dotfile_path.ptr, "something\n"); git_buf_free(&dotfile_path); git_buf_free(&dotfile_path); git_buf_free(&link_path); git_buf_free(&hooks_path); return path; }
void test_checkout_typechange__initialize(void) { g_repo = cl_git_sandbox_init("typechanges"); cl_fixture_sandbox("submod2_target"); p_rename("submod2_target/.gitted", "submod2_target/.git"); }
void test_sample__2(void) { cl_fixture_sandbox("test"); cl_assert(file_size("test/nonexistent") == -1); cl_assert(file_size("test/file") > 0); }
void test_diff_workdir__submodules(void) { const char *a_commit = "873585b94bdeabccea991ea5e3ec1a277895b698"; git_tree *a; git_diff_options opts = {0}; git_diff_list *diff = NULL; diff_expects exp; g_repo = cl_git_sandbox_init("submod2"); cl_fixture_sandbox("submod2_target"); p_rename("submod2_target/.gitted", "submod2_target/.git"); rewrite_gitmodules(git_repository_workdir(g_repo)); p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git"); cl_fixture_cleanup("submod2_target"); a = resolve_commit_oid_to_tree(g_repo, a_commit); opts.flags = GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_RECURSE_UNTRACKED_DIRS | GIT_DIFF_INCLUDE_UNTRACKED_CONTENT; cl_git_pass(git_diff_workdir_to_tree(g_repo, &opts, a, &diff)); /* diff_print(stderr, diff); */ /* essentially doing: git diff 873585b94bdeabccea991ea5e3ec1a277895b698 */ memset(&exp, 0, sizeof(exp)); cl_git_pass(git_diff_foreach( diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); /* the following differs from "git diff 873585" by one "untracked" file * because the diff list includes the "not_submodule/" directory which * is not displayed in the text diff. */ cl_assert_equal_i(10, exp.files); cl_assert_equal_i(0, exp.file_adds); cl_assert_equal_i(0, exp.file_dels); cl_assert_equal_i(1, exp.file_mods); cl_assert_equal_i(0, exp.file_ignored); cl_assert_equal_i(9, exp.file_untracked); /* the following numbers match "git diff 873585" exactly */ cl_assert_equal_i(9, exp.hunks); cl_assert_equal_i(33, exp.lines); cl_assert_equal_i(2, exp.line_ctxt); cl_assert_equal_i(30, exp.line_adds); cl_assert_equal_i(1, exp.line_dels); git_diff_list_free(diff); git_tree_free(a); }
git_repository *cl_git_sandbox_init(const char *sandbox) { /* Copy the whole sandbox folder from our fixtures to our test sandbox * area. After this it can be accessed with `./sandbox` */ cl_fixture_sandbox(sandbox); _cl_sandbox = sandbox; cl_git_pass(p_chdir(sandbox)); /* If this is not a bare repo, then rename `sandbox/.gitted` to * `sandbox/.git` which must be done since we cannot store a folder * named `.git` inside the fixtures folder of our libgit2 repo. */ if (p_access(".gitted", F_OK) == 0) cl_git_pass(cl_rename(".gitted", ".git")); /* If we have `gitattributes`, rename to `.gitattributes`. This may * be necessary if we don't want the attributes to be applied in the * libgit2 repo, but just during testing. */ if (p_access("gitattributes", F_OK) == 0) cl_git_pass(cl_rename("gitattributes", ".gitattributes")); /* As with `gitattributes`, we may need `gitignore` just for testing. */ if (p_access("gitignore", F_OK) == 0) cl_git_pass(cl_rename("gitignore", ".gitignore")); cl_git_pass(p_chdir("..")); /* Now open the sandbox repository and make it available for tests */ cl_git_pass(git_repository_open(&_cl_repo, sandbox)); return _cl_repo; }
void test_network_remote_local__update_tips_for_new_remote(void) { git_repository *src_repo; git_repository *dst_repo; git_remote *new_remote; git_reference* branch; /* Copy test repo */ cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&src_repo, "testrepo.git")); /* Set up an empty bare repo to push into */ cl_git_pass(git_repository_init(&dst_repo, "./localbare.git", 1)); /* Push to bare repo */ cl_git_pass(git_remote_create(&new_remote, src_repo, "bare", "./localbare.git")); cl_git_pass(git_remote_push(new_remote, &push_array, NULL)); /* Make sure remote branch has been created */ cl_git_pass(git_branch_lookup(&branch, src_repo, "bare/master", GIT_BRANCH_REMOTE)); git_reference_free(branch); git_remote_free(new_remote); git_repository_free(dst_repo); cl_fixture_cleanup("localbare.git"); git_repository_free(src_repo); cl_fixture_cleanup("testrepo.git"); }
void test_refs_listall__from_repository_opened_through_workdir_path(void) { cl_fixture_sandbox("status"); cl_git_pass(p_rename("status/.gitted", "status/.git")); ensure_no_refname_starts_with_a_forward_slash("status"); cl_fixture_cleanup("status"); }
void test_network_remotes__initialize(void) { cl_fixture_sandbox(REPOSITORY_FOLDER); cl_git_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); cl_git_pass(git_repository_config(&cfg, repo, NULL, NULL)); cl_git_pass(git_remote_get(&remote, cfg, "test")); refspec = git_remote_fetchspec(remote); cl_assert(refspec != NULL); }
void test_network_remotes__initialize(void) { cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&_repo, "testrepo.git")); cl_git_pass(git_remote_load(&_remote, _repo, "test")); _refspec = git_remote_fetchspec(_remote); cl_assert(_refspec != NULL); }
void test_refs_branches_listall__initialize(void) { git_oid id; cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&repo, "testrepo.git")); cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); cl_git_pass(git_reference_create_oid(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0)); }
void test_repo_config__initialize(void) { cl_fixture_sandbox("empty_standard_repo"); cl_git_pass(cl_rename( "empty_standard_repo/.gitted", "empty_standard_repo/.git")); git_buf_clear(&path); cl_must_pass(p_mkdir("alternate", 0777)); cl_git_pass(git_path_prettify(&path, "alternate", NULL)); }
static void setup_submodules2(void) { g_repo = cl_git_sandbox_init("submod2"); cl_fixture_sandbox("submod2_target"); p_rename("submod2_target/.gitted", "submod2_target/.git"); rewrite_gitmodules(git_repository_workdir(g_repo)); p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git"); p_rename("submod2/not/.gitted", "submod2/not/.git"); }
void test_submodule_modify__initialize(void) { g_repo = cl_git_sandbox_init("submod2"); cl_fixture_sandbox("submod2_target"); p_rename("submod2_target/.gitted", "submod2_target/.git"); /* must create submod2_target before rewrite so prettify will work */ rewrite_gitmodules(git_repository_workdir(g_repo)); p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git"); }
void test_attr_repo__initialize(void) { /* Before each test, instantiate the attr repo from the fixtures and * rename the .gitted to .git so it is a repo with a working dir. * Also rename gitattributes to .gitattributes, because it contains * macro definitions which are only allowed in the root. */ cl_fixture_sandbox("attr"); cl_git_pass(p_rename("attr/.gitted", "attr/.git")); cl_git_pass(p_rename("attr/gitattributes", "attr/.gitattributes")); cl_git_pass(git_repository_open(&g_repo, "attr/.git")); }
void test_network_createremotethenload__initialize(void) { cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&_repo, "testrepo.git")); cl_git_pass(git_repository_config(&_config, _repo)); cl_git_pass(git_config_set_string(_config, "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*")); cl_git_pass(git_config_set_string(_config, "remote.origin.url", url)); git_config_free(_config); cl_git_pass(git_remote_load(&_remote, _repo, "origin")); }
git_repository *setup_fixture_submodule_simple(void) { git_repository *repo = cl_git_sandbox_init("submodule_simple"); cl_fixture_sandbox("testrepo.git"); p_mkdir("submodule_simple/testrepo", 0777); cl_set_cleanup(cleanup_fixture_submodules, "testrepo.git"); cl_git_pass(git_repository_reinit_filesystem(repo, 1)); return repo; }
git_repository *setup_fixture_submodules(void) { git_repository *repo = cl_git_sandbox_init("submodules"); cl_fixture_sandbox("testrepo.git"); rewrite_gitmodules(git_repository_workdir(repo)); p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git"); cl_set_cleanup(cleanup_fixture_submodules, "testrepo.git"); cl_git_pass(git_repository_reinit_filesystem(repo, 1)); return repo; }
git_repository *setup_fixture_super(void) { git_repository *repo = cl_git_sandbox_init("super"); cl_fixture_sandbox("sub.git"); p_mkdir("super/sub", 0777); rewrite_gitmodules(git_repository_workdir(repo)); cl_set_cleanup(cleanup_fixture_submodules, "sub.git"); cl_git_pass(git_repository_reinit_filesystem(repo, 1)); return repo; }
git_repository *setup_fixture_submod2(void) { git_repository *repo = cl_git_sandbox_init("submod2"); cl_fixture_sandbox("submod2_target"); p_rename("submod2_target/.gitted", "submod2_target/.git"); rewrite_gitmodules(git_repository_workdir(repo)); p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git"); p_rename("submod2/not/.gitted", "submod2/not/.git"); cl_set_cleanup(cleanup_fixture_submodules, "submod2_target"); cl_git_pass(git_repository_reinit_filesystem(repo, 1)); return repo; }
void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void) { int how_many_refs = 0; cl_fixture_sandbox("testrepo.git"); cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git")); connect_to_local_repository("spaced testrepo.git"); cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); cl_assert(how_many_refs == 14); /* 1 HEAD + 6 heads + 1 lightweight tag + 3 annotated tags + 3 peeled target */ git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */ remote = NULL; cl_fixture_cleanup("spaced testrepo.git"); }
void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void) { int how_many_refs = 0; cl_fixture_sandbox("testrepo.git"); cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git")); connect_to_local_repository("spaced testrepo.git"); cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); cl_assert_equal_i(how_many_refs, 26); git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */ remote = NULL; cl_fixture_cleanup("spaced testrepo.git"); }
void test_network_remote_local__retrieve_advertised_references_from_spaced_repository(void) { const git_remote_head **refs; size_t refs_len; cl_fixture_sandbox("testrepo.git"); cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git")); connect_to_local_repository("spaced testrepo.git"); cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); cl_assert_equal_i(refs_len, 28); git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */ remote = NULL; cl_fixture_cleanup("spaced testrepo.git"); }
void test_repo_open__open_with_discover(void) { static const char *variants[] = { "attr", "attr/", "attr/.git", "attr/.git/", "attr/sub", "attr/sub/", "attr/sub/sub", "attr/sub/sub/", NULL }; git_repository *repo; const char **scan; cl_fixture_sandbox("attr"); cl_git_pass(p_rename("attr/.gitted", "attr/.git")); for (scan = variants; *scan != NULL; scan++) { cl_git_pass(git_repository_open_ext(&repo, *scan, 0, NULL)); cl_assert(git__suffixcmp(git_repository_path(repo), "attr/.git/") == 0); cl_assert(git__suffixcmp(git_repository_workdir(repo), "attr/") == 0); git_repository_free(repo); } cl_fixture_cleanup("attr"); }
void test_odb_foreach__files_in_objects_dir(void) { git_repository *repo; git_odb *odb; git_buf buf = GIT_BUF_INIT; int nobj = 0; cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&repo, "testrepo.git")); cl_git_pass(git_buf_printf(&buf, "%s/objects/somefile", git_repository_path(repo))); cl_git_mkfile(buf.ptr, ""); git_buf_dispose(&buf); cl_git_pass(git_repository_odb(&odb, repo)); cl_git_pass(git_odb_foreach(odb, foreach_cb, &nobj)); cl_assert_equal_i(60 + 1640, nobj); /* count + in-pack */ git_odb_free(odb); git_repository_free(repo); cl_fixture_cleanup("testrepo.git"); }
/** * Initializer * * This method is called once before starting each * test, and will load the required fixtures */ void test_status_worktree__initialize(void) { /* * Sandbox the `status/` repository from our Fixtures. * This will copy the whole folder to our sandbox, * so now it can be accessed with `./status` */ cl_fixture_sandbox("status"); /* * Rename `status/.gitted` to `status/.git` * We do this because we cannot store a folder named `.git` * inside the fixtures folder in our libgit2 repo. */ cl_git_pass( git_futils_mv_atomic("status/.gitted", "status/.git") ); /* * Open the sandboxed "status" repository */ cl_git_pass(git_repository_open(&_repository, "status/.git")); }
void test_repo_open__no_config(void) { git_buf path = GIT_BUF_INIT; git_repository *repo; git_config *config; cl_fixture_sandbox("empty_standard_repo"); cl_git_pass(cl_rename( "empty_standard_repo/.gitted", "empty_standard_repo/.git")); /* remove local config */ cl_git_pass(git_futils_rmdir_r( "empty_standard_repo/.git/config", NULL, GIT_RMDIR_REMOVE_FILES)); /* isolate from system level configs */ cl_must_pass(p_mkdir("alternate", 0777)); cl_git_pass(git_path_prettify(&path, "alternate", NULL)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); git_buf_free(&path); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_set_string(config, "test.set", "42")); git_config_free(config); git_repository_free(repo); cl_fixture_cleanup("empty_standard_repo"); cl_sandbox_set_search_path_defaults(); }
void test_repo_env__open(void) { git_repository *repo = NULL; git_buf repo_dir_buf = GIT_BUF_INIT; const char *repo_dir = NULL; git_index *index = NULL; const char *t_obj = "testrepo.git/objects"; const char *p_obj = "peeled.git/objects"; clear_git_env(); cl_fixture_sandbox("attr"); cl_fixture_sandbox("testrepo.git"); cl_fixture_sandbox("peeled.git"); cl_git_pass(p_rename("attr/.gitted", "attr/.git")); cl_git_pass(git_path_prettify_dir(&repo_dir_buf, "attr", NULL)); repo_dir = git_buf_cstr(&repo_dir_buf); /* GIT_DIR that doesn't exist */ cl_setenv("GIT_DIR", "does-not-exist"); env_fail(NULL); /* Explicit start_path overrides GIT_DIR */ env_pass("attr"); env_pass("attr/.git"); env_pass("attr/sub"); env_pass("attr/sub/sub"); /* GIT_DIR with relative paths */ cl_setenv("GIT_DIR", "attr/.git"); env_pass(NULL); cl_setenv("GIT_DIR", "attr"); env_fail(NULL); cl_setenv("GIT_DIR", "attr/sub"); env_fail(NULL); cl_setenv("GIT_DIR", "attr/sub/sub"); env_fail(NULL); /* GIT_DIR with absolute paths */ cl_setenv_printf("GIT_DIR", "%s/.git", repo_dir); env_pass(NULL); cl_setenv("GIT_DIR", repo_dir); env_fail(NULL); cl_setenv_printf("GIT_DIR", "%s/sub", repo_dir); env_fail(NULL); cl_setenv_printf("GIT_DIR", "%s/sub/sub", repo_dir); env_fail(NULL); cl_setenv("GIT_DIR", NULL); /* Searching from the current directory */ env_cd_pass("attr"); env_cd_pass("attr/.git"); env_cd_pass("attr/sub"); env_cd_pass("attr/sub/sub"); /* A ceiling directory blocks searches from ascending into that * directory, but doesn't block the start_path itself. */ cl_setenv("GIT_CEILING_DIRECTORIES", repo_dir); env_cd_pass("attr"); env_cd_fail("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s/sub", repo_dir); env_cd_pass("attr"); env_cd_pass("attr/sub"); env_cd_fail("attr/sub/sub"); /* Multiple ceiling directories */ cl_setenv_printf("GIT_CEILING_DIRECTORIES", "123%c%s/sub%cabc", GIT_PATH_LIST_SEPARATOR, repo_dir, GIT_PATH_LIST_SEPARATOR); env_cd_pass("attr"); env_cd_pass("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s%c%s/sub", repo_dir, GIT_PATH_LIST_SEPARATOR, repo_dir); env_cd_pass("attr"); env_cd_fail("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s/sub%c%s", repo_dir, GIT_PATH_LIST_SEPARATOR, repo_dir); env_cd_pass("attr"); env_cd_fail("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s%c%s/sub/sub", repo_dir, GIT_PATH_LIST_SEPARATOR, repo_dir); env_cd_pass("attr"); env_cd_fail("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv("GIT_CEILING_DIRECTORIES", NULL); /* Index files */ cl_setenv("GIT_INDEX_FILE", cl_fixture("gitgit.index")); cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL)); cl_git_pass(git_repository_index(&index, repo)); cl_assert_equal_s(git_index_path(index), cl_fixture("gitgit.index")); cl_assert_equal_i(git_index_entrycount(index), 1437); git_index_free(index); git_repository_free(repo); cl_setenv("GIT_INDEX_FILE", NULL); /* Namespaces */ cl_setenv("GIT_NAMESPACE", "some-namespace"); cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL)); cl_assert_equal_s(git_repository_get_namespace(repo), "some-namespace"); git_repository_free(repo); cl_setenv("GIT_NAMESPACE", NULL); /* Object directories and alternates */ env_check_objects(true, false, false); cl_setenv("GIT_OBJECT_DIRECTORY", t_obj); env_check_objects(false, true, false); cl_setenv("GIT_OBJECT_DIRECTORY", NULL); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", t_obj); env_check_objects(true, true, false); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL); cl_setenv("GIT_OBJECT_DIRECTORY", p_obj); env_check_objects(false, false, true); cl_setenv("GIT_OBJECT_DIRECTORY", NULL); cl_setenv("GIT_OBJECT_DIRECTORY", t_obj); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", p_obj); env_check_objects(false, true, true); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL); cl_setenv("GIT_OBJECT_DIRECTORY", NULL); cl_setenv_printf("GIT_ALTERNATE_OBJECT_DIRECTORIES", "%s%c%s", t_obj, GIT_PATH_LIST_SEPARATOR, p_obj); env_check_objects(true, true, true); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL); cl_setenv_printf("GIT_ALTERNATE_OBJECT_DIRECTORIES", "%s%c%s", p_obj, GIT_PATH_LIST_SEPARATOR, t_obj); env_check_objects(true, true, true); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL); cl_fixture_cleanup("peeled.git"); cl_fixture_cleanup("testrepo.git"); cl_fixture_cleanup("attr"); git_buf_free(&repo_dir_buf); clear_git_env(); }
void test_config_validkeyname__initialize(void) { cl_fixture_sandbox("config/config10"); cl_git_pass(git_config_open_ondisk(&cfg, "config10")); }
void test_config_write__initialize(void) { cl_fixture_sandbox("config/config9"); cl_fixture_sandbox("config/config15"); cl_fixture_sandbox("config/config17"); }