rebase: teach --autosquash to match on sha1 in addition to message
[git/kirr.git] / t / t1506-rev-parse-diagnosis.sh
blob0eeeb0e45090661c0576607792ff9b91d096e282
1 #!/bin/sh
3 test_description='test git rev-parse diagnosis for invalid argument'
5 exec </dev/null
7 . ./test-lib.sh
9 HASH_file=
11 test_expect_success 'set up basic repo' '
12 echo one > file.txt &&
13 mkdir subdir &&
14 echo two > subdir/file.txt &&
15 echo three > subdir/file2.txt &&
16 git add . &&
17 git commit -m init &&
18 echo four > index-only.txt &&
19 git add index-only.txt &&
20 echo five > disk-only.txt
23 test_expect_success 'correct file objects' '
24 HASH_file=$(git rev-parse HEAD:file.txt) &&
25 git rev-parse HEAD:subdir/file.txt &&
26 git rev-parse :index-only.txt &&
27 (cd subdir &&
28 git rev-parse HEAD:subdir/file2.txt &&
29 test $HASH_file = $(git rev-parse HEAD:file.txt) &&
30 test $HASH_file = $(git rev-parse :file.txt) &&
31 test $HASH_file = $(git rev-parse :0:file.txt) )
34 test_expect_success 'incorrect revision id' '
35 test_must_fail git rev-parse foobar:file.txt 2>error &&
36 grep "Invalid object name '"'"'foobar'"'"'." error &&
37 test_must_fail git rev-parse foobar 2> error &&
38 grep "unknown revision or path not in the working tree." error
41 test_expect_success 'incorrect file in sha1:path' '
42 test_must_fail git rev-parse HEAD:nothing.txt 2> error &&
43 grep "fatal: Path '"'"'nothing.txt'"'"' does not exist in '"'"'HEAD'"'"'" error &&
44 test_must_fail git rev-parse HEAD:index-only.txt 2> error &&
45 grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
46 (cd subdir &&
47 test_must_fail git rev-parse HEAD:file2.txt 2> error &&
48 grep "Did you mean '"'"'HEAD:subdir/file2.txt'"'"'?" error )
51 test_expect_success 'incorrect file in :path and :N:path' '
52 test_must_fail git rev-parse :nothing.txt 2> error &&
53 grep "fatal: Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
54 test_must_fail git rev-parse :1:nothing.txt 2> error &&
55 grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
56 test_must_fail git rev-parse :1:file.txt 2> error &&
57 grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
58 (cd subdir &&
59 test_must_fail git rev-parse :1:file.txt 2> error &&
60 grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
61 test_must_fail git rev-parse :file2.txt 2> error &&
62 grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error &&
63 test_must_fail git rev-parse :2:file2.txt 2> error &&
64 grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error) &&
65 test_must_fail git rev-parse :disk-only.txt 2> error &&
66 grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
69 test_expect_success 'invalid @{n} reference' '
70 test_must_fail git rev-parse master@{99999} >output 2>error &&
71 test -z "$(cat output)" &&
72 grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error &&
73 test_must_fail git rev-parse --verify master@{99999} >output 2>error &&
74 test -z "$(cat output)" &&
75 grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error
78 test_done