]>
Commit | Line | Data |
---|---|---|
58a05c74 JN |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test git check-ref-format' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | valid_ref() { | |
42afe62d JS |
8 | prereq= |
9 | case $1 in | |
10 | [A-Z]*) | |
11 | prereq=$1 | |
12 | shift | |
13 | esac | |
14 | test_expect_success $prereq "ref name '$1' is valid${2:+ with options $2}" " | |
15 | git check-ref-format $2 '$1' | |
16 | " | |
58a05c74 JN |
17 | } |
18 | invalid_ref() { | |
42afe62d JS |
19 | prereq= |
20 | case $1 in | |
21 | [A-Z]*) | |
22 | prereq=$1 | |
23 | shift | |
24 | esac | |
25 | test_expect_success $prereq "ref name '$1' is invalid${2:+ with options $2}" " | |
26 | test_must_fail git check-ref-format $2 '$1' | |
27 | " | |
58a05c74 JN |
28 | } |
29 | ||
f9b1a5b9 | 30 | invalid_ref '' |
42afe62d JS |
31 | invalid_ref NOT_MINGW '/' |
32 | invalid_ref NOT_MINGW '/' --allow-onelevel | |
33 | invalid_ref NOT_MINGW '/' --normalize | |
34 | invalid_ref NOT_MINGW '/' '--allow-onelevel --normalize' | |
58a05c74 | 35 | valid_ref 'foo/bar/baz' |
a40e6fb6 MH |
36 | valid_ref 'foo/bar/baz' --normalize |
37 | invalid_ref 'refs///heads/foo' | |
38 | valid_ref 'refs///heads/foo' --normalize | |
58a05c74 | 39 | invalid_ref 'heads/foo/' |
42afe62d JS |
40 | invalid_ref NOT_MINGW '/heads/foo' |
41 | valid_ref NOT_MINGW '/heads/foo' --normalize | |
a40e6fb6 MH |
42 | invalid_ref '///heads/foo' |
43 | valid_ref '///heads/foo' --normalize | |
58a05c74 | 44 | invalid_ref './foo' |
e4ed6105 MH |
45 | invalid_ref './foo/bar' |
46 | invalid_ref 'foo/./bar' | |
47 | invalid_ref 'foo/bar/.' | |
58a05c74 JN |
48 | invalid_ref '.refs/foo' |
49 | invalid_ref 'heads/foo..bar' | |
50 | invalid_ref 'heads/foo?bar' | |
51 | valid_ref 'foo./bar' | |
52 | invalid_ref 'heads/foo.lock' | |
f9b1a5b9 | 53 | invalid_ref 'heads///foo.lock' |
7e9d2fe9 MH |
54 | invalid_ref 'foo.lock/bar' |
55 | invalid_ref 'foo.lock///bar' | |
58a05c74 JN |
56 | valid_ref 'heads/foo@bar' |
57 | invalid_ref 'heads/v@{ation' | |
58 | invalid_ref 'heads/foo\bar' | |
f3738c1c MH |
59 | invalid_ref "$(printf 'heads/foo\t')" |
60 | invalid_ref "$(printf 'heads/foo\177')" | |
61 | valid_ref "$(printf 'heads/fu\303\237')" | |
e4ed6105 MH |
62 | invalid_ref 'heads/*foo/bar' --refspec-pattern |
63 | invalid_ref 'heads/foo*/bar' --refspec-pattern | |
64 | invalid_ref 'heads/f*o/bar' --refspec-pattern | |
65 | ||
66 | ref='foo' | |
67 | invalid_ref "$ref" | |
68 | valid_ref "$ref" --allow-onelevel | |
69 | invalid_ref "$ref" --refspec-pattern | |
70 | valid_ref "$ref" '--refspec-pattern --allow-onelevel' | |
a40e6fb6 MH |
71 | invalid_ref "$ref" --normalize |
72 | valid_ref "$ref" '--allow-onelevel --normalize' | |
e4ed6105 MH |
73 | |
74 | ref='foo/bar' | |
75 | valid_ref "$ref" | |
76 | valid_ref "$ref" --allow-onelevel | |
77 | valid_ref "$ref" --refspec-pattern | |
78 | valid_ref "$ref" '--refspec-pattern --allow-onelevel' | |
a40e6fb6 | 79 | valid_ref "$ref" --normalize |
e4ed6105 MH |
80 | |
81 | ref='foo/*' | |
82 | invalid_ref "$ref" | |
83 | invalid_ref "$ref" --allow-onelevel | |
84 | valid_ref "$ref" --refspec-pattern | |
85 | valid_ref "$ref" '--refspec-pattern --allow-onelevel' | |
86 | ||
87 | ref='*/foo' | |
88 | invalid_ref "$ref" | |
89 | invalid_ref "$ref" --allow-onelevel | |
90 | valid_ref "$ref" --refspec-pattern | |
91 | valid_ref "$ref" '--refspec-pattern --allow-onelevel' | |
a40e6fb6 MH |
92 | invalid_ref "$ref" --normalize |
93 | valid_ref "$ref" '--refspec-pattern --normalize' | |
e4ed6105 MH |
94 | |
95 | ref='foo/*/bar' | |
96 | invalid_ref "$ref" | |
97 | invalid_ref "$ref" --allow-onelevel | |
98 | valid_ref "$ref" --refspec-pattern | |
99 | valid_ref "$ref" '--refspec-pattern --allow-onelevel' | |
100 | ||
101 | ref='*' | |
102 | invalid_ref "$ref" | |
8d9c5010 | 103 | invalid_ref "$ref" --allow-onelevel |
e4ed6105 MH |
104 | invalid_ref "$ref" --refspec-pattern |
105 | valid_ref "$ref" '--refspec-pattern --allow-onelevel' | |
106 | ||
107 | ref='foo/*/*' | |
108 | invalid_ref "$ref" --refspec-pattern | |
109 | invalid_ref "$ref" '--refspec-pattern --allow-onelevel' | |
110 | ||
111 | ref='*/foo/*' | |
112 | invalid_ref "$ref" --refspec-pattern | |
113 | invalid_ref "$ref" '--refspec-pattern --allow-onelevel' | |
114 | ||
115 | ref='*/*/foo' | |
116 | invalid_ref "$ref" --refspec-pattern | |
117 | invalid_ref "$ref" '--refspec-pattern --allow-onelevel' | |
118 | ||
119 | ref='/foo' | |
42afe62d JS |
120 | invalid_ref NOT_MINGW "$ref" |
121 | invalid_ref NOT_MINGW "$ref" --allow-onelevel | |
122 | invalid_ref NOT_MINGW "$ref" --refspec-pattern | |
123 | invalid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel' | |
124 | invalid_ref NOT_MINGW "$ref" --normalize | |
125 | valid_ref NOT_MINGW "$ref" '--allow-onelevel --normalize' | |
126 | invalid_ref NOT_MINGW "$ref" '--refspec-pattern --normalize' | |
127 | valid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize' | |
58a05c74 JN |
128 | |
129 | test_expect_success "check-ref-format --branch @{-1}" ' | |
130 | T=$(git write-tree) && | |
131 | sha1=$(echo A | git commit-tree $T) && | |
132 | git update-ref refs/heads/master $sha1 && | |
a48fcd83 | 133 | git update-ref refs/remotes/origin/master $sha1 && |
58a05c74 JN |
134 | git checkout master && |
135 | git checkout origin/master && | |
136 | git checkout master && | |
137 | refname=$(git check-ref-format --branch @{-1}) && | |
138 | test "$refname" = "$sha1" && | |
139 | refname2=$(git check-ref-format --branch @{-2}) && | |
140 | test "$refname2" = master' | |
141 | ||
49cc460d JN |
142 | test_expect_success 'check-ref-format --branch from subdir' ' |
143 | mkdir subdir && | |
144 | ||
145 | T=$(git write-tree) && | |
146 | sha1=$(echo A | git commit-tree $T) && | |
147 | git update-ref refs/heads/master $sha1 && | |
a48fcd83 | 148 | git update-ref refs/remotes/origin/master $sha1 && |
49cc460d JN |
149 | git checkout master && |
150 | git checkout origin/master && | |
151 | git checkout master && | |
152 | refname=$( | |
153 | cd subdir && | |
154 | git check-ref-format --branch @{-1} | |
155 | ) && | |
156 | test "$refname" = "$sha1" | |
157 | ' | |
158 | ||
38eedc63 | 159 | valid_ref_normalized() { |
42afe62d JS |
160 | prereq= |
161 | case $1 in | |
162 | [A-Z]*) | |
163 | prereq=$1 | |
164 | shift | |
165 | esac | |
166 | test_expect_success $prereq "ref name '$1' simplifies to '$2'" " | |
a40e6fb6 | 167 | refname=\$(git check-ref-format --normalize '$1') && |
42afe62d JS |
168 | test \"\$refname\" = '$2' |
169 | " | |
38eedc63 JH |
170 | } |
171 | invalid_ref_normalized() { | |
42afe62d JS |
172 | prereq= |
173 | case $1 in | |
174 | [A-Z]*) | |
175 | prereq=$1 | |
176 | shift | |
177 | esac | |
178 | test_expect_success $prereq "check-ref-format --normalize rejects '$1'" " | |
179 | test_must_fail git check-ref-format --normalize '$1' | |
180 | " | |
38eedc63 JH |
181 | } |
182 | ||
183 | valid_ref_normalized 'heads/foo' 'heads/foo' | |
184 | valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo' | |
42afe62d | 185 | valid_ref_normalized NOT_MINGW '/heads/foo' 'heads/foo' |
2f633f41 | 186 | valid_ref_normalized '///heads/foo' 'heads/foo' |
38eedc63 | 187 | invalid_ref_normalized 'foo' |
42afe62d | 188 | invalid_ref_normalized NOT_MINGW '/foo' |
38eedc63 JH |
189 | invalid_ref_normalized 'heads/foo/../bar' |
190 | invalid_ref_normalized 'heads/./foo' | |
191 | invalid_ref_normalized 'heads\foo' | |
f9b1a5b9 MH |
192 | invalid_ref_normalized 'heads/foo.lock' |
193 | invalid_ref_normalized 'heads///foo.lock' | |
7e9d2fe9 MH |
194 | invalid_ref_normalized 'foo.lock/bar' |
195 | invalid_ref_normalized 'foo.lock///bar' | |
38eedc63 | 196 | |
58a05c74 | 197 | test_done |