Merge branch 'jc/pack-objects-bigfile'
[gitweb.git] / t / t1506-rev-parse-diagnosis.sh
index 18664702b968102f393be836306a833731790e80..4a6396f9e3fb8006969916e12066fa6fc1527b3d 100755 (executable)
@@ -6,6 +6,13 @@ exec </dev/null
 
 . ./test-lib.sh
 
+test_did_you_mean ()
+{
+       printf "fatal: Path '$2$3' $4, but not ${5:-'$3'}.\n" >expected &&
+       printf "Did you mean '$1:$2$3'${2:+ aka '$1:./$3'}?\n" >>expected &&
+       test_cmp expected error
+}
+
 HASH_file=
 
 test_expect_success 'set up basic repo' '
@@ -34,6 +41,8 @@ test_expect_success 'correct file objects' '
 test_expect_success 'correct relative file objects (0)' '
        git rev-parse :file.txt >expected &&
        git rev-parse :./file.txt >result &&
+       test_cmp expected result &&
+       git rev-parse :0:./file.txt >result &&
        test_cmp expected result
 '
 
@@ -68,6 +77,28 @@ test_expect_success 'correct relative file objects (4)' '
        )
 '
 
+test_expect_success 'correct relative file objects (5)' '
+       git rev-parse :subdir/file.txt >expected &&
+       (
+               cd subdir &&
+               git rev-parse :./file.txt >result &&
+               test_cmp ../expected result &&
+               git rev-parse :0:./file.txt >result &&
+               test_cmp ../expected result
+       )
+'
+
+test_expect_success 'correct relative file objects (6)' '
+       git rev-parse :file.txt >expected &&
+       (
+               cd subdir &&
+               git rev-parse :../file.txt >result &&
+               test_cmp ../expected result &&
+               git rev-parse :0:../file.txt >result &&
+               test_cmp ../expected result
+       )
+'
+
 test_expect_success 'incorrect revision id' '
        test_must_fail git rev-parse foobar:file.txt 2>error &&
        grep "Invalid object name '"'"'foobar'"'"'." error &&
@@ -82,7 +113,7 @@ test_expect_success 'incorrect file in sha1:path' '
        grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
        (cd subdir &&
         test_must_fail git rev-parse HEAD:file2.txt 2> error &&
-        grep "Did you mean '"'"'HEAD:subdir/file2.txt'"'"'?" error )
+        test_did_you_mean HEAD subdir/ file2.txt exists )
 '
 
 test_expect_success 'incorrect file in :path and :N:path' '
@@ -91,14 +122,14 @@ test_expect_success 'incorrect file in :path and :N:path' '
        test_must_fail git rev-parse :1:nothing.txt 2> error &&
        grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
        test_must_fail git rev-parse :1:file.txt 2> error &&
-       grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
+       test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
        (cd subdir &&
         test_must_fail git rev-parse :1:file.txt 2> error &&
-        grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
+        test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
         test_must_fail git rev-parse :file2.txt 2> error &&
-        grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error &&
+        test_did_you_mean ":0" subdir/ file2.txt "is in the index" &&
         test_must_fail git rev-parse :2:file2.txt 2> error &&
-        grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error) &&
+        test_did_you_mean :0 subdir/ file2.txt "is in the index") &&
        test_must_fail git rev-parse :disk-only.txt 2> error &&
        grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
 '