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 !MINGW '/'
34 invalid_ref !MINGW '/' --allow-onelevel
35 invalid_ref !MINGW '/' --normalize
36 invalid_ref !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 !MINGW '/heads/foo'
43 valid_ref !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 'refs/heads/foo.'
52 invalid_ref 'heads/foo..bar'
53 invalid_ref 'heads/foo?bar'
55 invalid_ref 'heads/foo.lock'
56 invalid_ref 'heads///foo.lock'
57 invalid_ref 'foo.lock/bar'
58 invalid_ref 'foo.lock///bar'
59 valid_ref 'heads/foo@bar'
60 invalid_ref 'heads/v@{ation'
61 invalid_ref 'heads/foo\bar'
62 invalid_ref "$(printf 'heads/foo\t')"
63 invalid_ref "$(printf 'heads/foo\177')"
64 valid_ref "$(printf 'heads/fu\303\237')"
65 valid_ref 'heads/*foo/bar' --refspec-pattern
66 valid_ref 'heads/foo*/bar' --refspec-pattern
67 valid_ref 'heads/f*o/bar' --refspec-pattern
68 invalid_ref 'heads/f*o*/bar' --refspec-pattern
69 invalid_ref 'heads/foo*/bar*' --refspec-pattern
73 valid_ref "$ref" --allow-onelevel
74 invalid_ref "$ref" --refspec-pattern
75 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
76 invalid_ref "$ref" --normalize
77 valid_ref "$ref" '--allow-onelevel --normalize'
81 valid_ref "$ref" --allow-onelevel
82 valid_ref "$ref" --refspec-pattern
83 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
84 valid_ref "$ref" --normalize
88 invalid_ref "$ref" --allow-onelevel
89 valid_ref "$ref" --refspec-pattern
90 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
94 invalid_ref "$ref" --allow-onelevel
95 valid_ref "$ref" --refspec-pattern
96 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
97 invalid_ref "$ref" --normalize
98 valid_ref "$ref" '--refspec-pattern --normalize'
102 invalid_ref "$ref" --allow-onelevel
103 valid_ref "$ref" --refspec-pattern
104 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
108 invalid_ref "$ref" --allow-onelevel
109 invalid_ref "$ref" --refspec-pattern
110 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
113 invalid_ref "$ref" --refspec-pattern
114 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
117 invalid_ref "$ref" --refspec-pattern
118 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
121 invalid_ref "$ref" --refspec-pattern
122 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
125 invalid_ref !MINGW "$ref"
126 invalid_ref !MINGW "$ref" --allow-onelevel
127 invalid_ref !MINGW "$ref" --refspec-pattern
128 invalid_ref !MINGW "$ref" '--refspec-pattern --allow-onelevel'
129 invalid_ref !MINGW "$ref" --normalize
130 valid_ref !MINGW "$ref" '--allow-onelevel --normalize'
131 invalid_ref !MINGW "$ref" '--refspec-pattern --normalize'
132 valid_ref !MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize'
134 test_expect_success "check-ref-format --branch @{-1}" '
135 T=$(git write-tree) &&
136 sha1=$(echo A | git commit-tree $T) &&
137 git update-ref refs/heads/master $sha1 &&
138 git update-ref refs/remotes/origin/master $sha1 &&
139 git checkout master &&
140 git checkout origin/master &&
141 git checkout master &&
142 refname=$(git check-ref-format --branch @{-1}) &&
143 test "$refname" = "$sha1" &&
144 refname2=$(git check-ref-format --branch @{-2}) &&
145 test "$refname2" = master'
147 test_expect_success 'check-ref-format --branch from subdir' '
150 T=$(git write-tree) &&
151 sha1=$(echo A | git commit-tree $T) &&
152 git update-ref refs/heads/master $sha1 &&
153 git update-ref refs/remotes/origin/master $sha1 &&
154 git checkout master &&
155 git checkout origin/master &&
156 git checkout master &&
159 git check-ref-format --branch @{-1}
161 test "$refname" = "$sha1"
164 valid_ref_normalized() {
171 test_expect_success $prereq "ref name '$1' simplifies to '$2'" "
172 refname=\$(git check-ref-format --normalize '$1') &&
173 test \"\$refname\" = '$2'
176 invalid_ref_normalized() {
183 test_expect_success $prereq "check-ref-format --normalize rejects '$1'" "
184 test_must_fail git check-ref-format --normalize '$1'
188 valid_ref_normalized 'heads/foo' 'heads/foo'
189 valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
190 valid_ref_normalized !MINGW '/heads/foo' 'heads/foo'
191 valid_ref_normalized '///heads/foo' 'heads/foo'
192 invalid_ref_normalized 'foo'
193 invalid_ref_normalized !MINGW '/foo'
194 invalid_ref_normalized 'heads/foo/../bar'
195 invalid_ref_normalized 'heads/./foo'
196 invalid_ref_normalized 'heads\foo'
197 invalid_ref_normalized 'heads/foo.lock'
198 invalid_ref_normalized 'heads///foo.lock'
199 invalid_ref_normalized 'foo.lock/bar'
200 invalid_ref_normalized 'foo.lock///bar'