summaryrefslogtreecommitdiff
path: root/tests/repo/extensions.c
blob: e7772acd512ab7e0734d66fc0493d0118824000a (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
70
71
72
#include "clar_libgit2.h"
#include "futils.h"
#include "sysdir.h"
#include <ctype.h>

git_repository *repo;

void test_repo_extensions__initialize(void)
{
	git_config *config;

	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));
	git_config_free(config);
}

void test_repo_extensions__cleanup(void)
{
	cl_git_sandbox_cleanup();
	cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, NULL, 0));
}

void test_repo_extensions__builtin(void)
{
	git_repository *extended;

	cl_repo_set_string(repo, "extensions.noop", "foobar");

	cl_git_pass(git_repository_open(&extended, "empty_bare.git"));
	cl_assert(git_repository_path(extended) != NULL);
	cl_assert(git__suffixcmp(git_repository_path(extended), "/") == 0);
	git_repository_free(extended);
}

void test_repo_extensions__negate_builtin(void)
{
	const char *in[] = { "foo", "!noop", "baz" };
	git_repository *extended;

	cl_repo_set_string(repo, "extensions.noop", "foobar");

	cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));

	cl_git_fail(git_repository_open(&extended, "empty_bare.git"));
	git_repository_free(extended);
}

void test_repo_extensions__unsupported(void)
{
	git_repository *extended = NULL;

	cl_repo_set_string(repo, "extensions.unknown", "foobar");

	cl_git_fail(git_repository_open(&extended, "empty_bare.git"));
	git_repository_free(extended);
}

void test_repo_extensions__adds_extension(void)
{
	const char *in[] = { "foo", "!noop", "newextension", "baz" };
	git_repository *extended;

	cl_repo_set_string(repo, "extensions.newextension", "foobar");
	cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));

	cl_git_pass(git_repository_open(&extended, "empty_bare.git"));
	cl_assert(git_repository_path(extended) != NULL);
	cl_assert(git__suffixcmp(git_repository_path(extended), "/") == 0);
	git_repository_free(extended);
}