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