sha1_name: Suggest commit:./file for path in subdir
[git/dscho.git] / t / t1506-rev-parse-diagnosis.sh
blob4a6396f9e3fb8006969916e12066fa6fc1527b3d
1 #!/bin/sh
3 test_description='test git rev-parse diagnosis for invalid argument'
5 exec </dev/null
7 . ./test-lib.sh
9 test_did_you_mean ()
11 printf "fatal: Path '$2$3' $4, but not ${5:-'$3'}.\n" >expected &&
12 printf "Did you mean '$1:$2$3'${2:+ aka '$1:./$3'}?\n" >>expected &&
13 test_cmp expected error
16 HASH_file=
18 test_expect_success 'set up basic repo' '
19 echo one > file.txt &&
20 mkdir subdir &&
21 echo two > subdir/file.txt &&
22 echo three > subdir/file2.txt &&
23 git add . &&
24 git commit -m init &&
25 echo four > index-only.txt &&
26 git add index-only.txt &&
27 echo five > disk-only.txt
30 test_expect_success 'correct file objects' '
31 HASH_file=$(git rev-parse HEAD:file.txt) &&
32 git rev-parse HEAD:subdir/file.txt &&
33 git rev-parse :index-only.txt &&
34 (cd subdir &&
35 git rev-parse HEAD:subdir/file2.txt &&
36 test $HASH_file = $(git rev-parse HEAD:file.txt) &&
37 test $HASH_file = $(git rev-parse :file.txt) &&
38 test $HASH_file = $(git rev-parse :0:file.txt) )
41 test_expect_success 'correct relative file objects (0)' '
42 git rev-parse :file.txt >expected &&
43 git rev-parse :./file.txt >result &&
44 test_cmp expected result &&
45 git rev-parse :0:./file.txt >result &&
46 test_cmp expected result
49 test_expect_success 'correct relative file objects (1)' '
50 git rev-parse HEAD:file.txt >expected &&
51 git rev-parse HEAD:./file.txt >result &&
52 test_cmp expected result
55 test_expect_success 'correct relative file objects (2)' '
57 cd subdir &&
58 git rev-parse HEAD:../file.txt >result &&
59 test_cmp ../expected result
63 test_expect_success 'correct relative file objects (3)' '
65 cd subdir &&
66 git rev-parse HEAD:../subdir/../file.txt >result &&
67 test_cmp ../expected result
71 test_expect_success 'correct relative file objects (4)' '
72 git rev-parse HEAD:subdir/file.txt >expected &&
74 cd subdir &&
75 git rev-parse HEAD:./file.txt >result &&
76 test_cmp ../expected result
80 test_expect_success 'correct relative file objects (5)' '
81 git rev-parse :subdir/file.txt >expected &&
83 cd subdir &&
84 git rev-parse :./file.txt >result &&
85 test_cmp ../expected result &&
86 git rev-parse :0:./file.txt >result &&
87 test_cmp ../expected result
91 test_expect_success 'correct relative file objects (6)' '
92 git rev-parse :file.txt >expected &&
94 cd subdir &&
95 git rev-parse :../file.txt >result &&
96 test_cmp ../expected result &&
97 git rev-parse :0:../file.txt >result &&
98 test_cmp ../expected result
102 test_expect_success 'incorrect revision id' '
103 test_must_fail git rev-parse foobar:file.txt 2>error &&
104 grep "Invalid object name '"'"'foobar'"'"'." error &&
105 test_must_fail git rev-parse foobar 2> error &&
106 grep "unknown revision or path not in the working tree." error
109 test_expect_success 'incorrect file in sha1:path' '
110 test_must_fail git rev-parse HEAD:nothing.txt 2> error &&
111 grep "fatal: Path '"'"'nothing.txt'"'"' does not exist in '"'"'HEAD'"'"'" error &&
112 test_must_fail git rev-parse HEAD:index-only.txt 2> error &&
113 grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
114 (cd subdir &&
115 test_must_fail git rev-parse HEAD:file2.txt 2> error &&
116 test_did_you_mean HEAD subdir/ file2.txt exists )
119 test_expect_success 'incorrect file in :path and :N:path' '
120 test_must_fail git rev-parse :nothing.txt 2> error &&
121 grep "fatal: Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
122 test_must_fail git rev-parse :1:nothing.txt 2> error &&
123 grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
124 test_must_fail git rev-parse :1:file.txt 2> error &&
125 test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
126 (cd subdir &&
127 test_must_fail git rev-parse :1:file.txt 2> error &&
128 test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
129 test_must_fail git rev-parse :file2.txt 2> error &&
130 test_did_you_mean ":0" subdir/ file2.txt "is in the index" &&
131 test_must_fail git rev-parse :2:file2.txt 2> error &&
132 test_did_you_mean :0 subdir/ file2.txt "is in the index") &&
133 test_must_fail git rev-parse :disk-only.txt 2> error &&
134 grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
137 test_expect_success 'invalid @{n} reference' '
138 test_must_fail git rev-parse master@{99999} >output 2>error &&
139 test -z "$(cat output)" &&
140 grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error &&
141 test_must_fail git rev-parse --verify master@{99999} >output 2>error &&
142 test -z "$(cat output)" &&
143 grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error
146 test_expect_success 'relative path not found' '
148 cd subdir &&
149 test_must_fail git rev-parse HEAD:./nonexistent.txt 2>error &&
150 grep subdir/nonexistent.txt error
154 test_expect_success 'relative path outside worktree' '
155 test_must_fail git rev-parse HEAD:../file.txt >output 2>error &&
156 test -z "$(cat output)" &&
157 grep "outside repository" error
160 test_expect_success 'relative path when cwd is outside worktree' '
161 test_must_fail git --git-dir=.git --work-tree=subdir rev-parse HEAD:./file.txt >output 2>error &&
162 test -z "$(cat output)" &&
163 grep "relative path syntax can.t be used outside working tree." error
166 test_expect_success 'relative path when startup_info is NULL' '
167 test_must_fail test-match-trees HEAD:./file.txt HEAD:./file.txt 2>error &&
168 grep "BUG: startup_info struct is not initialized." error
171 test_done