tests/libgit2: conditional checks for the "files"-backend

We have a bunch of checks for properties of the "files" reference
backend:

  - Whether a specific reference has been packed or whether it still
    exists as a loose reference.

  - Whether empty ref directories get pruned.

  - Whether we properly fsync data to disk.

These checks continue to be sensible for that backend, but for any other
backend they plain don't work. Adapt the tests so that we only run them
in case the repository uses the "files" backend.
This commit is contained in:
Patrick Steinhardt
2025-07-29 09:36:35 +02:00
parent 1030b68f3d
commit 1888a166e4
10 changed files with 106 additions and 40 deletions

View File

@@ -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));

View File

@@ -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);

View File

@@ -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));

View File

@@ -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));

View File

@@ -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",

View File

@@ -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);

View File

@@ -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));

View File

@@ -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);

View File

@@ -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"));

View File

@@ -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);