diff --git a/tests/clar/clar_libgit2.c b/tests/clar/clar_libgit2.c index c4a2dfc7e48..afea57f25bc 100644 --- a/tests/clar/clar_libgit2.c +++ b/tests/clar/clar_libgit2.c @@ -504,6 +504,26 @@ void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value git_config_free(config); } +int cl_repo_has_ref_format(git_repository *repo, const char *format) +{ + const char *configured_format; + git_config *config; + int result; + + cl_git_pass(git_repository_config_snapshot(&config, repo)); + result = git_config_get_string(&configured_format, config, + "extensions.refStorage"); + if (result < 0 && result != GIT_ENOTFOUND) + cl_fail("cannot read extensions.refStorage"); + if (result < 0) + configured_format = "files"; + + result = !strcmp(configured_format, format); + + git_config_free(config); + return result; +} + /* this is essentially the code from git__unescape modified slightly */ static size_t strip_cr_from_buf(char *start, size_t len) { diff --git a/tests/clar/clar_libgit2.h b/tests/clar/clar_libgit2.h index c6cad6835f7..90fe4679b0f 100644 --- a/tests/clar/clar_libgit2.h +++ b/tests/clar/clar_libgit2.h @@ -254,6 +254,8 @@ int cl_repo_get_int(git_repository *repo, const char *cfg); void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value); +int cl_repo_has_ref_format(git_repository *repo, const char *format); + /* * set up a fake "home" directory -- automatically configures cleanup * function to restore the home directory, although you can call it diff --git a/tests/libgit2/cherrypick/workdir.c b/tests/libgit2/cherrypick/workdir.c index 45b8349e1ed..a7384e8e65f 100644 --- a/tests/libgit2/cherrypick/workdir.c +++ b/tests/libgit2/cherrypick/workdir.c @@ -63,6 +63,7 @@ void test_cherrypick_workdir__automerge(void) git_commit *head = NULL, *commit = NULL; git_oid cherry_oid, cherrypicked_oid, cherrypicked_tree_oid; git_tree *cherrypicked_tree = NULL; + git_reference *ref; cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); @@ -71,7 +72,7 @@ void test_cherrypick_workdir__automerge(void) cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, NULL)); - cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); + cl_git_pass(git_reference_lookup(&ref, repo, "CHERRY_PICK_HEAD")); cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); cl_git_pass(git_index_write_tree(&cherrypicked_tree_oid, repo_index)); @@ -84,6 +85,7 @@ void test_cherrypick_workdir__automerge(void) git_oid_cpy(&head_oid, &cherrypicked_oid); git_tree_free(cherrypicked_tree); + git_reference_free(ref); git_commit_free(head); git_commit_free(commit); } @@ -140,6 +142,7 @@ void test_cherrypick_workdir__conflicts(void) git_commit *head = NULL, *commit = NULL; git_oid head_oid, cherry_oid; git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT; + git_reference *ref; struct merge_index_entry merge_index_entries[] = { { 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" }, @@ -160,7 +163,7 @@ void test_cherrypick_workdir__conflicts(void) cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, NULL)); - cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); + cl_git_pass(git_reference_lookup(&ref, repo, "CHERRY_PICK_HEAD")); cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); cl_assert(merge_test_index(repo_index, merge_index_entries, 7)); @@ -225,6 +228,7 @@ void test_cherrypick_workdir__conflicts(void) "File 3!\n" \ ">>>>>>> e9b63f3... Change all files\n") == 0); + git_reference_free(ref); git_commit_free(commit); git_commit_free(head); git_str_dispose(&mergemsg_buf); diff --git a/tests/libgit2/config/conditionals.c b/tests/libgit2/config/conditionals.c index 564719dcbcf..0e32f19d718 100644 --- a/tests/libgit2/config/conditionals.c +++ b/tests/libgit2/config/conditionals.c @@ -23,13 +23,15 @@ void test_config_conditionals__cleanup(void) static void assert_condition_includes(const char *keyword, const char *path, bool expected) { git_buf value = GIT_BUF_INIT; + git_str key = GIT_STR_INIT; git_str buf = GIT_STR_INIT; git_config *cfg; - cl_git_pass(git_str_printf(&buf, "[includeIf \"%s:%s\"]\n", keyword, path)); - cl_git_pass(git_str_puts(&buf, "path = other\n")); + cl_git_pass(git_repository_config(&cfg, _repo)); + cl_git_pass(git_str_printf(&key, "includeIf.%s:%s.path", keyword, path)); + cl_git_pass(git_config_set_string(cfg, key.ptr, "other")); + git_config_free(cfg); - cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr); cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n"); _repo = cl_git_sandbox_reopen(); @@ -45,6 +47,9 @@ static void assert_condition_includes(const char *keyword, const char *path, boo git_config_get_string_buf(&value, cfg, "foo.bar")); } + cl_git_pass(git_config_delete_entry(cfg, key.ptr)); + + git_str_dispose(&key); git_str_dispose(&buf); git_buf_dispose(&value); git_config_free(cfg); @@ -155,10 +160,10 @@ void test_config_conditionals__empty(void) git_str buf = GIT_STR_INIT; git_config *cfg; - cl_git_pass(git_str_puts(&buf, "[includeIf]\n")); - cl_git_pass(git_str_puts(&buf, "path = other\n")); + cl_git_pass(git_repository_config(&cfg, _repo)); + cl_git_pass(git_config_set_string(cfg, "includeIf.path", "other")); + git_config_free(cfg); - cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr); cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n"); _repo = cl_git_sandbox_reopen(); diff --git a/tests/libgit2/merge/analysis.c b/tests/libgit2/merge/analysis.c index 8c61303e342..2538ecfdccd 100644 --- a/tests/libgit2/merge/analysis.c +++ b/tests/libgit2/merge/analysis.c @@ -120,15 +120,11 @@ void test_merge_analysis__unborn(void) { git_merge_analysis_t merge_analysis; git_merge_preference_t merge_pref; - git_str master = GIT_STR_INIT; - cl_git_pass(git_str_joinpath(&master, git_repository_path(repo), "refs/heads/master")); - cl_must_pass(p_unlink(git_str_cstr(&master))); + cl_git_pass(git_reference_remove(repo, "refs/heads/master")); analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH); cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD|GIT_MERGE_ANALYSIS_UNBORN, merge_analysis); - - git_str_dispose(&master); } void test_merge_analysis__fastforward_with_config_noff(void) diff --git a/tests/libgit2/merge/workdir/setup.c b/tests/libgit2/merge/workdir/setup.c index 84496c436e1..2969558ffdf 100644 --- a/tests/libgit2/merge/workdir/setup.c +++ b/tests/libgit2/merge/workdir/setup.c @@ -462,45 +462,15 @@ void test_merge_workdir_setup__three_same_oids(void) static int create_remote_tracking_branch(const char *branch_name, const char *oid_str) { - int error = 0; + git_str refname = GIT_STR_INIT; + git_oid oid; - git_str remotes_path = GIT_STR_INIT, - origin_path = GIT_STR_INIT, - filename = GIT_STR_INIT, - data = GIT_STR_INIT; + cl_git_pass(git_oid_from_string(&oid, oid_str, GIT_OID_SHA1)); + cl_git_pass(git_str_printf(&refname, GIT_REFS_REMOTES_DIR "origin/%s", branch_name)); + cl_git_pass(git_reference_create(NULL, repo, refname.ptr, &oid, 0, NULL)); - if ((error = git_str_puts(&remotes_path, git_repository_path(repo))) < 0 || - (error = git_str_puts(&remotes_path, GIT_REFS_REMOTES_DIR)) < 0) - goto done; - - if (!git_fs_path_exists(git_str_cstr(&remotes_path)) && - (error = p_mkdir(git_str_cstr(&remotes_path), 0777)) < 0) - goto done; - - if ((error = git_str_puts(&origin_path, git_str_cstr(&remotes_path))) < 0 || - (error = git_str_puts(&origin_path, "origin")) < 0) - goto done; - - if (!git_fs_path_exists(git_str_cstr(&origin_path)) && - (error = p_mkdir(git_str_cstr(&origin_path), 0777)) < 0) - goto done; - - if ((error = git_str_puts(&filename, git_str_cstr(&origin_path))) < 0 || - (error = git_str_puts(&filename, "/")) < 0 || - (error = git_str_puts(&filename, branch_name)) < 0 || - (error = git_str_puts(&data, oid_str)) < 0 || - (error = git_str_puts(&data, "\n")) < 0) - goto done; - - cl_git_rewritefile(git_str_cstr(&filename), git_str_cstr(&data)); - -done: - git_str_dispose(&remotes_path); - git_str_dispose(&origin_path); - git_str_dispose(&filename); - git_str_dispose(&data); - - return error; + git_str_dispose(&refname); + return 0; } /* git merge refs/remotes/origin/octo1 */ diff --git a/tests/libgit2/rebase/setup.c b/tests/libgit2/rebase/setup.c index 10cc306de34..e94dea42110 100644 --- a/tests/libgit2/rebase/setup.c +++ b/tests/libgit2/rebase/setup.c @@ -23,6 +23,18 @@ void test_rebase_setup__cleanup(void) cl_git_sandbox_cleanup(); } +static void cl_assert_equal_ref(const char *oid_str, const char *refname) +{ + git_reference *ref; + git_oid oid; + + cl_git_pass(git_oid_from_string(&oid, oid_str, GIT_OID_SHA1)); + cl_git_pass(git_reference_lookup(&ref, repo, refname)); + cl_assert_equal_oid(&oid, git_reference_target(ref)); + + git_reference_free(ref); +} + /* git checkout beef ; git rebase --merge master * git checkout beef ; git rebase --merge master */ void test_rebase_setup__blocked_when_in_progress(void) @@ -79,7 +91,7 @@ void test_rebase_setup__merge(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD"); cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1"); cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2"); @@ -125,7 +137,7 @@ void test_rebase_setup__merge_root(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD"); cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); @@ -175,7 +187,7 @@ void test_rebase_setup__merge_onto_and_upstream(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("d616d97082eb7bb2dc6f180a7cca940993b7a56f", "ORIG_HEAD"); cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); @@ -229,7 +241,7 @@ void test_rebase_setup__merge_onto_upstream_and_branch(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("f87d14a4a236582a0278a916340a793714256864", "ORIG_HEAD"); cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); @@ -287,7 +299,7 @@ void test_rebase_setup__merge_onto_upstream_and_branch_by_id(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("d616d97082eb7bb2dc6f180a7cca940993b7a56f", "ORIG_HEAD"); cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); @@ -333,7 +345,7 @@ void test_rebase_setup__branch_with_merges(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("f87d14a4a236582a0278a916340a793714256864", "ORIG_HEAD"); cl_assert_equal_file("4bed71df7017283cac61bbf726197ad6a5a18b84\n", 41, "rebase/.git/rebase-merge/cmt.1"); cl_assert_equal_file("2aa3ce842094e08ebac152b3d6d5b0fff39f9c6e\n", 41, "rebase/.git/rebase-merge/cmt.2"); @@ -381,7 +393,7 @@ void test_rebase_setup__orphan_branch(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("12c084412b952396962eb420716df01022b847cc\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("12c084412b952396962eb420716df01022b847cc", "ORIG_HEAD"); cl_assert_equal_file("aa4c42aecdfc7cd989bbc3209934ea7cda3f4d88\n", 41, "rebase/.git/rebase-merge/cmt.1"); cl_assert_equal_file("e4f809f826c1a9fc929874bc0e4644dd2f2a1af4\n", 41, "rebase/.git/rebase-merge/cmt.2"); @@ -432,7 +444,7 @@ void test_rebase_setup__merge_null_branch_uses_HEAD(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD"); cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1"); cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2"); @@ -479,7 +491,7 @@ void test_rebase_setup__merge_from_detached(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD"); cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1"); cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2"); @@ -527,7 +539,7 @@ void test_rebase_setup__merge_branch_by_id(void) cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); - cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD"); + cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD"); cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1"); cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2"); diff --git a/tests/libgit2/refs/branches/delete.c b/tests/libgit2/refs/branches/delete.c index 2c28dd294fa..d5f26d7a414 100644 --- a/tests/libgit2/refs/branches/delete.c +++ b/tests/libgit2/refs/branches/delete.c @@ -171,6 +171,9 @@ void test_refs_branches_delete__removes_empty_folders(void) git_str ref_folder = GIT_STR_INIT; git_str reflog_folder = GIT_STR_INIT; + if (!cl_repo_has_ref_format(repo, "files")) + cl_skip(); + /* Create a new branch with a nested name */ cl_git_pass(git_oid_from_string(&commit_id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); diff --git a/tests/libgit2/refs/create.c b/tests/libgit2/refs/create.c index aca6ecd63b5..42c43e51931 100644 --- a/tests/libgit2/refs/create.c +++ b/tests/libgit2/refs/create.c @@ -42,7 +42,8 @@ void test_refs_create__symbolic(void) /* Ensure the reference can be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker)); cl_assert(git_reference_type(looked_up_ref) & GIT_REFERENCE_SYMBOLIC); - cl_assert(reference_is_packed(looked_up_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(looked_up_ref) == 0); cl_assert_equal_s(looked_up_ref->name, new_head_tracker); /* ...peeled.. */ @@ -92,7 +93,8 @@ void test_refs_create__symbolic_with_arbitrary_content(void) /* Ensure the reference can be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker)); cl_assert(git_reference_type(looked_up_ref) & GIT_REFERENCE_SYMBOLIC); - cl_assert(reference_is_packed(looked_up_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(looked_up_ref) == 0); cl_assert_equal_s(looked_up_ref->name, new_head_tracker); git_reference_free(looked_up_ref); @@ -105,7 +107,8 @@ void test_refs_create__symbolic_with_arbitrary_content(void) /* Ensure the reference can be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, repo2, new_head_tracker)); cl_assert(git_reference_type(looked_up_ref) & GIT_REFERENCE_SYMBOLIC); - cl_assert(reference_is_packed(looked_up_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(looked_up_ref) == 0); cl_assert_equal_s(looked_up_ref->name, new_head_tracker); /* Ensure the target is what we expect it to be */ @@ -153,7 +156,8 @@ void test_refs_create__oid(void) /* Ensure the reference can be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head)); cl_assert(git_reference_type(looked_up_ref) & GIT_REFERENCE_DIRECT); - cl_assert(reference_is_packed(looked_up_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(looked_up_ref) == 0); cl_assert_equal_s(looked_up_ref->name, new_head); /* ...and that it points to the current master tip */ @@ -332,8 +336,9 @@ static void count_fsyncs(size_t *create_count, size_t *compress_count) void test_refs_create__does_not_fsync_by_default(void) { size_t create_count, compress_count; + if (!cl_repo_has_ref_format(g_repo, "files")) + cl_skip(); count_fsyncs(&create_count, &compress_count); - cl_assert_equal_i(0, create_count); cl_assert_equal_i(0, compress_count); } @@ -342,6 +347,9 @@ void test_refs_create__fsyncs_when_global_opt_set(void) { size_t create_count, compress_count; + if (!cl_repo_has_ref_format(g_repo, "files")) + cl_skip(); + cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_FSYNC_GITDIR, 1)); count_fsyncs(&create_count, &compress_count); @@ -353,6 +361,9 @@ void test_refs_create__fsyncs_when_repo_config_set(void) { size_t create_count, compress_count; + if (!cl_repo_has_ref_format(g_repo, "files")) + cl_skip(); + cl_repo_set_bool(g_repo, "core.fsyncObjectFiles", true); count_fsyncs(&create_count, &compress_count); diff --git a/tests/libgit2/refs/delete.c b/tests/libgit2/refs/delete.c index b420bb157a9..918362fc331 100644 --- a/tests/libgit2/refs/delete.c +++ b/tests/libgit2/refs/delete.c @@ -33,13 +33,15 @@ void test_refs_delete__packed_loose(void) /* Ensure the loose reference exists on the file system */ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name)); - cl_assert(git_fs_path_exists(temp_path.ptr)); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(git_fs_path_exists(temp_path.ptr)); /* Lookup the reference */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_test_head_name)); /* Ensure it's the loose version that has been found */ - cl_assert(reference_is_packed(looked_up_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(looked_up_ref) == 0); /* Now that the reference is deleted... */ cl_git_pass(git_reference_delete(looked_up_ref)); @@ -49,7 +51,8 @@ void test_refs_delete__packed_loose(void) cl_git_fail(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name)); /* Ensure the loose reference doesn't exist any longer on the file system */ - cl_assert(!git_fs_path_exists(temp_path.ptr)); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(!git_fs_path_exists(temp_path.ptr)); git_reference_free(another_looked_up_ref); git_str_dispose(&temp_path); @@ -73,7 +76,8 @@ void test_refs_delete__packed_only(void) cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref)); /* Ensure it's a loose reference */ - cl_assert(reference_is_packed(ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(ref) == 0); /* Pack all existing references */ cl_git_pass(git_repository_refdb(&refdb, g_repo)); @@ -84,7 +88,8 @@ void test_refs_delete__packed_only(void) cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref)); /* Ensure it's a packed reference */ - cl_assert(reference_is_packed(ref) == 1); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(ref) == 1); /* This should pass */ cl_git_pass(git_reference_delete(ref)); diff --git a/tests/libgit2/refs/iterator.c b/tests/libgit2/refs/iterator.c index d79d968a588..0b2e65a718c 100644 --- a/tests/libgit2/refs/iterator.c +++ b/tests/libgit2/refs/iterator.c @@ -161,6 +161,8 @@ void test_refs_iterator__foreach_through_symlink(void) #ifdef GIT_WIN32 cl_skip(); #endif + if (!cl_repo_has_ref_format(repo, "files")) + cl_skip(); cl_git_pass(git_vector_init(&output, 32, &refcmp_cb)); diff --git a/tests/libgit2/refs/list.c b/tests/libgit2/refs/list.c index 8085ff84b23..72c91267429 100644 --- a/tests/libgit2/refs/list.c +++ b/tests/libgit2/refs/list.c @@ -45,6 +45,9 @@ void test_refs_list__do_not_retrieve_references_which_name_end_with_a_lock_exten { git_strarray ref_list; + if (!cl_repo_has_ref_format(g_repo, "files")) + cl_skip(); + /* Create a fake locked reference */ cl_git_mkfile( "./testrepo/.git/refs/heads/hanwen.lock", diff --git a/tests/libgit2/refs/pack.c b/tests/libgit2/refs/pack.c index 1c1cd51cba5..50670a2348f 100644 --- a/tests/libgit2/refs/pack.c +++ b/tests/libgit2/refs/pack.c @@ -35,6 +35,9 @@ void test_refs_pack__empty(void) /* create a packfile for an empty folder */ git_str temp_path = GIT_STR_INIT; + if (!cl_repo_has_ref_format(g_repo, "files")) + cl_skip(); + cl_git_pass(git_str_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir")); cl_git_pass(git_futils_mkdir_r(temp_path.ptr, GIT_REFS_DIR_MODE)); git_str_dispose(&temp_path); @@ -48,6 +51,9 @@ void test_refs_pack__loose(void) git_reference *reference; git_str temp_path = GIT_STR_INIT; + if (!cl_repo_has_ref_format(g_repo, "files")) + cl_skip(); + /* Ensure a known loose ref can be looked up */ cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name)); cl_assert(reference_is_packed(reference) == 0); diff --git a/tests/libgit2/refs/reflog/reflog.c b/tests/libgit2/refs/reflog/reflog.c index 674b809a362..109192ac0f1 100644 --- a/tests/libgit2/refs/reflog/reflog.c +++ b/tests/libgit2/refs/reflog/reflog.c @@ -107,15 +107,19 @@ void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void) git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master"); git_str_joinpath(&moved_log_path, git_str_cstr(&moved_log_path), "refs/moved"); - cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&master_log_path))); - cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&moved_log_path))); + if (cl_repo_has_ref_format(g_repo, "files")) { + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&master_log_path))); + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&moved_log_path))); + } cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master")); cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL)); git_reference_free(master); - cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&master_log_path))); - cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&moved_log_path))); + if (cl_repo_has_ref_format(g_repo, "files")) { + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&master_log_path))); + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&moved_log_path))); + } git_reference_free(new_master); git_str_dispose(&moved_log_path); @@ -130,13 +134,15 @@ void test_refs_reflog_reflog__deleting_the_reference_deletes_the_reflog(void) git_str_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master"); - cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&master_log_path))); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&master_log_path))); cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master")); cl_git_pass(git_reference_delete(master)); git_reference_free(master); - cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&master_log_path))); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&master_log_path))); git_str_dispose(&master_log_path); } @@ -153,7 +159,8 @@ void test_refs_reflog_reflog__removes_empty_reflog_dir(void) git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head"); - cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path))); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path))); cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); @@ -180,10 +187,12 @@ void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void) git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head"); - cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path))); + if (cl_repo_has_ref_format(g_repo, "files")) { + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path))); - /* delete the ref manually, leave the reflog */ - cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head")); + /* delete the ref manually, leave the reflog */ + cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head")); + } /* new ref creation should fail since new-dir contains reflogs still */ git_oid_from_string(&id, current_master_tip, GIT_OID_SHA1); @@ -212,7 +221,9 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re git_str subtrees_log_path = GIT_STR_INIT; git_str_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname); - cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&subtrees_log_path))); + + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&subtrees_log_path))); cl_git_pass(git_reflog_read(&reflog, g_repo, refname)); @@ -234,6 +245,9 @@ void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void git_str logpath = GIT_STR_INIT, logcontents = GIT_STR_INIT; char *star; + if (!cl_repo_has_ref_format(g_repo, "files")) + cl_skip(); + /* Create a new branch. */ cl_git_pass(git_oid_from_string(&id, current_master_tip, GIT_OID_SHA1)); cl_git_pass(git_reference_create(&ref, g_repo, refname, &id, 1, refmessage)); diff --git a/tests/libgit2/refs/rename.c b/tests/libgit2/refs/rename.c index f71e657820f..9b75fc8ca9c 100644 --- a/tests/libgit2/refs/rename.c +++ b/tests/libgit2/refs/rename.c @@ -47,7 +47,8 @@ void test_refs_rename__loose(void) cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, loose_tag_ref_name)); /* ... which is indeed loose */ - cl_assert(reference_is_packed(looked_up_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(looked_up_ref) == 0); /* Now that the reference is renamed... */ cl_git_pass(git_reference_rename(&new_ref, looked_up_ref, new_name, 0, NULL)); @@ -62,12 +63,16 @@ void test_refs_rename__loose(void) cl_assert_equal_s(new_ref->name, new_name); /* .. the new ref is loose... */ - cl_assert(reference_is_packed(another_looked_up_ref) == 0); - cl_assert(reference_is_packed(new_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) { + cl_assert(reference_is_packed(another_looked_up_ref) == 0); + cl_assert(reference_is_packed(new_ref) == 0); + } /* ...and the ref can be found in the file system */ - cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name)); - cl_assert(git_fs_path_exists(temp_path.ptr)); + if (cl_repo_has_ref_format(g_repo, "files")) { + cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name)); + cl_assert(git_fs_path_exists(temp_path.ptr)); + } git_reference_free(new_ref); git_reference_free(another_looked_up_ref); @@ -82,14 +87,17 @@ void test_refs_rename__packed(void) const char *brand_new_name = "refs/heads/brand_new_name"; /* Ensure the ref doesn't exist on the file system */ - cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name)); - cl_assert(!git_fs_path_exists(temp_path.ptr)); + if (cl_repo_has_ref_format(g_repo, "files")) { + cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name)); + cl_assert(!git_fs_path_exists(temp_path.ptr)); + } /* The reference can however be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_head_name)); /* .. and it's packed */ - cl_assert(reference_is_packed(looked_up_ref) != 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(looked_up_ref) != 0); /* Now that the reference is renamed... */ cl_git_pass(git_reference_rename(&new_ref, looked_up_ref, brand_new_name, 0, NULL)); @@ -104,12 +112,16 @@ void test_refs_rename__packed(void) cl_assert_equal_s(another_looked_up_ref->name, brand_new_name); /* .. the ref is no longer packed... */ - cl_assert(reference_is_packed(another_looked_up_ref) == 0); - cl_assert(reference_is_packed(new_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) { + cl_assert(reference_is_packed(another_looked_up_ref) == 0); + cl_assert(reference_is_packed(new_ref) == 0); + } /* ...and the ref now happily lives in the file system */ - cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name)); - cl_assert(git_fs_path_exists(temp_path.ptr)); + if (cl_repo_has_ref_format(g_repo, "files")) { + cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name)); + cl_assert(git_fs_path_exists(temp_path.ptr)); + } git_reference_free(new_ref); git_reference_free(another_looked_up_ref); @@ -124,21 +136,25 @@ void test_refs_rename__packed_doesnt_pack_others(void) const char *brand_new_name = "refs/heads/brand_new_name"; /* Ensure the other reference exists on the file system */ - cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name)); - cl_assert(git_fs_path_exists(temp_path.ptr)); + if (cl_repo_has_ref_format(g_repo, "files")) { + cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name)); + cl_assert(git_fs_path_exists(temp_path.ptr)); + } /* Lookup the other reference */ cl_git_pass(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name)); /* Ensure it's loose */ - cl_assert(reference_is_packed(another_looked_up_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(another_looked_up_ref) == 0); git_reference_free(another_looked_up_ref); /* Lookup the reference to rename */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_head_name)); /* Ensure it's packed */ - cl_assert(reference_is_packed(looked_up_ref) != 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(looked_up_ref) != 0); /* Now that the reference is renamed... */ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, brand_new_name, 0, NULL)); @@ -148,10 +164,12 @@ void test_refs_rename__packed_doesnt_pack_others(void) cl_git_pass(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name)); /* Ensure it's loose */ - cl_assert(reference_is_packed(another_looked_up_ref) == 0); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(reference_is_packed(another_looked_up_ref) == 0); /* Ensure the other ref still exists on the file system */ - cl_assert(git_fs_path_exists(temp_path.ptr)); + if (cl_repo_has_ref_format(g_repo, "files")) + cl_assert(git_fs_path_exists(temp_path.ptr)); git_reference_free(renamed_ref); git_reference_free(another_looked_up_ref); diff --git a/tests/libgit2/repo/repo_helpers.c b/tests/libgit2/repo/repo_helpers.c index 1efde70a50d..ded1d8f86a7 100644 --- a/tests/libgit2/repo/repo_helpers.c +++ b/tests/libgit2/repo/repo_helpers.c @@ -1,6 +1,8 @@ #include "clar_libgit2.h" #include "refs.h" #include "repo_helpers.h" +#include "repository.h" +#include "refdb.h" #include "posix.h" void make_head_unborn(git_repository* repo, const char *target) @@ -13,12 +15,9 @@ void make_head_unborn(git_repository* repo, const char *target) void delete_head(git_repository* repo) { - git_str head_path = GIT_STR_INIT; - - cl_git_pass(git_str_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE)); - cl_git_pass(p_unlink(git_str_cstr(&head_path))); - - git_str_dispose(&head_path); + git_refdb *refdb; + cl_git_pass(git_repository_refdb__weakptr(&refdb, repo)); + cl_git_pass(git_refdb_delete(refdb, GIT_HEAD_FILE, NULL, NULL)); } void create_tmp_global_config(const char *dirname, const char *key, const char *val) diff --git a/tests/libgit2/revwalk/basic.c b/tests/libgit2/revwalk/basic.c index b4cf76d262e..920afc7cd0a 100644 --- a/tests/libgit2/revwalk/basic.c +++ b/tests/libgit2/revwalk/basic.c @@ -170,6 +170,9 @@ void test_revwalk_basic__glob_heads_with_invalid(void) revwalk_basic_setup_walk("testrepo"); + if (!cl_repo_has_ref_format(_repo, "files")) + cl_skip(); + cl_git_mkfile("testrepo/.git/refs/heads/garbage", "not-a-ref"); cl_git_pass(git_revwalk_push_glob(_walk, "heads")); @@ -182,12 +185,13 @@ void test_revwalk_basic__glob_heads_with_invalid(void) void test_revwalk_basic__glob_invalid_symbolic_ref(void) { + git_reference *ref; int i; git_oid oid; revwalk_basic_setup_walk("testrepo"); - - cl_git_mkfile("testrepo/.git/refs/heads/broken-sym-ref", "ref: refs/heads/does-not-exist"); + cl_git_pass(git_reference_symbolic_create(&ref, _repo, "refs/heads/broken-sym-ref", + "refs/heads/does-not-exist", 1, NULL)); cl_git_pass(git_revwalk_push_glob(_walk, "heads")); for (i = 0; !git_revwalk_next(&oid, _walk); ++i) @@ -195,6 +199,8 @@ void test_revwalk_basic__glob_invalid_symbolic_ref(void) /* git log --branches --oneline | wc -l => 16 */ cl_assert_equal_i(20, i); + + git_reference_free(ref); } void test_revwalk_basic__push_head(void) diff --git a/tests/libgit2/worktree/refs.c b/tests/libgit2/worktree/refs.c index 51e7b2b9463..c18d45fec14 100644 --- a/tests/libgit2/worktree/refs.c +++ b/tests/libgit2/worktree/refs.c @@ -248,7 +248,8 @@ void test_worktree_refs__creating_refs_uses_commondir(void) cl_git_pass(git_branch_create(&branch, fixture.worktree, "testbranch", commit, 0)); cl_git_pass(git_branch_lookup(&lookup, fixture.worktree, "testbranch", GIT_BRANCH_LOCAL)); cl_assert(git_reference_cmp(branch, lookup) == 0); - cl_assert(git_fs_path_exists(refpath.ptr)); + if (cl_repo_has_ref_format(fixture.worktree, "files")) + cl_assert(git_fs_path_exists(refpath.ptr)); git_reference_free(lookup); git_reference_free(branch);