25
26
. ./test-lib.sh
27
28
+test_cmp_failed_rev_parse () {
29
+ dir=$1
30
+ rev=$2
31
+
32
+ cat >expect &&
33
+ test_must_fail git -C "$dir" rev-parse "$rev" 2>actual.raw &&
34
+ sed "s/\($rev\)[0-9a-f]*/\1.../" <actual.raw >actual &&
35
+ test_cmp expect actual
36
+}
37
+
38
+test_expect_success 'ambiguous blob output' '
39
+ git init --bare blob.prefix &&
40
+ (
41
+ cd blob.prefix &&
42
+
43
+ # Both start with "dead..", under both SHA-1 and SHA-256
44
+ echo brocdnra | git hash-object -w --stdin &&
45
+ echo brigddsv | git hash-object -w --stdin &&
46
+
47
+ # Both start with "beef.."
48
+ echo 1agllotbh | git hash-object -w --stdin &&
49
+ echo 1bbfctrkc | git hash-object -w --stdin
50
+ ) &&
51
+
52
+ test_must_fail git -C blob.prefix rev-parse dead &&
53
+ test_cmp_failed_rev_parse blob.prefix beef <<-\EOF
54
+ error: short object ID beef... is ambiguous
55
+ hint: The candidates are:
56
+ hint: beef... blob
57
+ hint: beef... blob
58
+ fatal: ambiguous argument '\''beef...'\'': unknown revision or path not in the working tree.
59
+ Use '\''--'\'' to separate paths from revisions, like this:
60
+ '\''git <command> [<revision>...] -- [<file>...]'\''
61
+ EOF
62
+'
63
+
64
+test_expect_success 'ambiguous loose bad object parsed as OBJ_BAD' '
65
+ git init --bare blob.bad &&
66
+ (
67
+ cd blob.bad &&
68
+
69
+ # Both have the prefix "bad0"
70
+ echo xyzfaowcoh | git hash-object -t bad -w --stdin --literally &&
71
+ echo xyzhjpyvwl | git hash-object -t bad -w --stdin --literally
72
+ ) &&
73
+
74
+ test_cmp_failed_rev_parse blob.bad bad0 <<-\EOF
75
+ error: short object ID bad0... is ambiguous
76
+ hint: The candidates are:
77
+ fatal: invalid object type
78
+ EOF
79
+'
80
+
81
+test_expect_success POSIXPERM 'ambigous zlib corrupt loose blob' '
82
+ git init --bare blob.corrupt &&
83
+ (
84
+ cd blob.corrupt &&
85
+
86
+ # Both have the prefix "cafe"
87
+ echo bnkxmdwz | git hash-object -w --stdin &&
88
+ oid=$(echo bmwsjxzi | git hash-object -w --stdin) &&
89
+
90
+ oidf=objects/$(test_oid_to_path "$oid") &&
91
+ chmod 755 $oidf &&
92
+ echo broken >$oidf
93
+ ) &&
94
+
95
+ test_cmp_failed_rev_parse blob.corrupt cafe <<-\EOF
96
+ error: short object ID cafe... is ambiguous
97
+ hint: The candidates are:
98
+ error: inflate: data stream error (incorrect header check)
99
+ error: unable to unpack cafe... header
100
+ error: inflate: data stream error (incorrect header check)
101
+ error: unable to unpack cafe... header
102
+ hint: cafe... unknown type
103
+ hint: cafe... blob
104
+ fatal: ambiguous argument '\''cafe...'\'': unknown revision or path not in the working tree.
105
+ Use '\''--'\'' to separate paths from revisions, like this:
106
+ '\''git <command> [<revision>...] -- [<file>...]'\''
107
+ EOF
108
+'
109
+
110
if ! test_have_prereq SHA1
111
then
112
skip_all='not using SHA-1 for objects'