]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t1512-rev-parse-disambiguation.sh
Merge branch 'ab/ambiguous-object-name'
[thirdparty/git.git] / t / t1512-rev-parse-disambiguation.sh
index b0119bf8bc8417439bee91bb7c1add21bc460c2e..98cefe3b7039fe726148e47fdf81b1f9fb454e15 100755 (executable)
@@ -25,6 +25,87 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
 
+test_cmp_failed_rev_parse () {
+       dir=$1
+       rev=$2
+
+       cat >expect &&
+       test_must_fail git -C "$dir" rev-parse "$rev" 2>actual.raw &&
+       sed "s/\($rev\)[0-9a-f]*/\1.../" <actual.raw >actual &&
+       test_cmp expect actual
+}
+
+test_expect_success 'ambiguous blob output' '
+       git init --bare blob.prefix &&
+       (
+               cd blob.prefix &&
+
+               # Both start with "dead..", under both SHA-1 and SHA-256
+               echo brocdnra | git hash-object -w --stdin &&
+               echo brigddsv | git hash-object -w --stdin &&
+
+               # Both start with "beef.."
+               echo 1agllotbh | git hash-object -w --stdin &&
+               echo 1bbfctrkc | git hash-object -w --stdin
+       ) &&
+
+       test_must_fail git -C blob.prefix rev-parse dead &&
+       test_cmp_failed_rev_parse blob.prefix beef <<-\EOF
+       error: short object ID beef... is ambiguous
+       hint: The candidates are:
+       hint:   beef... blob
+       hint:   beef... blob
+       fatal: ambiguous argument '\''beef...'\'': unknown revision or path not in the working tree.
+       Use '\''--'\'' to separate paths from revisions, like this:
+       '\''git <command> [<revision>...] -- [<file>...]'\''
+       EOF
+'
+
+test_expect_success 'ambiguous loose bad object parsed as OBJ_BAD' '
+       git init --bare blob.bad &&
+       (
+               cd blob.bad &&
+
+               # Both have the prefix "bad0"
+               echo xyzfaowcoh | git hash-object -t bad -w --stdin --literally &&
+               echo xyzhjpyvwl | git hash-object -t bad -w --stdin --literally
+       ) &&
+
+       test_cmp_failed_rev_parse blob.bad bad0 <<-\EOF
+       error: short object ID bad0... is ambiguous
+       fatal: invalid object type
+       EOF
+'
+
+test_expect_success POSIXPERM 'ambigous zlib corrupt loose blob' '
+       git init --bare blob.corrupt &&
+       (
+               cd blob.corrupt &&
+
+               # Both have the prefix "cafe"
+               echo bnkxmdwz | git hash-object -w --stdin &&
+               oid=$(echo bmwsjxzi | git hash-object -w --stdin) &&
+
+               oidf=objects/$(test_oid_to_path "$oid") &&
+               chmod 755 $oidf &&
+               echo broken >$oidf
+       ) &&
+
+       test_cmp_failed_rev_parse blob.corrupt cafe <<-\EOF
+       error: short object ID cafe... is ambiguous
+       error: inflate: data stream error (incorrect header check)
+       error: unable to unpack cafe... header
+       error: inflate: data stream error (incorrect header check)
+       error: unable to unpack cafe... header
+       hint: The candidates are:
+       hint:   cafe... [bad object]
+       hint:   cafe... blob
+       fatal: ambiguous argument '\''cafe...'\'': unknown revision or path not in the working tree.
+       Use '\''--'\'' to separate paths from revisions, like this:
+       '\''git <command> [<revision>...] -- [<file>...]'\''
+       EOF
+'
+
 if ! test_have_prereq SHA1
 then
        skip_all='not using SHA-1 for objects'