]>
git.proxmox.com Git - libgit2.git/blob - tests/refs/pack.c
92312e26d8f2a2640d7aca5a67d4fbadc6916a3e
1 #include "clar_libgit2.h"
4 #include "git2/reflog.h"
5 #include "git2/refdb.h"
8 #include "ref_helpers.h"
10 static const char *loose_tag_ref_name
= "refs/tags/e90810b";
12 static git_repository
*g_repo
;
14 void test_refs_pack__initialize(void)
16 g_repo
= cl_git_sandbox_init("testrepo");
19 void test_refs_pack__cleanup(void)
21 cl_git_sandbox_cleanup();
24 static void packall(void)
28 cl_git_pass(git_repository_refdb(&refdb
, g_repo
));
29 cl_git_pass(git_refdb_compress(refdb
));
30 git_refdb_free(refdb
);
33 void test_refs_pack__empty(void)
35 /* create a packfile for an empty folder */
36 git_buf temp_path
= GIT_BUF_INIT
;
38 cl_git_pass(git_buf_join_n(&temp_path
, '/', 3, git_repository_path(g_repo
), GIT_REFS_HEADS_DIR
, "empty_dir"));
39 cl_git_pass(git_futils_mkdir_r(temp_path
.ptr
, GIT_REFS_DIR_MODE
));
40 git_buf_dispose(&temp_path
);
45 void test_refs_pack__loose(void)
47 /* create a packfile from all the loose refs in a repo */
48 git_reference
*reference
;
49 git_buf temp_path
= GIT_BUF_INIT
;
51 /* Ensure a known loose ref can be looked up */
52 cl_git_pass(git_reference_lookup(&reference
, g_repo
, loose_tag_ref_name
));
53 cl_assert(reference_is_packed(reference
) == 0);
54 cl_assert_equal_s(reference
->name
, loose_tag_ref_name
);
55 git_reference_free(reference
);
58 * We are now trying to pack also a loose reference
59 * called `points_to_blob`, to make sure we can properly
64 /* Ensure the packed-refs file exists */
65 cl_git_pass(git_buf_joinpath(&temp_path
, git_repository_path(g_repo
), GIT_PACKEDREFS_FILE
));
66 cl_assert(git_path_exists(temp_path
.ptr
));
68 /* Ensure the known ref can still be looked up but is now packed */
69 cl_git_pass(git_reference_lookup(&reference
, g_repo
, loose_tag_ref_name
));
70 cl_assert(reference_is_packed(reference
));
71 cl_assert_equal_s(reference
->name
, loose_tag_ref_name
);
73 /* Ensure the known ref has been removed from the loose folder structure */
74 cl_git_pass(git_buf_joinpath(&temp_path
, git_repository_path(g_repo
), loose_tag_ref_name
));
75 cl_assert(!git_path_exists(temp_path
.ptr
));
77 git_reference_free(reference
);
78 git_buf_dispose(&temp_path
);
81 void test_refs_pack__symbolic(void)
83 /* create a packfile from loose refs skipping symbolic refs */
89 cl_git_pass(git_reference_name_to_id(&head
, g_repo
, "HEAD"));
91 /* make a bunch of references */
93 for (i
= 0; i
< 100; ++i
) {
94 p_snprintf(name
, sizeof(name
), "refs/heads/symbolic-%03d", i
);
95 cl_git_pass(git_reference_symbolic_create(
96 &ref
, g_repo
, name
, "refs/heads/master", 0, NULL
));
97 git_reference_free(ref
);
99 p_snprintf(name
, sizeof(name
), "refs/heads/direct-%03d", i
);
100 cl_git_pass(git_reference_create(&ref
, g_repo
, name
, &head
, 0, NULL
));
101 git_reference_free(ref
);