@matheusbsbs / matheus-bagliano / commits / 3d12d0cfbb
Fork 0

Catch errors when writing an index that contains invalid objects.

If git-write-index is called without --missing-ok, it reports invalid objects that it finds in the index. But without this patch it dies right away or may run into an infinite loop. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Sixt committed Nov 13, 2006 at 13:50 UTC 3d12d0cfbbda0feb6305d6c53f3cf9aae2330c4c
2 files changed +24
cache-tree.c
+2
@@ -282,6 +282,8 @@ static int update_one(struct cache_tree *it,
282 baselen + sublen + 1,
283 missing_ok,
284 dryrun);
285 + if (subcnt < 0)
286 + return subcnt;
287 i += subcnt - 1;
288 sub->used = 1;
289 }
t/t0000-basic.sh
+22
@@ -209,6 +209,28 @@ test_expect_success \
209 'validate object ID for a known tree.' \
210 'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2'
211
212 +cat >badobjects <<EOF
213 +100644 blob 1000000000000000000000000000000000000000 dir/file1
214 +100644 blob 2000000000000000000000000000000000000000 dir/file2
215 +100644 blob 3000000000000000000000000000000000000000 dir/file3
216 +100644 blob 4000000000000000000000000000000000000000 dir/file4
217 +100644 blob 5000000000000000000000000000000000000000 dir/file5
218 +EOF
219 +
220 +rm .git/index
221 +test_expect_success \
222 + 'put invalid objects into the index.' \
223 + 'git-update-index --index-info < badobjects'
224 +
225 +test_expect_failure \
226 + 'writing this tree without --missing-ok.' \
227 + 'git-write-tree'
228 +
229 +test_expect_success \
230 + 'writing this tree with --missing-ok.' \
231 + 'git-write-tree --missing-ok'
232 +
233 +
234 ################################################################
235 rm .git/index
236 test_expect_success \