flags.c 3.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "clar_libgit2.h"
#include "git2/attr.h"

void test_attr_flags__cleanup(void)
{
	cl_git_sandbox_cleanup();
}

void test_attr_flags__bare(void)
{
	git_repository *repo = cl_git_sandbox_init("testrepo.git");
	const char *value;

	cl_assert(git_repository_is_bare(repo));

	cl_git_pass(git_attr_get(
17
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM, "README.md", "diff"));
18 19 20 21 22 23 24 25 26 27 28 29
	cl_assert(GIT_ATTR_UNSPECIFIED(value));
}

void test_attr_flags__index_vs_workdir(void)
{
	git_repository *repo = cl_git_sandbox_init("attr_index");
	const char *value;

	cl_assert(!git_repository_is_bare(repo));

	/* wd then index */
	cl_git_pass(git_attr_get(
30 31
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
		"README.md", "bar"));
32 33 34
	cl_assert(GIT_ATTR_FALSE(value));

	cl_git_pass(git_attr_get(
35 36
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
		"README.md", "blargh"));
37 38 39
	cl_assert_equal_s(value, "goop");

	cl_git_pass(git_attr_get(
40 41
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
		"README.txt", "foo"));
42 43 44 45
	cl_assert(GIT_ATTR_FALSE(value));

	/* index then wd */
	cl_git_pass(git_attr_get(
46 47
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
		"README.md", "bar"));
48 49 50
	cl_assert(GIT_ATTR_TRUE(value));

	cl_git_pass(git_attr_get(
51 52
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
		"README.md", "blargh"));
53 54 55
	cl_assert_equal_s(value, "garble");

	cl_git_pass(git_attr_get(
56 57
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
		"README.txt", "foo"));
58 59 60 61 62 63 64 65 66 67
	cl_assert(GIT_ATTR_TRUE(value));
}

void test_attr_flags__subdir(void)
{
	git_repository *repo = cl_git_sandbox_init("attr_index");
	const char *value;

	/* wd then index */
	cl_git_pass(git_attr_get(
68 69
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
		"sub/sub/README.md", "bar"));
70 71 72
	cl_assert_equal_s(value, "1234");

	cl_git_pass(git_attr_get(
73 74
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
		"sub/sub/README.txt", "another"));
75 76 77
	cl_assert_equal_s(value, "one");

	cl_git_pass(git_attr_get(
78 79
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
		"sub/sub/README.txt", "again"));
80 81 82
	cl_assert(GIT_ATTR_TRUE(value));

	cl_git_pass(git_attr_get(
83 84
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
		"sub/sub/README.txt", "beep"));
85 86 87 88
	cl_assert_equal_s(value, "10");

	/* index then wd */
	cl_git_pass(git_attr_get(
89 90
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
		"sub/sub/README.md", "bar"));
91 92 93
	cl_assert_equal_s(value, "1337");

	cl_git_pass(git_attr_get(
94 95
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
		"sub/sub/README.txt", "another"));
96 97 98
	cl_assert_equal_s(value, "one");

	cl_git_pass(git_attr_get(
99 100
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
		"sub/sub/README.txt", "again"));
101 102 103
	cl_assert(GIT_ATTR_TRUE(value));

	cl_git_pass(git_attr_get(
104 105
		&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
		"sub/sub/README.txt", "beep"));
106 107 108
	cl_assert_equal_s(value, "5");
}