summaryrefslogtreecommitdiff
path: root/tests/libgit2/repo/objectformat.c
blob: 3518115f4d92461a63d976131c6e922843db5c06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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);
}