]>
Commit | Line | Data |
---|---|---|
95fbedcd RB |
1 | #include "clar_libgit2.h" |
2 | #include "git2/repository.h" | |
3 | #include "git2/index.h" | |
4 | ||
5 | git_repository *repo = NULL; | |
6 | ||
7 | void test_index_collision__cleanup(void) | |
8 | { | |
9 | cl_git_sandbox_cleanup(); | |
10 | repo = NULL; | |
11 | } | |
12 | ||
13 | void test_index_collision__add(void) | |
14 | { | |
15 | git_index *index; | |
16 | git_index_entry entry; | |
17 | git_oid tree_id; | |
18 | git_tree *tree; | |
19 | ||
20 | repo = cl_git_sandbox_init("empty_standard_repo"); | |
21 | cl_git_pass(git_repository_index(&index, repo)); | |
22 | ||
23 | memset(&entry, 0, sizeof(entry)); | |
24 | entry.ctime.seconds = 12346789; | |
25 | entry.mtime.seconds = 12346789; | |
26 | entry.mode = 0100644; | |
27 | entry.file_size = 0; | |
28 | git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); | |
29 | ||
30 | entry.path = "a/b"; | |
31 | cl_git_pass(git_index_add(index, &entry)); | |
32 | ||
33 | /* create a tree/blob collision */ | |
34 | entry.path = "a/b/c"; | |
35 | cl_git_fail(git_index_add(index, &entry)); | |
36 | ||
37 | cl_git_pass(git_index_write_tree(&tree_id, index)); | |
38 | cl_git_pass(git_tree_lookup(&tree, repo, &tree_id)); | |
39 | ||
40 | git_tree_free(tree); | |
41 | git_index_free(index); | |
42 | } | |
bae8bea0 ET |
43 | |
44 | void test_index_collision__add_with_highstage_1(void) | |
45 | { | |
46 | git_index *index; | |
47 | git_index_entry entry; | |
48 | ||
49 | repo = cl_git_sandbox_init("empty_standard_repo"); | |
50 | cl_git_pass(git_repository_index(&index, repo)); | |
51 | ||
52 | memset(&entry, 0, sizeof(entry)); | |
53 | entry.ctime.seconds = 12346789; | |
54 | entry.mtime.seconds = 12346789; | |
55 | entry.mode = 0100644; | |
56 | entry.file_size = 0; | |
57 | git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); | |
58 | ||
59 | entry.path = "a/b"; | |
60 | entry.flags = (2 << GIT_IDXENTRY_STAGESHIFT); | |
61 | cl_git_pass(git_index_add(index, &entry)); | |
62 | ||
63 | /* create a blob beneath the previous tree entry */ | |
64 | entry.path = "a/b/c"; | |
65 | entry.flags = 0; | |
66 | cl_git_pass(git_index_add(index, &entry)); | |
67 | ||
68 | /* create another tree entry above the blob */ | |
69 | entry.path = "a/b"; | |
70 | entry.flags = (1 << GIT_IDXENTRY_STAGESHIFT); | |
71 | cl_git_pass(git_index_add(index, &entry)); | |
72 | ||
73 | git_index_free(index); | |
74 | } | |
75 | ||
76 | void test_index_collision__add_with_highstage_2(void) | |
77 | { | |
78 | git_index *index; | |
79 | git_index_entry entry; | |
80 | ||
81 | repo = cl_git_sandbox_init("empty_standard_repo"); | |
82 | cl_git_pass(git_repository_index(&index, repo)); | |
83 | ||
84 | memset(&entry, 0, sizeof(entry)); | |
85 | entry.ctime.seconds = 12346789; | |
86 | entry.mtime.seconds = 12346789; | |
87 | entry.mode = 0100644; | |
88 | entry.file_size = 0; | |
89 | git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); | |
90 | ||
91 | entry.path = "a/b/c"; | |
92 | entry.flags = (1 << GIT_IDXENTRY_STAGESHIFT); | |
93 | cl_git_pass(git_index_add(index, &entry)); | |
94 | ||
95 | /* create a blob beneath the previous tree entry */ | |
96 | entry.path = "a/b/c"; | |
97 | entry.flags = (2 << GIT_IDXENTRY_STAGESHIFT); | |
98 | cl_git_pass(git_index_add(index, &entry)); | |
99 | ||
100 | /* create another tree entry above the blob */ | |
101 | entry.path = "a/b"; | |
102 | entry.flags = (3 << GIT_IDXENTRY_STAGESHIFT); | |
103 | cl_git_pass(git_index_add(index, &entry)); | |
104 | ||
105 | git_index_free(index); | |
106 | } |