]>
git.proxmox.com Git - libgit2.git/blob - tests/repo/setters.c
1 #include "clar_libgit2.h"
2 #include "git2/sys/repository.h"
9 static git_repository
*repo
;
11 void test_repo_setters__initialize(void)
13 cl_fixture_sandbox("testrepo.git");
14 cl_git_pass(git_repository_open(&repo
, "testrepo.git"));
15 cl_must_pass(p_mkdir("new_workdir", 0777));
18 void test_repo_setters__cleanup(void)
20 git_repository_free(repo
);
23 cl_fixture_cleanup("testrepo.git");
24 cl_fixture_cleanup("new_workdir");
27 void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standard_one(void)
29 cl_assert(git_repository_is_bare(repo
) == 1);
31 cl_assert(git_repository_workdir(repo
) == NULL
);
32 cl_git_pass(git_repository_set_workdir(repo
, "./new_workdir", false));
34 cl_assert(git_repository_workdir(repo
) != NULL
);
35 cl_assert(git_repository_is_bare(repo
) == 0);
38 void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
40 cl_git_pass(git_repository_set_workdir(repo
, "./new_workdir", false));
42 cl_assert(git__suffixcmp(git_repository_workdir(repo
), "new_workdir/") == 0);
45 void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
48 git_buf buf
= GIT_BUF_INIT
;
49 git_str content
= GIT_STR_INIT
;
51 cl_git_pass(git_repository_set_workdir(repo
, "./new_workdir", true));
53 cl_assert(git_fs_path_isfile("./new_workdir/.git"));
55 cl_git_pass(git_futils_readbuffer(&content
, "./new_workdir/.git"));
56 cl_assert(git__prefixcmp(git_str_cstr(&content
), "gitdir: ") == 0);
57 cl_assert(git__suffixcmp(git_str_cstr(&content
), "testrepo.git/") == 0);
58 git_str_dispose(&content
);
60 cl_git_pass(git_repository_config(&cfg
, repo
));
61 cl_git_pass(git_config_get_string_buf(&buf
, cfg
, "core.worktree"));
62 cl_assert(git__suffixcmp(buf
.ptr
, "new_workdir/") == 0);
64 git_buf_dispose(&buf
);
68 void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_one_properly_honors_the_refcount(void)
72 cl_git_pass(git_index_open(&new_index
, "./my-index"));
73 cl_assert(((git_refcount
*)new_index
)->refcount
.val
== 1);
75 git_repository_set_index(repo
, new_index
);
76 cl_assert(((git_refcount
*)new_index
)->refcount
.val
== 2);
78 git_repository_free(repo
);
79 cl_assert(((git_refcount
*)new_index
)->refcount
.val
== 1);
81 git_index_free(new_index
);
84 * Ensure the cleanup method won't try to free the repo as it's already been taken care of
89 void test_repo_setters__setting_a_new_odb_on_a_repo_which_already_loaded_one_properly_honors_the_refcount(void)
93 cl_git_pass(git_odb_open(&new_odb
, "./testrepo.git/objects"));
94 cl_assert(((git_refcount
*)new_odb
)->refcount
.val
== 1);
96 git_repository_set_odb(repo
, new_odb
);
97 cl_assert(((git_refcount
*)new_odb
)->refcount
.val
== 2);
99 git_repository_free(repo
);
100 cl_assert(((git_refcount
*)new_odb
)->refcount
.val
== 1);
102 git_odb_free(new_odb
);
105 * Ensure the cleanup method won't try to free the repo as it's already been taken care of