stage.c 1.77 KB
Newer Older
Edward Thomson committed
1 2 3 4 5 6 7 8 9 10
#include "clar_libgit2.h"
#include "index.h"
#include "git2/repository.h"

static git_repository *repo;
static git_index *repo_index;

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

11
/* Fixture setup and teardown */
Edward Thomson committed
12 13 14 15 16 17 18 19 20
void test_index_stage__initialize(void)
{
	repo = cl_git_sandbox_init("mergedrepo");
	git_repository_index(&repo_index, repo);
}

void test_index_stage__cleanup(void)
{
	git_index_free(repo_index);
21 22
	repo_index = NULL;

Edward Thomson committed
23 24 25 26 27 28
	cl_git_sandbox_cleanup();
}


void test_index_stage__add_always_adds_stage_0(void)
{
29
	size_t entry_idx;
Ben Straub committed
30
	const git_index_entry *entry;
Edward Thomson committed
31 32 33

    cl_git_mkfile("./mergedrepo/new-file.txt", "new-file\n");

34
	cl_git_pass(git_index_add_bypath(repo_index, "new-file.txt"));
Edward Thomson committed
35

36
	cl_assert(!git_index_find(&entry_idx, repo_index, "new-file.txt"));
Edward Thomson committed
37 38 39 40 41 42
	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
	cl_assert(git_index_entry_stage(entry) == 0);
}

void test_index_stage__find_gets_first_stage(void)
{
43
	size_t entry_idx;
Ben Straub committed
44
	const git_index_entry *entry;
Edward Thomson committed
45

46
	cl_assert(!git_index_find(&entry_idx, repo_index, "one.txt"));
Edward Thomson committed
47 48 49
	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
	cl_assert(git_index_entry_stage(entry) == 0);

50
	cl_assert(!git_index_find(&entry_idx, repo_index, "two.txt"));
Edward Thomson committed
51 52 53
	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
	cl_assert(git_index_entry_stage(entry) == 0);

54
	cl_assert(!git_index_find(&entry_idx, repo_index, "conflicts-one.txt"));
Edward Thomson committed
55 56 57
	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
	cl_assert(git_index_entry_stage(entry) == 1);

58
	cl_assert(!git_index_find(&entry_idx, repo_index, "conflicts-two.txt"));
Edward Thomson committed
59 60 61 62
	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
	cl_assert(git_index_entry_stage(entry) == 1);
}