Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4afe536

Browse files
author
Edward Thomson
committed
tests: use legitimate object ids
Use legitimate (existing) object IDs in tests so that we have the ability to turn on strict object validation when running tests.
1 parent 98c3414 commit 4afe536

File tree

12 files changed

+57
-44
lines changed

12 files changed

+57
-44
lines changed

tests/diff/index.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ static void do_conflicted_diff(diff_expects *exp, unsigned long flags)
185185
ancestor.path = ours.path = theirs.path = "staged_changes";
186186
ancestor.mode = ours.mode = theirs.mode = GIT_FILEMODE_BLOB;
187187

188-
git_oid_fromstr(&ancestor.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
189-
git_oid_fromstr(&ours.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
190-
git_oid_fromstr(&theirs.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
188+
git_oid_fromstr(&ancestor.id, "d427e0b2e138501a3d15cc376077a3631e15bd46");
189+
git_oid_fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
190+
git_oid_fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863");
191191

192192
cl_git_pass(git_index_conflict_add(index, &ancestor, &ours, &theirs));
193193
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, index, &opts));
@@ -255,7 +255,7 @@ void test_diff_index__not_in_head_conflicted(void)
255255

256256
theirs.path = "file_not_in_head";
257257
theirs.mode = GIT_FILEMODE_BLOB;
258-
git_oid_fromstr(&theirs.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
258+
git_oid_fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863");
259259
cl_git_pass(git_index_conflict_add(index, NULL, NULL, &theirs));
260260

261261
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, index, NULL));

