]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1506-rev-parse-diagnosis.sh
get_sha1: support relative path ":path" syntax
[thirdparty/git.git] / t / t1506-rev-parse-diagnosis.sh
CommitLineData
009fee47
MM
1#!/bin/sh
2
3test_description='test git rev-parse diagnosis for invalid argument'
4
5exec </dev/null
6
7. ./test-lib.sh
8
9HASH_file=
10
11test_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
21'
22
23test_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) )
32'
33
979f7929
NTND
34test_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'
39
40test_expect_success 'correct relative file objects (1)' '
41 git rev-parse HEAD:file.txt >expected &&
42 git rev-parse HEAD:./file.txt >result &&
43 test_cmp expected result
44'
45
46test_expect_success 'correct relative file objects (2)' '
47 (
48 cd subdir &&
49 git rev-parse HEAD:../file.txt >result &&
50 test_cmp ../expected result
51 )
52'
53
54test_expect_success 'correct relative file objects (3)' '
55 (
56 cd subdir &&
57 git rev-parse HEAD:../subdir/../file.txt >result &&
58 test_cmp ../expected result
59 )
60'
61
62test_expect_success 'correct relative file objects (4)' '
63 git rev-parse HEAD:subdir/file.txt >expected &&
64 (
65 cd subdir &&
66 git rev-parse HEAD:./file.txt >result &&
67 test_cmp ../expected result
68 )
69'
70
009fee47
MM
71test_expect_success 'incorrect revision id' '
72 test_must_fail git rev-parse foobar:file.txt 2>error &&
73 grep "Invalid object name '"'"'foobar'"'"'." error &&
74 test_must_fail git rev-parse foobar 2> error &&
75 grep "unknown revision or path not in the working tree." error
76'
77
78test_expect_success 'incorrect file in sha1:path' '
79 test_must_fail git rev-parse HEAD:nothing.txt 2> error &&
80 grep "fatal: Path '"'"'nothing.txt'"'"' does not exist in '"'"'HEAD'"'"'" error &&
81 test_must_fail git rev-parse HEAD:index-only.txt 2> error &&
82 grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
83 (cd subdir &&
84 test_must_fail git rev-parse HEAD:file2.txt 2> error &&
85 grep "Did you mean '"'"'HEAD:subdir/file2.txt'"'"'?" error )
86'
87
88test_expect_success 'incorrect file in :path and :N:path' '
89 test_must_fail git rev-parse :nothing.txt 2> error &&
90 grep "fatal: Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
91 test_must_fail git rev-parse :1:nothing.txt 2> error &&
92 grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
93 test_must_fail git rev-parse :1:file.txt 2> error &&
94 grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
95 (cd subdir &&
96 test_must_fail git rev-parse :1:file.txt 2> error &&
97 grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
98 test_must_fail git rev-parse :file2.txt 2> error &&
99 grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error &&
100 test_must_fail git rev-parse :2:file2.txt 2> error &&
101 grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error) &&
102 test_must_fail git rev-parse :disk-only.txt 2> error &&
103 grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
104'
105
9c46c054
JS
106test_expect_success 'invalid @{n} reference' '
107 test_must_fail git rev-parse master@{99999} >output 2>error &&
108 test -z "$(cat output)" &&
109 grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error &&
110 test_must_fail git rev-parse --verify master@{99999} >output 2>error &&
111 test -z "$(cat output)" &&
112 grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error
113'
114
979f7929
NTND
115test_expect_success 'relative path not found' '
116 (
117 cd subdir &&
118 test_must_fail git rev-parse HEAD:./nonexistent.txt 2>error &&
119 grep subdir/nonexistent.txt error
120 )
121'
122
123test_expect_success 'relative path outside worktree' '
124 test_must_fail git rev-parse HEAD:../file.txt >output 2>error &&
125 test -z "$(cat output)" &&
126 grep "outside repository" error
127'
128
129test_expect_success 'relative path when cwd is outside worktree' '
130 test_must_fail git --git-dir=.git --work-tree=subdir rev-parse HEAD:./file.txt >output 2>error &&
131 test -z "$(cat output)" &&
132 grep "relative path syntax can.t be used outside working tree." error
133'
134
135test_expect_success 'relative path when startup_info is NULL' '
136 test_must_fail test-match-trees HEAD:./file.txt HEAD:./file.txt 2>error &&
137 grep "BUG: startup_info struct is not initialized." error
138'
139
009fee47 140test_done