cat-file tests: test for missing/bogus object with -t, -s and -p
When we look up a missing object with cat_one_file() what error we
print out currently depends on whether we'll error out early in
get_oid_with_context(), or if we'll get an error later from
oid_object_info_extended().
The --allow-unknown-type flag then changes whether we pass the
"OBJECT_INFO_ALLOW_UNKNOWN_TYPE" flag to get_oid_with_context() or
not.
The "-p" flag is yet another special-case in printing the same output
on the deadbeef OID as we'd emit on the deadbeef_short OID for the
"-s" and "-t" options, it also doesn't support the
"--allow-unknown-type" flag at all.
Let's test the combination of the two sets of [-t, -s, -p] and
[--{no-}allow-unknown-type] (the --no-allow-unknown-type is implicit
in not supplying it), as well as a [missing,bogus] object pair.
This extends tests added in 3e370f9faf
(t1006: add tests for git
cat-file --allow-unknown-type, 2015-05-03).
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
70e4a57762
commit
59b8283d55
@ -27,3 +27,5 @@ numeric sha1:0123456789012345678901234567890123456789
|
||||
numeric sha256:0123456789012345678901234567890123456789012345678901234567890123
|
||||
deadbeef sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
|
||||
deadbeef sha256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef
|
||||
deadbeef_short sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbee
|
||||
deadbeef_short sha256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbee
|
||||
|
@ -327,6 +327,81 @@ test_expect_success 'setup bogus data' '
|
||||
bogus_long_sha1=$(echo_without_newline "$bogus_long_content" | git hash-object -t $bogus_long_type --literally -w --stdin)
|
||||
'
|
||||
|
||||
for arg1 in '' --allow-unknown-type
|
||||
do
|
||||
for arg2 in -s -t -p
|
||||
do
|
||||
if test "$arg1" = "--allow-unknown-type" && test "$arg2" = "-p"
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
|
||||
test_expect_success "cat-file $arg1 $arg2 error on bogus short OID" '
|
||||
cat >expect <<-\EOF &&
|
||||
fatal: invalid object type
|
||||
EOF
|
||||
|
||||
if test "$arg1" = "--allow-unknown-type"
|
||||
then
|
||||
git cat-file $arg1 $arg2 $bogus_short_sha1
|
||||
else
|
||||
test_must_fail git cat-file $arg1 $arg2 $bogus_short_sha1 >out 2>actual &&
|
||||
test_must_be_empty out &&
|
||||
test_cmp expect actual
|
||||
fi
|
||||
'
|
||||
|
||||
test_expect_success "cat-file $arg1 $arg2 error on bogus full OID" '
|
||||
if test "$arg2" = "-p"
|
||||
then
|
||||
cat >expect <<-EOF
|
||||
error: unable to unpack $bogus_long_sha1 header
|
||||
fatal: Not a valid object name $bogus_long_sha1
|
||||
EOF
|
||||
else
|
||||
cat >expect <<-EOF
|
||||
error: unable to unpack $bogus_long_sha1 header
|
||||
fatal: git cat-file: could not get object info
|
||||
EOF
|
||||
fi &&
|
||||
|
||||
if test "$arg1" = "--allow-unknown-type"
|
||||
then
|
||||
git cat-file $arg1 $arg2 $bogus_short_sha1
|
||||
else
|
||||
test_must_fail git cat-file $arg1 $arg2 $bogus_long_sha1 >out 2>actual &&
|
||||
test_must_be_empty out &&
|
||||
test_cmp expect actual
|
||||
fi
|
||||
'
|
||||
|
||||
test_expect_success "cat-file $arg1 $arg2 error on missing short OID" '
|
||||
cat >expect.err <<-EOF &&
|
||||
fatal: Not a valid object name $(test_oid deadbeef_short)
|
||||
EOF
|
||||
test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef_short) >out 2>err.actual &&
|
||||
test_must_be_empty out
|
||||
'
|
||||
|
||||
test_expect_success "cat-file $arg1 $arg2 error on missing full OID" '
|
||||
if test "$arg2" = "-p"
|
||||
then
|
||||
cat >expect.err <<-EOF
|
||||
fatal: Not a valid object name $(test_oid deadbeef)
|
||||
EOF
|
||||
else
|
||||
cat >expect.err <<-\EOF
|
||||
fatal: git cat-file: could not get object info
|
||||
EOF
|
||||
fi &&
|
||||
test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef) >out 2>err.actual &&
|
||||
test_must_be_empty out &&
|
||||
test_cmp expect.err err.actual
|
||||
'
|
||||
done
|
||||
done
|
||||
|
||||
test_expect_success "Type of broken object is correct" '
|
||||
echo $bogus_short_type >expect &&
|
||||
git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
|
||||
|
Loading…
Reference in New Issue
Block a user