summaryrefslogtreecommitdiff
path: root/tests-clay/repo/getters.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-11-25 08:16:26 +0100
committerVicent Marti <tanoku@gmail.com>2011-11-26 08:37:08 +0100
commit9462c471435b4de74848408bebe41d770dc49a50 (patch)
treeaac5e696d1b3e7b4cba64082b28255e5c4593b66 /tests-clay/repo/getters.c
parent880b6f0c22153db164ecb3a18c362ba8337365d3 (diff)
downloadlibgit2-9462c471435b4de74848408bebe41d770dc49a50.tar.gz
repository: Change ownership semantics
The ownership semantics have been changed all over the library to be consistent. There are no more "borrowed" or duplicated references. Main changes: - `git_repository_open2` and `3` have been dropped. - Added setters and getters to hotswap all the repository owned objects: `git_repository_index` `git_repository_set_index` `git_repository_odb` `git_repository_set_odb` `git_repository_config` `git_repository_set_config` `git_repository_workdir` `git_repository_set_workdir` Now working directories/index files/ODBs and so on can be hot-swapped after creating a repository and between operations. - All these objects now have proper ownership semantics with refcounting: they all require freeing after they are no longer needed (the repository always keeps its internal reference). - Repository open and initialization has been updated to keep in mind the configuration files. Bare repositories are now always detected, and a default config file is created on init. - All the tests affected by these changes have been dropped from the old test suite and ported to the new one.
Diffstat (limited to 'tests-clay/repo/getters.c')
-rw-r--r--tests-clay/repo/getters.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests-clay/repo/getters.c b/tests-clay/repo/getters.c
new file mode 100644
index 000000000..3acdb7566
--- /dev/null
+++ b/tests-clay/repo/getters.c
@@ -0,0 +1,68 @@
+#include "clay_libgit2.h"
+
+void test_repo_getters__initialize(void)
+{
+ cl_fixture_sandbox("testrepo.git");
+}
+
+void test_repo_getters__cleanup(void)
+{
+ cl_fixture_cleanup("testrepo.git");
+}
+
+void test_repo_getters__empty(void)
+{
+ git_repository *repo_empty, *repo_normal;
+
+ cl_git_pass(git_repository_open(&repo_normal, cl_fixture("testrepo.git")));
+ cl_assert(git_repository_is_empty(repo_normal) == 0);
+ git_repository_free(repo_normal);
+
+ cl_git_pass(git_repository_open(&repo_empty, cl_fixture("empty_bare.git")));
+ cl_assert(git_repository_is_empty(repo_empty) == 1);
+ git_repository_free(repo_empty);
+}
+
+void test_repo_getters__head_detached(void)
+{
+ git_repository *repo;
+ git_reference *ref;
+ git_oid oid;
+
+ cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+
+ cl_assert(git_repository_head_detached(repo) == 0);
+
+ /* detach the HEAD */
+ git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd");
+ cl_git_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1));
+ cl_assert(git_repository_head_detached(repo) == 1);
+
+ /* take the reop back to it's original state */
+ cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
+ cl_assert(git_repository_head_detached(repo) == 0);
+
+ git_reference_free(ref);
+ git_repository_free(repo);
+}
+
+void test_repo_getters__head_orphan(void)
+{
+ git_repository *repo;
+ git_reference *ref;
+
+ cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+
+ cl_assert(git_repository_head_orphan(repo) == 0);
+
+ /* orphan HEAD */
+ cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/orphan", 1));
+ cl_assert(git_repository_head_orphan(repo) == 1);
+
+ /* take the reop back to it's original state */
+ cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
+ cl_assert(git_repository_head_orphan(repo) == 0);
+
+ git_reference_free(ref);
+ git_repository_free(repo);
+}