Tag
Hash :
9994cd3f
Author :
Date :
2018-06-25T11:56:52
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
#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"
/* Fixture setup and teardown */
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);
repo_index = NULL;
cl_git_sandbox_cleanup();
}
void test_index_stage__add_always_adds_stage_0(void)
{
size_t entry_idx;
const git_index_entry *entry;
cl_git_mkfile("./mergedrepo/new-file.txt", "new-file\n");
cl_git_pass(git_index_add_bypath(repo_index, "new-file.txt"));
cl_assert(!git_index_find(&entry_idx, repo_index, "new-file.txt"));
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)
{
size_t entry_idx;
const git_index_entry *entry;
cl_assert(!git_index_find(&entry_idx, repo_index, "one.txt"));
cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
cl_assert(git_index_entry_stage(entry) == 0);
cl_assert(!git_index_find(&entry_idx, repo_index, "two.txt"));
cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
cl_assert(git_index_entry_stage(entry) == 0);
cl_assert(!git_index_find(&entry_idx, repo_index, "conflicts-one.txt"));
cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
cl_assert(git_index_entry_stage(entry) == 1);
cl_assert(!git_index_find(&entry_idx, repo_index, "conflicts-two.txt"));
cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
cl_assert(git_index_entry_stage(entry) == 1);
}