327
bogus_long_sha1=$(echo_without_newline "$bogus_long_content" | git hash-object -t $bogus_long_type --literally -w --stdin)
328
'
329
330
+for arg1 in '' --allow-unknown-type
331
+do
332
+ for arg2 in -s -t -p
333
+ do
334
+ if test "$arg1" = "--allow-unknown-type" && test "$arg2" = "-p"
335
+ then
336
+ continue
337
+ fi
338
+
339
+
340
+ test_expect_success "cat-file $arg1 $arg2 error on bogus short OID" '
341
+ cat >expect <<-\EOF &&
342
+ fatal: invalid object type
343
+ EOF
344
+
345
+ if test "$arg1" = "--allow-unknown-type"
346
+ then
347
+ git cat-file $arg1 $arg2 $bogus_short_sha1
348
+ else
349
+ test_must_fail git cat-file $arg1 $arg2 $bogus_short_sha1 >out 2>actual &&
350
+ test_must_be_empty out &&
351
+ test_cmp expect actual
352
+ fi
353
+ '
354
+
355
+ test_expect_success "cat-file $arg1 $arg2 error on bogus full OID" '
356
+ if test "$arg2" = "-p"
357
+ then
358
+ cat >expect <<-EOF
359
+ error: unable to unpack $bogus_long_sha1 header
360
+ fatal: Not a valid object name $bogus_long_sha1
361
+ EOF
362
+ else
363
+ cat >expect <<-EOF
364
+ error: unable to unpack $bogus_long_sha1 header
365
+ fatal: git cat-file: could not get object info
366
+ EOF
367
+ fi &&
368
+
369
+ if test "$arg1" = "--allow-unknown-type"
370
+ then
371
+ git cat-file $arg1 $arg2 $bogus_short_sha1
372
+ else
373
+ test_must_fail git cat-file $arg1 $arg2 $bogus_long_sha1 >out 2>actual &&
374
+ test_must_be_empty out &&
375
+ test_cmp expect actual
376
+ fi
377
+ '
378
+
379
+ test_expect_success "cat-file $arg1 $arg2 error on missing short OID" '
380
+ cat >expect.err <<-EOF &&
381
+ fatal: Not a valid object name $(test_oid deadbeef_short)
382
+ EOF
383
+ test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef_short) >out 2>err.actual &&
384
+ test_must_be_empty out
385
+ '
386
+
387
+ test_expect_success "cat-file $arg1 $arg2 error on missing full OID" '
388
+ if test "$arg2" = "-p"
389
+ then
390
+ cat >expect.err <<-EOF
391
+ fatal: Not a valid object name $(test_oid deadbeef)
392
+ EOF
393
+ else
394
+ cat >expect.err <<-\EOF
395
+ fatal: git cat-file: could not get object info
396
+ EOF
397
+ fi &&
398
+ test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef) >out 2>err.actual &&
399
+ test_must_be_empty out &&
400
+ test_cmp expect.err err.actual
401
+ '
402
+ done
403
+done
404
+
405
test_expect_success "Type of broken object is correct" '
406
echo $bogus_short_type >expect &&
407
git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&