3 test_description='Test git check-ref-format'
14 desc="ref name '$1' is valid${2:+ with options $2}"
15 test_expect_success $prereq "$desc" "
16 git check-ref-format $2 '$1'
26 desc="ref name '$1' is invalid${2:+ with options $2}"
27 test_expect_success $prereq "$desc" "
28 test_must_fail git check-ref-format $2 '$1'
33 invalid_ref NOT_MINGW '/'
34 invalid_ref NOT_MINGW '/' --allow-onelevel
35 invalid_ref NOT_MINGW '/' --normalize
36 invalid_ref NOT_MINGW '/' '--allow-onelevel --normalize'
37 valid_ref 'foo/bar/baz'
38 valid_ref 'foo/bar/baz' --normalize
39 invalid_ref 'refs///heads/foo'
40 valid_ref 'refs///heads/foo' --normalize
41 invalid_ref 'heads/foo/'
42 invalid_ref NOT_MINGW '/heads/foo'
43 valid_ref NOT_MINGW '/heads/foo' --normalize
44 invalid_ref '///heads/foo'
45 valid_ref '///heads/foo' --normalize
47 invalid_ref './foo/bar'
48 invalid_ref 'foo/./bar'
49 invalid_ref 'foo/bar/.'
50 invalid_ref '.refs/foo'
51 invalid_ref 'heads/foo..bar'
52 invalid_ref 'heads/foo?bar'
54 invalid_ref 'heads/foo.lock'
55 invalid_ref 'heads///foo.lock'
56 invalid_ref 'foo.lock/bar'
57 invalid_ref 'foo.lock///bar'
58 valid_ref 'heads/foo@bar'
59 invalid_ref 'heads/v@{ation'
60 invalid_ref 'heads/foo\bar'
61 invalid_ref "$(printf 'heads/foo\t')"
62 invalid_ref "$(printf 'heads/foo\177')"
63 valid_ref "$(printf 'heads/fu\303\237')"
64 invalid_ref 'heads/*foo/bar' --refspec-pattern
65 invalid_ref 'heads/foo*/bar' --refspec-pattern
66 invalid_ref 'heads/f*o/bar' --refspec-pattern
67 invalid_ref 'heads/foo*//bar' --refspec-pattern
71 valid_ref "$ref" --allow-onelevel
72 invalid_ref "$ref" --refspec-pattern
73 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
74 invalid_ref "$ref" --normalize
75 valid_ref "$ref" '--allow-onelevel --normalize'
79 valid_ref "$ref" --allow-onelevel
80 valid_ref "$ref" --refspec-pattern
81 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
82 valid_ref "$ref" --normalize
86 invalid_ref "$ref" --allow-onelevel
87 valid_ref "$ref" --refspec-pattern
88 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
92 invalid_ref "$ref" --allow-onelevel
93 valid_ref "$ref" --refspec-pattern
94 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
95 invalid_ref "$ref" --normalize
96 valid_ref "$ref" '--refspec-pattern --normalize'
100 invalid_ref "$ref" --allow-onelevel
101 valid_ref "$ref" --refspec-pattern
102 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
106 invalid_ref "$ref" --allow-onelevel
107 invalid_ref "$ref" --refspec-pattern
108 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
111 invalid_ref "$ref" --refspec-pattern
112 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
115 invalid_ref "$ref" --refspec-pattern
116 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
119 invalid_ref "$ref" --refspec-pattern
120 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
123 invalid_ref NOT_MINGW "$ref"
124 invalid_ref NOT_MINGW "$ref" --allow-onelevel
125 invalid_ref NOT_MINGW "$ref" --refspec-pattern
126 invalid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel'
127 invalid_ref NOT_MINGW "$ref" --normalize
128 valid_ref NOT_MINGW "$ref" '--allow-onelevel --normalize'
129 invalid_ref NOT_MINGW "$ref" '--refspec-pattern --normalize'
130 valid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize'
133 valid_ref 'refs/heads/a-very-long-refname'
134 invalid_ref 'refs/heads/.a-very-long-refname'
135 invalid_ref 'refs/heads/abcdefgh0123..'
136 invalid_ref 'refs/heads/abcdefgh01234..'
137 invalid_ref 'refs/heads/abcdefgh012345..'
138 invalid_ref 'refs/heads/abcdefgh0123456..'
139 invalid_ref 'refs/heads/abcdefgh01234567..'
140 valid_ref 'refs/heads/abcdefgh0123.a'
141 valid_ref 'refs/heads/abcdefgh01234.a'
142 valid_ref 'refs/heads/abcdefgh012345.a'
143 valid_ref 'refs/heads/abcdefgh0123456.a'
144 valid_ref 'refs/heads/abcdefgh01234567.a'
146 test_expect_success "check-ref-format --branch @{-1}" '
147 T=$(git write-tree) &&
148 sha1=$(echo A | git commit-tree $T) &&
149 git update-ref refs/heads/master $sha1 &&
150 git update-ref refs/remotes/origin/master $sha1 &&
151 git checkout master &&
152 git checkout origin/master &&
153 git checkout master &&
154 refname=$(git check-ref-format --branch @{-1}) &&
155 test "$refname" = "$sha1" &&
156 refname2=$(git check-ref-format --branch @{-2}) &&
157 test "$refname2" = master'
159 test_expect_success 'check-ref-format --branch from subdir' '
162 T=$(git write-tree) &&
163 sha1=$(echo A | git commit-tree $T) &&
164 git update-ref refs/heads/master $sha1 &&
165 git update-ref refs/remotes/origin/master $sha1 &&
166 git checkout master &&
167 git checkout origin/master &&
168 git checkout master &&
171 git check-ref-format --branch @{-1}
173 test "$refname" = "$sha1"
176 valid_ref_normalized() {
183 test_expect_success $prereq "ref name '$1' simplifies to '$2'" "
184 refname=\$(git check-ref-format --normalize '$1') &&
185 test \"\$refname\" = '$2'
188 invalid_ref_normalized() {
195 test_expect_success $prereq "check-ref-format --normalize rejects '$1'" "
196 test_must_fail git check-ref-format --normalize '$1'
200 valid_ref_normalized 'heads/foo' 'heads/foo'
201 valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
202 valid_ref_normalized NOT_MINGW '/heads/foo' 'heads/foo'
203 valid_ref_normalized '///heads/foo' 'heads/foo'
204 invalid_ref_normalized 'foo'
205 invalid_ref_normalized NOT_MINGW '/foo'
206 invalid_ref_normalized 'heads/foo/../bar'
207 invalid_ref_normalized 'heads/./foo'
208 invalid_ref_normalized 'heads\foo'
209 invalid_ref_normalized 'heads/foo.lock'
210 invalid_ref_normalized 'heads///foo.lock'
211 invalid_ref_normalized 'foo.lock/bar'
212 invalid_ref_normalized 'foo.lock///bar'