tests/diff/workdir.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ void test_diff_workdir__to_index_with_conflicts(void)
8585
/* Adding an entry that represents a rename gets two files in conflict */
8686
our_entry.path = "subdir/modified_file";
8787
our_entry.mode = 0100644;
88+
git_oid_fromstr(&our_entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
8889

8990
their_entry.path = "subdir/rename_conflict";
9091
their_entry.mode = 0100644;
92+
git_oid_fromstr(&their_entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863");
9193

9294
cl_git_pass(git_repository_index(&index, g_repo));
9395
cl_git_pass(git_index_conflict_add(index, NULL, &our_entry, &their_entry));
@@ -1975,9 +1977,9 @@ void test_diff_workdir__to_index_conflicted(void) {
19751977

19761978
ancestor.path = ours.path = theirs.path = "_file";
19771979
ancestor.mode = ours.mode = theirs.mode = 0100644;
1978-
git_oid_fromstr(&ancestor.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
1979-
git_oid_fromstr(&ours.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
1980-
git_oid_fromstr(&theirs.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
1980+
git_oid_fromstr(&ancestor.id, "d427e0b2e138501a3d15cc376077a3631e15bd46");
1981+
git_oid_fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
1982+
git_oid_fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863");
19811983
cl_git_pass(git_index_conflict_add(index, &ancestor, &ours, &theirs));
19821984

19831985
cl_git_pass(git_diff_tree_to_index(&diff1, g_repo, a, index, NULL));

tests/index/bypath.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ void test_index_bypath__add_honors_existing_case_2(void)
134134
clar__skip();
135135

136136
dummy.mode = GIT_FILEMODE_BLOB;
137+
cl_git_pass(git_oid_fromstr(&dummy.id, "f990a25a74d1a8281ce2ab018ea8df66795cd60b"));
137138

138139
/* note that `git_index_add` does no checking to canonical directories */
139140
dummy.path = "Just_a_dir/file0.txt";
@@ -189,6 +190,7 @@ void test_index_bypath__add_honors_existing_case_3(void)
189190
clar__skip();
190191

191192
dummy.mode = GIT_FILEMODE_BLOB;
193+
cl_git_pass(git_oid_fromstr(&dummy.id, "f990a25a74d1a8281ce2ab018ea8df66795cd60b"));
192194

193195
dummy.path = "just_a_dir/filea.txt";
194196
cl_git_pass(git_index_add(g_idx, &dummy));
@@ -219,6 +221,7 @@ void test_index_bypath__add_honors_existing_case_4(void)
219221
clar__skip();
220222

221223
dummy.mode = GIT_FILEMODE_BLOB;
224+
cl_git_pass(git_oid_fromstr(&dummy.id, "f990a25a74d1a8281ce2ab018ea8df66795cd60b"));
222225

223226
dummy.path = "just_a_dir/a/b/c/d/e/file1.txt";
224227
cl_git_pass(git_index_add(g_idx, &dummy));

tests/index/cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void test_index_cache__read_tree_no_children(void)
111111
memset(&entry, 0x0, sizeof(git_index_entry));
112112
entry.path = "new.txt";
113113
entry.mode = GIT_FILEMODE_BLOB;
114-
git_oid_fromstr(&entry.id, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
114+
git_oid_fromstr(&entry.id, "d4bcc68acd4410bf836a39f20afb2c2ece09584e");
115115

116116
cl_git_pass(git_index_add(index, &entry));
117117
cl_assert_equal_i(-1, index->tree->entry_count);
@@ -191,7 +191,7 @@ void test_index_cache__read_tree_children(void)
191191
memset(&entry, 0x0, sizeof(git_index_entry));
192192
entry.path = "top-level";
193193
entry.mode = GIT_FILEMODE_BLOB;
194-
git_oid_fromstr(&entry.id, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
194+
git_oid_fromstr(&entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
195195
cl_git_pass(git_index_add(index, &entry));
196196

197197

@@ -217,7 +217,7 @@ void test_index_cache__read_tree_children(void)
217217

218218
/* override with a slightly different id, also dummy */
219219
entry.path = "subdir/some-file";
220-
git_oid_fromstr(&entry.id, "45b983be36b73c0788dc9cbcb76cbb80fc7bb058");
220+
git_oid_fromstr(&entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
221221
cl_git_pass(git_index_add(index, &entry));
222222

223223
cl_assert_equal_i(-1, index->tree->entry_count);

tests/index/conflicts.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ static git_index *repo_index;
1616
#define CONFLICTS_TWO_OUR_OID "8b3f43d2402825c200f835ca1762413e386fd0b2"
1717
#define CONFLICTS_TWO_THEIR_OID "220bd62631c8cf7a83ef39c6b94595f00517211e"
1818

19-
#define TEST_STAGED_OID "beefdadafeedabedcafedeedbabedeadbeaddeaf"
20-
#define TEST_ANCESTOR_OID "f00ff00ff00ff00ff00ff00ff00ff00ff00ff00f"
21-
#define TEST_OUR_OID "b44bb44bb44bb44bb44bb44bb44bb44bb44bb44b"
22-
#define TEST_THEIR_OID "0123456789abcdef0123456789abcdef01234567"
23-
2419
// Fixture setup and teardown
2520
void test_index_conflicts__initialize(void)
2621
{
@@ -49,17 +44,17 @@ void test_index_conflicts__add(void)
4944
ancestor_entry.path = "test-one.txt";
5045
ancestor_entry.mode = 0100644;
5146
GIT_IDXENTRY_STAGE_SET(&ancestor_entry, 1);
52-
git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
47+
git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID);
5348

5449
our_entry.path = "test-one.txt";
5550
our_entry.mode = 0100644;
5651
GIT_IDXENTRY_STAGE_SET(&our_entry, 2);
57-
git_oid_fromstr(&our_entry.id, TEST_OUR_OID);
52+
git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID);
5853

5954
their_entry.path = "test-one.txt";
6055
their_entry.mode = 0100644;
6156
GIT_IDXENTRY_STAGE_SET(&ancestor_entry, 2);
62-
git_oid_fromstr(&their_entry.id, TEST_THEIR_OID);
57+
git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID);
6358

6459
cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry));
6560

@@ -80,17 +75,17 @@ void test_index_conflicts__add_fixes_incorrect_stage(void)
8075
ancestor_entry.path = "test-one.txt";
8176
ancestor_entry.mode = 0100644;
8277
GIT_IDXENTRY_STAGE_SET(&ancestor_entry, 3);
83-
git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
78+
git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID);
8479

8580
our_entry.path = "test-one.txt";
8681
our_entry.mode = 0100644;
8782
GIT_IDXENTRY_STAGE_SET(&our_entry, 1);
88-
git_oid_fromstr(&our_entry.id, TEST_OUR_OID);
83+
git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID);
8984

9085
their_entry.path = "test-one.txt";
9186
their_entry.mode = 0100644;
9287
GIT_IDXENTRY_STAGE_SET(&their_entry, 2);
93-
git_oid_fromstr(&their_entry.id, TEST_THEIR_OID);
88+
git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID);
9489

9590
cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry));
9691

@@ -105,36 +100,33 @@ void test_index_conflicts__add_fixes_incorrect_stage(void)
105100

106101
void test_index_conflicts__add_removes_stage_zero(void)
107102
{
108-
git_index_entry staged, ancestor_entry, our_entry, their_entry;
103+
git_index_entry ancestor_entry, our_entry, their_entry;
109104
const git_index_entry *conflict_entry[3];
110105

111106
cl_assert(git_index_entrycount(repo_index) == 8);
112107

113-
memset(&staged, 0x0, sizeof(git_index_entry));
114108
memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
115109
memset(&our_entry, 0x0, sizeof(git_index_entry));
116110
memset(&their_entry, 0x0, sizeof(git_index_entry));
117111

118-
staged.path = "test-one.txt";
119-
staged.mode = 0100644;
120-
git_oid_fromstr(&staged.id, TEST_STAGED_OID);
121-
cl_git_pass(git_index_add(repo_index, &staged));
112+
cl_git_mkfile("./mergedrepo/test-one.txt", "new-file\n");
113+
cl_git_pass(git_index_add_bypath(repo_index, "test-one.txt"));
122114
cl_assert(git_index_entrycount(repo_index) == 9);
123115

124116
ancestor_entry.path = "test-one.txt";
125117
ancestor_entry.mode = 0100644;
126118
GIT_IDXENTRY_STAGE_SET(&ancestor_entry, 3);
127-
git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
119+
git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID);
128120

129121
our_entry.path = "test-one.txt";
130122
our_entry.mode = 0100644;
131123
GIT_IDXENTRY_STAGE_SET(&our_entry, 1);
132-
git_oid_fromstr(&our_entry.id, TEST_OUR_OID);
124+
git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID);
133125

