names.c 2.77 KB
Newer Older
Edward Thomson committed
1 2
#include "clar_libgit2.h"
#include "index.h"
3
#include "git2/sys/index.h"
Edward Thomson committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include "git2/repository.h"
#include "../reset/reset_helpers.h"

static git_repository *repo;
static git_index *repo_index;

#define TEST_REPO_PATH "mergedrepo"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"

// Fixture setup and teardown
void test_index_names__initialize(void)
{
	repo = cl_git_sandbox_init("mergedrepo");
	git_repository_index(&repo_index, repo);
}

void test_index_names__cleanup(void)
{
	git_index_free(repo_index);
	repo_index = NULL;
nulltoken committed
24

Edward Thomson committed
25 26 27 28 29 30 31 32 33 34
	cl_git_sandbox_cleanup();
}

void test_index_names__add(void)
{
	const git_index_name_entry *conflict_name;

	cl_git_pass(git_index_name_add(repo_index, "ancestor", "ours", "theirs"));
	cl_git_pass(git_index_name_add(repo_index, "ancestor2", "ours2", NULL));
	cl_git_pass(git_index_name_add(repo_index, "ancestor3", NULL, "theirs3"));
nulltoken committed
35

Edward Thomson committed
36
	cl_assert(git_index_name_entrycount(repo_index) == 3);
nulltoken committed
37

Edward Thomson committed
38 39 40 41
	conflict_name = git_index_name_get_byindex(repo_index, 0);
	cl_assert(strcmp(conflict_name->ancestor, "ancestor") == 0);
	cl_assert(strcmp(conflict_name->ours, "ours") == 0);
	cl_assert(strcmp(conflict_name->theirs, "theirs") == 0);
nulltoken committed
42

Edward Thomson committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56
	conflict_name = git_index_name_get_byindex(repo_index, 1);
	cl_assert(strcmp(conflict_name->ancestor, "ancestor2") == 0);
	cl_assert(strcmp(conflict_name->ours, "ours2") == 0);
	cl_assert(conflict_name->theirs == NULL);

	conflict_name = git_index_name_get_byindex(repo_index, 2);
	cl_assert(strcmp(conflict_name->ancestor, "ancestor3") == 0);
	cl_assert(conflict_name->ours == NULL);
	cl_assert(strcmp(conflict_name->theirs, "theirs3") == 0);
}

void test_index_names__roundtrip(void)
{
	const git_index_name_entry *conflict_name;
nulltoken committed
57

Edward Thomson committed
58 59 60
	cl_git_pass(git_index_name_add(repo_index, "ancestor", "ours", "theirs"));
	cl_git_pass(git_index_name_add(repo_index, "ancestor2", "ours2", NULL));
	cl_git_pass(git_index_name_add(repo_index, "ancestor3", NULL, "theirs3"));
nulltoken committed
61

Edward Thomson committed
62 63 64
	cl_git_pass(git_index_write(repo_index));
	git_index_clear(repo_index);
	cl_assert(git_index_name_entrycount(repo_index) == 0);
nulltoken committed
65

Edward Thomson committed
66 67
	cl_git_pass(git_index_read(repo_index));
	cl_assert(git_index_name_entrycount(repo_index) == 3);
nulltoken committed
68

Edward Thomson committed
69 70 71 72
	conflict_name = git_index_name_get_byindex(repo_index, 0);
	cl_assert(strcmp(conflict_name->ancestor, "ancestor") == 0);
	cl_assert(strcmp(conflict_name->ours, "ours") == 0);
	cl_assert(strcmp(conflict_name->theirs, "theirs") == 0);
nulltoken committed
73

Edward Thomson committed
74 75 76 77
	conflict_name = git_index_name_get_byindex(repo_index, 1);
	cl_assert(strcmp(conflict_name->ancestor, "ancestor2") == 0);
	cl_assert(strcmp(conflict_name->ours, "ours2") == 0);
	cl_assert(conflict_name->theirs == NULL);
nulltoken committed
78

Edward Thomson committed
79 80 81 82
	conflict_name = git_index_name_get_byindex(repo_index, 2);
	cl_assert(strcmp(conflict_name->ancestor, "ancestor3") == 0);
	cl_assert(conflict_name->ours == NULL);
	cl_assert(strcmp(conflict_name->theirs, "theirs3") == 0);
nulltoken committed
83

Edward Thomson committed
84
}