Merge branch 'nd/init-gitdir'
[git/jrn.git] / t / t1506-rev-parse-diagnosis.sh
blob9f8adb1f824a5bafe8829e5ab613e2ab83065f4f
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 'correct relative file objects (0)' '
35 git rev-parse :file.txt >expected &&
36 git rev-parse :./file.txt >result &&
37 test_cmp expected result &&
38 git rev-parse :0:./file.txt >result &&
39 test_cmp expected result
42 test_expect_success 'correct relative file objects (1)' '
43 git rev-parse HEAD:file.txt >expected &&
44 git rev-parse HEAD:./file.txt >result &&
45 test_cmp expected result
48 test_expect_success 'correct relative file objects (2)' '
50 cd subdir &&
51 git rev-parse HEAD:../file.txt >result &&
52 test_cmp ../expected result
56 test_expect_success 'correct relative file objects (3)' '
58 cd subdir &&
59 git rev-parse HEAD:../subdir/../file.txt >result &&
60 test_cmp ../expected result
64 test_expect_success 'correct relative file objects (4)' '
65 git rev-parse HEAD:subdir/file.txt >expected &&
67 cd subdir &&
68 git rev-parse HEAD:./file.txt >result &&
69 test_cmp ../expected result
73 test_expect_success 'correct relative file objects (5)' '
74 git rev-parse :subdir/file.txt >expected &&
76 cd subdir &&
77 git rev-parse :./file.txt >result &&
78 test_cmp ../expected result &&
79 git rev-parse :0:./file.txt >result &&
80 test_cmp ../expected result
84 test_expect_success 'correct relative file objects (6)' '
85 git rev-parse :file.txt >expected &&
87 cd subdir &&
88 git rev-parse :../file.txt >result &&
89 test_cmp ../expected result &&
90 git rev-parse :0:../file.txt >result &&
91 test_cmp ../expected result
95 test_expect_success 'incorrect revision id' '
96 test_must_fail git rev-parse foobar:file.txt 2>error &&
97 grep "Invalid object name '"'"'foobar'"'"'." error &&
98 test_must_fail git rev-parse foobar 2> error &&
99 grep "unknown revision or path not in the working tree." error
102 test_expect_success 'incorrect file in sha1:path' '
103 test_must_fail git rev-parse HEAD:nothing.txt 2> error &&
104 grep "fatal: Path '"'"'nothing.txt'"'"' does not exist in '"'"'HEAD'"'"'" error &&
105 test_must_fail git rev-parse HEAD:index-only.txt 2> error &&
106 grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
107 (cd subdir &&
108 test_must_fail git rev-parse HEAD:file2.txt 2> error &&
109 grep "Did you mean '"'"'HEAD:subdir/file2.txt'"'"'?" error )
112 test_expect_success 'incorrect file in :path and :N:path' '
113 test_must_fail git rev-parse :nothing.txt 2> error &&
114 grep "fatal: Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
115 test_must_fail git rev-parse :1:nothing.txt 2> error &&
116 grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
117 test_must_fail git rev-parse :1:file.txt 2> error &&
118 grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
119 (cd subdir &&
120 test_must_fail git rev-parse :1:file.txt 2> error &&
121 grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
122 test_must_fail git rev-parse :file2.txt 2> error &&
123 grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error &&
124 test_must_fail git rev-parse :2:file2.txt 2> error &&
125 grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error) &&
126 test_must_fail git rev-parse :disk-only.txt 2> error &&
127 grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
130 test_expect_success 'invalid @{n} reference' '
131 test_must_fail git rev-parse master@{99999} >output 2>error &&
132 test -z "$(cat output)" &&
133 grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error &&
134 test_must_fail git rev-parse --verify master@{99999} >output 2>error &&
135 test -z "$(cat output)" &&
136 grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error
139 test_expect_success 'relative path not found' '
141 cd subdir &&
142 test_must_fail git rev-parse HEAD:./nonexistent.txt 2>error &&
143 grep subdir/nonexistent.txt error
147 test_expect_success 'relative path outside worktree' '
148 test_must_fail git rev-parse HEAD:../file.txt >output 2>error &&
149 test -z "$(cat output)" &&
150 grep "outside repository" error
153 test_expect_success 'relative path when cwd is outside worktree' '
154 test_must_fail git --git-dir=.git --work-tree=subdir rev-parse HEAD:./file.txt >output 2>error &&
155 test -z "$(cat output)" &&
156 grep "relative path syntax can.t be used outside working tree." error
159 test_expect_success 'relative path when startup_info is NULL' '
160 test_must_fail test-match-trees HEAD:./file.txt HEAD:./file.txt 2>error &&
161 grep "BUG: startup_info struct is not initialized." error
164 test_done