134126
their_entry.path = "test-one.txt";
135127
their_entry.mode = 0100644;
136128
GIT_IDXENTRY_STAGE_SET(&their_entry, 2);
137-
git_oid_fromstr(&their_entry.id, TEST_THEIR_OID);
129+
git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID);
138130

139131
cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry));
140132

@@ -330,7 +322,7 @@ void test_index_conflicts__partial(void)
330322
ancestor_entry.path = "test-one.txt";
331323
ancestor_entry.mode = 0100644;
332324
GIT_IDXENTRY_STAGE_SET(&ancestor_entry, 1);
333-
git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
325+
git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID);
334326

335327
cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, NULL, NULL));
336328
cl_assert(git_index_entrycount(repo_index) == 9);

tests/index/filemodes.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,19 @@ void test_index_filemodes__invalid(void)
236236
{
237237
git_index *index;
238238
git_index_entry entry;
239+
const git_index_entry *dummy;
239240

240241
cl_git_pass(git_repository_index(&index, g_repo));
241242

243+
/* add a dummy file so that we have a valid id */
244+
cl_git_mkfile("./filemodes/dummy-file.txt", "new-file\n");
245+
cl_git_pass(git_index_add_bypath(index, "dummy-file.txt"));
246+
cl_assert((dummy = git_index_get_bypath(index, "dummy-file.txt", 0)));
247+
242248
GIT_IDXENTRY_STAGE_SET(&entry, 0);
243249
entry.path = "foo";
244250
entry.mode = GIT_OBJ_BLOB;
251+
git_oid_cpy(&entry.id, &dummy->id);
245252
cl_git_fail(git_index_add(index, &entry));
246253

247254
entry.mode = GIT_FILEMODE_BLOB;

tests/index/racy.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ static void setup_uptodate_files(void)
178178
{
179179
git_buf path = GIT_BUF_INIT;
180180
git_index *index;
181+
const git_index_entry *a_entry;
181182
git_index_entry new_entry = {{0}};
182183

183184
cl_git_pass(git_repository_index(&index, g_repo));
@@ -188,9 +189,12 @@ static void setup_uptodate_files(void)
188189
/* Put 'A' into the index */
189190
cl_git_pass(git_index_add_bypath(index, "A"));
190191

192+
cl_assert((a_entry = git_index_get_bypath(index, "A", 0)));
193+
191194
/* Put 'B' into the index */
192195
new_entry.path = "B";
193196
new_entry.mode = GIT_FILEMODE_BLOB;
197+
git_oid_cpy(&new_entry.id, &a_entry->id);
194198
cl_git_pass(git_index_add(index, &new_entry));
195199

196200
/* Put 'C' into the index */

tests/object/tree/write.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,18 @@ void test_object_tree_write__sorted_subtrees(void)
133133
{ GIT_FILEMODE_TREE, "vendors"}
134134
};
135135

136-
git_oid blank_oid, tree_oid;
136+
git_oid bid, tid, tree_oid;
137137

138-
memset(&blank_oid, 0x0, sizeof(blank_oid));
138+
cl_git_pass(git_oid_fromstr(&bid, blob_oid));
139+
cl_git_pass(git_oid_fromstr(&tid, first_tree));
139140

140141
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
141142

142143
for (i = 0; i < ARRAY_SIZE(entries); ++i) {
144+
git_oid *id = entries[i].attr == GIT_FILEMODE_TREE ? &tid : &bid;
145+
143146
cl_git_pass(git_treebuilder_insert(NULL,
144-
builder, entries[i].filename, &blank_oid, entries[i].attr));
147+
builder, entries[i].filename, id, entries[i].attr));
145148
}
146149

