collision.c 2.48 KB
Newer Older
1 2 3 4
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/index.h"

5 6 7 8 9 10 11 12 13 14 15 16 17
static git_repository *g_repo;
static git_odb *g_odb;
static git_index *g_index;
static git_oid g_empty_id;

void test_index_collision__initialize(void)
{
	g_repo = cl_git_sandbox_init("empty_standard_repo");
	cl_git_pass(git_repository_odb(&g_odb, g_repo));
	cl_git_pass(git_repository_index(&g_index, g_repo));

	cl_git_pass(git_odb_write(&g_empty_id, g_odb, "", 0, GIT_OBJ_BLOB));
}
18 19 20

void test_index_collision__cleanup(void)
{
21 22
	git_index_free(g_index);
	git_odb_free(g_odb);
23 24 25 26 27 28 29 30 31 32 33 34 35 36
	cl_git_sandbox_cleanup();
}

void test_index_collision__add(void)
{
	git_index_entry entry;
	git_oid tree_id;
	git_tree *tree;

	memset(&entry, 0, sizeof(entry));
	entry.ctime.seconds = 12346789;
	entry.mtime.seconds = 12346789;
	entry.mode  = 0100644;
	entry.file_size = 0;
37
	git_oid_cpy(&entry.id, &g_empty_id);
38 39

	entry.path = "a/b";
40
	cl_git_pass(git_index_add(g_index, &entry));
41 42 43

	/* create a tree/blob collision */
	entry.path = "a/b/c";
44
	cl_git_fail(git_index_add(g_index, &entry));
45

46 47
	cl_git_pass(git_index_write_tree(&tree_id, g_index));
	cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
48 49 50

	git_tree_free(tree);
}
51 52 53 54 55 56 57 58 59 60

void test_index_collision__add_with_highstage_1(void)
{
	git_index_entry entry;

	memset(&entry, 0, sizeof(entry));
	entry.ctime.seconds = 12346789;
	entry.mtime.seconds = 12346789;
	entry.mode  = 0100644;
	entry.file_size = 0;
61
	git_oid_cpy(&entry.id, &g_empty_id);
62 63

	entry.path = "a/b";
64
	GIT_IDXENTRY_STAGE_SET(&entry, 2);
65
	cl_git_pass(git_index_add(g_index, &entry));
66 67 68 69

	/* create a blob beneath the previous tree entry */
	entry.path = "a/b/c";
	entry.flags = 0;
70
	cl_git_pass(git_index_add(g_index, &entry));
71 72 73

	/* create another tree entry above the blob */
	entry.path = "a/b";
74
	GIT_IDXENTRY_STAGE_SET(&entry, 1);
75
	cl_git_pass(git_index_add(g_index, &entry));
76 77 78 79 80 81 82 83 84 85 86
}

void test_index_collision__add_with_highstage_2(void)
{
	git_index_entry entry;

	memset(&entry, 0, sizeof(entry));
	entry.ctime.seconds = 12346789;
	entry.mtime.seconds = 12346789;
	entry.mode  = 0100644;
	entry.file_size = 0;
87
	git_oid_cpy(&entry.id, &g_empty_id);
88 89

	entry.path = "a/b/c";
90
	GIT_IDXENTRY_STAGE_SET(&entry, 1);
91
	cl_git_pass(git_index_add(g_index, &entry));
92 93 94

	/* create a blob beneath the previous tree entry */
	entry.path = "a/b/c";
95
	GIT_IDXENTRY_STAGE_SET(&entry, 2);
96
	cl_git_pass(git_index_add(g_index, &entry));
97 98 99

	/* create another tree entry above the blob */
	entry.path = "a/b";
100
	GIT_IDXENTRY_STAGE_SET(&entry, 3);
101
	cl_git_pass(git_index_add(g_index, &entry));
102
}