collision.c 2.61 KB
Newer Older
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
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/index.h"

git_repository *repo = NULL;

void test_index_collision__cleanup(void)
{
	cl_git_sandbox_cleanup();
	repo = NULL;
}

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

	repo = cl_git_sandbox_init("empty_standard_repo");
	cl_git_pass(git_repository_index(&index, repo));

	memset(&entry, 0, sizeof(entry));
	entry.ctime.seconds = 12346789;
	entry.mtime.seconds = 12346789;
	entry.mode  = 0100644;
	entry.file_size = 0;
	git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");

	entry.path = "a/b";
	cl_git_pass(git_index_add(index, &entry));

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

	cl_git_pass(git_index_write_tree(&tree_id, index));
	cl_git_pass(git_tree_lookup(&tree, repo, &tree_id));

	git_tree_free(tree);
	git_index_free(index);
}
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

void test_index_collision__add_with_highstage_1(void)
{
	git_index *index;
	git_index_entry entry;

	repo = cl_git_sandbox_init("empty_standard_repo");
	cl_git_pass(git_repository_index(&index, repo));

	memset(&entry, 0, sizeof(entry));
	entry.ctime.seconds = 12346789;
	entry.mtime.seconds = 12346789;
	entry.mode  = 0100644;
	entry.file_size = 0;
	git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");

	entry.path = "a/b";
60
	GIT_IDXENTRY_STAGE_SET(&entry, 2);
61 62 63 64 65 66 67 68 69
	cl_git_pass(git_index_add(index, &entry));

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

	/* create another tree entry above the blob */
	entry.path = "a/b";
70
	GIT_IDXENTRY_STAGE_SET(&entry, 1);
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
	cl_git_pass(git_index_add(index, &entry));

	git_index_free(index);
}

void test_index_collision__add_with_highstage_2(void)
{
	git_index *index;
	git_index_entry entry;

	repo = cl_git_sandbox_init("empty_standard_repo");
	cl_git_pass(git_repository_index(&index, repo));

	memset(&entry, 0, sizeof(entry));
	entry.ctime.seconds = 12346789;
	entry.mtime.seconds = 12346789;
	entry.mode  = 0100644;
	entry.file_size = 0;
	git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");

	entry.path = "a/b/c";
92
	GIT_IDXENTRY_STAGE_SET(&entry, 1);
93 94 95 96
	cl_git_pass(git_index_add(index, &entry));

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

	/* create another tree entry above the blob */
	entry.path = "a/b";
102
	GIT_IDXENTRY_STAGE_SET(&entry, 3);
103 104 105 106
	cl_git_pass(git_index_add(index, &entry));

	git_index_free(index);
}