147150
cl_git_pass(git_treebuilder_write(&tree_oid, builder));
@@ -189,18 +192,18 @@ void test_object_tree_write__removing_and_re_adding_in_treebuilder(void)
189192
{
190193
git_treebuilder *builder;
191194
int i, aardvark_i, apple_i, apple_after_i, apple_extra_i, last_i;
192-
git_oid blank_oid, tree_oid;
195+
git_oid entry_oid, tree_oid;
193196
git_tree *tree;
194197

195-
memset(&blank_oid, 0x0, sizeof(blank_oid));
198+
cl_git_pass(git_oid_fromstr(&entry_oid, blob_oid));
196199

197200
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
198201

199202
cl_assert_equal_i(0, (int)git_treebuilder_entrycount(builder));
200203

201204
for (i = 0; _entries[i].filename; ++i)
202205
cl_git_pass(git_treebuilder_insert(NULL,
203-
builder, _entries[i].filename, &blank_oid, _entries[i].attr));
206+
builder, _entries[i].filename, &entry_oid, _entries[i].attr));
204207

205208
cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
206209

@@ -211,24 +214,24 @@ void test_object_tree_write__removing_and_re_adding_in_treebuilder(void)
211214
cl_assert_equal_i(4, (int)git_treebuilder_entrycount(builder));
212215

213216
cl_git_pass(git_treebuilder_insert(
214-
NULL, builder, "before_last", &blank_oid, GIT_FILEMODE_BLOB));
217+
NULL, builder, "before_last", &entry_oid, GIT_FILEMODE_BLOB));
215218
cl_assert_equal_i(5, (int)git_treebuilder_entrycount(builder));
216219

217220
/* reinsert apple_after */
218221
cl_git_pass(git_treebuilder_insert(
219-
NULL, builder, "apple_after", &blank_oid, GIT_FILEMODE_BLOB));
222+
NULL, builder, "apple_after", &entry_oid, GIT_FILEMODE_BLOB));
220223
cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
221224

222225
cl_git_pass(git_treebuilder_remove(builder, "last"));
223226
cl_assert_equal_i(5, (int)git_treebuilder_entrycount(builder));
224227

225228
/* reinsert last */
226229
cl_git_pass(git_treebuilder_insert(
227-
NULL, builder, "last", &blank_oid, GIT_FILEMODE_BLOB));
230+
NULL, builder, "last", &entry_oid, GIT_FILEMODE_BLOB));
228231
cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
229232

230233
cl_git_pass(git_treebuilder_insert(
231-
NULL, builder, "apple_extra", &blank_oid, GIT_FILEMODE_BLOB));
234+
NULL, builder, "apple_extra", &entry_oid, GIT_FILEMODE_BLOB));
232235
cl_assert_equal_i(7, (int)git_treebuilder_entrycount(builder));
233236

234237
cl_git_pass(git_treebuilder_write(&tree_oid, builder));
@@ -280,16 +283,16 @@ void test_object_tree_write__filtering(void)
280283
{
281284
git_treebuilder *builder;
282285
int i;
283-
git_oid blank_oid, tree_oid;
286+
git_oid entry_oid, tree_oid;
284287
git_tree *tree;
285288

286-
memset(&blank_oid, 0x0, sizeof(blank_oid));
289+
git_oid_fromstr(&entry_oid, blob_oid);
287290

288291
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
289292

290293
for (i = 0; _entries[i].filename; ++i)
291294
cl_git_pass(git_treebuilder_insert(NULL,
292-
builder, _entries[i].filename, &blank_oid, _entries[i].attr));
295+
builder, _entries[i].filename, &entry_oid, _entries[i].attr));
293296

294297
cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
295298

@@ -408,6 +411,8 @@ void test_object_tree_write__protect_filesystems(void)
408411
git_treebuilder *builder;
409412
git_oid bid;
410413

414+
cl_git_pass(git_oid_fromstr(&bid, "fa49b077972391ad58037050f2a75f74e3671e92"));
415+
411416
/* Ensure that (by default) we can write objects with funny names on
412417
* platforms that are not affected.
413418
*/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)