summaryrefslogtreecommitdiff
path: root/tests-clar/checkout/checkout.c
blob: 9ad41d0328e6f9170c666692a97826c5807190d7 (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
73
74
75
76
77
78
79
80
81
#include "clar_libgit2.h"

#include "git2/checkout.h"
#include "repository.h"

#define DO_LOCAL_TEST 0
#define DO_LIVE_NETWORK_TESTS 1
#define LIVE_REPO_URL "http://github.com/libgit2/node-gitteh"


static git_repository *g_repo;

void test_checkout_checkout__initialize(void)
{
	g_repo = cl_git_sandbox_init("testrepo");
}

void test_checkout_checkout__cleanup(void)
{
	cl_git_sandbox_cleanup();
}


static void test_file_contents(const char *path, const char *expectedcontents)
{
	int fd;
	char buffer[1024] = {0};
	fd = p_open(path, O_RDONLY);
	cl_assert(fd);
	cl_assert_equal_i(p_read(fd, buffer, 1024), strlen(expectedcontents));
	cl_assert_equal_s(expectedcontents, buffer);
	cl_git_pass(p_close(fd));
}


void test_checkout_checkout__bare(void)
{
	cl_git_sandbox_cleanup();
	g_repo = cl_git_sandbox_init("testrepo.git");
	cl_git_fail(git_checkout_force(g_repo, NULL));
}

void test_checkout_checkout__default(void)
{
	cl_git_pass(git_checkout_force(g_repo, NULL));
	test_file_contents("./testrepo/README", "hey there\n");
	test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
	test_file_contents("./testrepo/new.txt", "my new file\n");
}


void test_checkout_checkout__crlf(void)
{
	const char *attributes =
		"branch_file.txt text eol=crlf\n"
		"README text eol=cr\n"
		"new.txt text eol=lf\n";
	cl_git_mkfile("./testrepo/.gitattributes", attributes);
	cl_git_pass(git_checkout_force(g_repo, NULL));
	/* test_file_contents("./testrepo/README", "hey there\n"); */
	/* test_file_contents("./testrepo/new.txt", "my new file\n"); */
	/* test_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n"); */
}

void test_checkout_checkout__stats(void)
{
	/* TODO */
}

void test_checkout_checkout__links(void)
{
	char link_data[1024];
	size_t link_size = 1024;

	cl_git_pass(git_checkout_force(g_repo, NULL));
	link_size = p_readlink("./testrepo/link_to_new.txt", link_data, link_size);
	cl_assert_equal_i(link_size, strlen("new.txt"));
	link_data[link_size] = '\0';
	cl_assert_equal_s(link_data, "new.txt");
	test_file_contents("./testrepo/link_to_new.txt", "my new file\n");
}