summaryrefslogtreecommitdiff
path: root/tests/libgit2
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-09-19 10:39:58 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-12 21:26:10 +0000
commitacb00e4eae66bfed84046bccb60bf59707fe9626 (patch)
treecb7136b9359e1ba600cc7f24571fcb8a69f6ce0e /tests/libgit2
parent4083e46f475cd3026a3c65a1e46c4b73d5c22513 (diff)
downloadlibgit2-acb00e4eae66bfed84046bccb60bf59707fe9626.tar.gz
repo: understand the `objectformat` extension
Teach the repository about the `objectformat` extension, supporting `sha1` always and `sha256` when the experimental sha256 support is active.
Diffstat (limited to 'tests/libgit2')
-rw-r--r--tests/libgit2/core/opts.c15
-rw-r--r--tests/libgit2/repo/objectformat.c69
2 files changed, 78 insertions, 6 deletions
diff --git a/tests/libgit2/core/opts.c b/tests/libgit2/core/opts.c
index e8f65d510..486ff58c6 100644
--- a/tests/libgit2/core/opts.c
+++ b/tests/libgit2/core/opts.c
@@ -34,8 +34,9 @@ void test_core_opts__extensions_query(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
- cl_assert_equal_sz(out.count, 1);
+ cl_assert_equal_sz(out.count, 2);
cl_assert_equal_s("noop", out.strings[0]);
+ cl_assert_equal_s("objectformat", out.strings[1]);
git_strarray_dispose(&out);
}
@@ -48,9 +49,10 @@ void test_core_opts__extensions_add(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
- cl_assert_equal_sz(out.count, 2);
+ cl_assert_equal_sz(out.count, 3);
cl_assert_equal_s("noop", out.strings[0]);
- cl_assert_equal_s("foo", out.strings[1]);
+ cl_assert_equal_s("objectformat", out.strings[1]);
+ cl_assert_equal_s("foo", out.strings[2]);
git_strarray_dispose(&out);
}
@@ -63,9 +65,10 @@ void test_core_opts__extensions_remove(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
- cl_assert_equal_sz(out.count, 2);
- cl_assert_equal_s("bar", out.strings[0]);
- cl_assert_equal_s("baz", out.strings[1]);
+ cl_assert_equal_sz(out.count, 3);
+ cl_assert_equal_s("objectformat", out.strings[0]);
+ cl_assert_equal_s("bar", out.strings[1]);
+ cl_assert_equal_s("baz", out.strings[2]);
git_strarray_dispose(&out);
}
diff --git a/tests/libgit2/repo/objectformat.c b/tests/libgit2/repo/objectformat.c
new file mode 100644
index 000000000..3518115f4
--- /dev/null
+++ b/tests/libgit2/repo/objectformat.c
@@ -0,0 +1,69 @@
+#include "clar_libgit2.h"
+#include "futils.h"
+#include "sysdir.h"
+#include "repository.h"
+#include <ctype.h>
+
+git_repository *repo;
+git_config *config;
+
+void test_repo_objectformat__initialize(void)
+{
+ repo = cl_git_sandbox_init("empty_bare.git");
+
+ cl_git_pass(git_repository_config(&config, repo));
+ cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 1));
+}
+
+void test_repo_objectformat__cleanup(void)
+{
+ git_config_free(config);
+ cl_git_sandbox_cleanup();
+}
+
+void test_repo_objectformat__unspecified(void)
+{
+ git_repository *other;
+
+ cl_git_pass(git_repository_open(&other, "empty_bare.git"));
+ cl_assert_equal_i(GIT_OID_SHA1, git_repository_oid_type(other));
+ git_repository_free(other);
+}
+
+void test_repo_objectformat__sha1(void)
+{
+ git_repository *other;
+
+ cl_git_pass(git_config_set_string(config, "extensions.objectformat", "sha1"));
+
+ cl_git_pass(git_repository_open(&other, "empty_bare.git"));
+ cl_assert_equal_i(GIT_OID_SHA1, git_repository_oid_type(other));
+ git_repository_free(other);
+}
+
+void test_repo_objectformat__sha256(void)
+{
+#ifndef GIT_EXPERIMENTAL_SHA256
+ cl_skip();
+#else
+ git_repository *other;
+
+ cl_git_pass(git_config_set_string(config, "extensions.objectformat", "sha256"));
+
+ cl_git_pass(git_repository_open(&other, "empty_bare.git"));
+ cl_assert_equal_i(GIT_OID_SHA256, git_repository_oid_type(other));
+ git_repository_free(other);
+#endif
+}
+
+void test_repo_objectformat__invalid(void)
+{
+ git_repository *other;
+
+ cl_git_pass(git_config_set_string(config, "extensions.objectformat", "bogus"));
+
+ cl_git_fail_with(GIT_EINVALID, git_repository_open(&other, "empty_bare.git"));
+ cl_assert_equal_s("unknown object format 'bogus'", git_error_last()->message);
+ git_repository_free(other);
+}
+