3 test_description='Test git check-ref-format'
14 test_expect_success $prereq "ref name '$1' is valid${2:+ with options $2}" "
15 git check-ref-format $2 '$1'
25 test_expect_success $prereq "ref name '$1' is invalid${2:+ with options $2}" "
26 test_must_fail git check-ref-format $2 '$1'
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'
35 valid_ref 'foo/bar/baz'
36 valid_ref 'foo/bar/baz' --normalize
37 invalid_ref 'refs///heads/foo'
38 valid_ref 'refs///heads/foo' --normalize
39 invalid_ref 'heads/foo/'
40 invalid_ref NOT_MINGW '/heads/foo'
41 valid_ref NOT_MINGW '/heads/foo' --normalize
42 invalid_ref '///heads/foo'
43 valid_ref '///heads/foo' --normalize
45 invalid_ref './foo/bar'
46 invalid_ref 'foo/./bar'
47 invalid_ref 'foo/bar/.'
48 invalid_ref '.refs/foo'
49 invalid_ref 'heads/foo..bar'
50 invalid_ref 'heads/foo?bar'
52 invalid_ref 'heads/foo.lock'
53 invalid_ref 'heads///foo.lock'
54 invalid_ref 'foo.lock/bar'
55 invalid_ref 'foo.lock///bar'
56 valid_ref 'heads/foo@bar'
57 invalid_ref 'heads/v@{ation'
58 invalid_ref 'heads/foo\bar'
59 invalid_ref "$(printf 'heads/foo\t')"
60 invalid_ref "$(printf 'heads/foo\177')"
61 valid_ref "$(printf 'heads/fu\303\237')"
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
68 valid_ref "$ref" --allow-onelevel
69 invalid_ref "$ref" --refspec-pattern
70 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
71 invalid_ref "$ref" --normalize
72 valid_ref "$ref" '--allow-onelevel --normalize'
76 valid_ref "$ref" --allow-onelevel
77 valid_ref "$ref" --refspec-pattern
78 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
79 valid_ref "$ref" --normalize
83 invalid_ref "$ref" --allow-onelevel
84 valid_ref "$ref" --refspec-pattern
85 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
89 invalid_ref "$ref" --allow-onelevel
90 valid_ref "$ref" --refspec-pattern
91 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
92 invalid_ref "$ref" --normalize
93 valid_ref "$ref" '--refspec-pattern --normalize'
97 invalid_ref "$ref" --allow-onelevel
98 valid_ref "$ref" --refspec-pattern
99 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
103 invalid_ref "$ref" --allow-onelevel
104 invalid_ref "$ref" --refspec-pattern
105 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
108 invalid_ref "$ref" --refspec-pattern
109 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
112 invalid_ref "$ref" --refspec-pattern
113 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
116 invalid_ref "$ref" --refspec-pattern
117 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
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'
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 &&
133 git update-ref refs/remotes/origin/master $sha1 &&
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'
142 test_expect_success 'check-ref-format --branch from subdir' '
145 T=$(git write-tree) &&
146 sha1=$(echo A | git commit-tree $T) &&
147 git update-ref refs/heads/master $sha1 &&
148 git update-ref refs/remotes/origin/master $sha1 &&
149 git checkout master &&
150 git checkout origin/master &&
151 git checkout master &&
154 git check-ref-format --branch @{-1}
156 test "$refname" = "$sha1"
159 valid_ref_normalized() {
166 test_expect_success $prereq "ref name '$1' simplifies to '$2'" "
167 refname=\$(git check-ref-format --normalize '$1') &&
168 test \"\$refname\" = '$2'
171 invalid_ref_normalized() {
178 test_expect_success $prereq "check-ref-format --normalize rejects '$1'" "
179 test_must_fail git check-ref-format --normalize '$1'
183 valid_ref_normalized 'heads/foo' 'heads/foo'
184 valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
185 valid_ref_normalized NOT_MINGW '/heads/foo' 'heads/foo'
186 valid_ref_normalized '///heads/foo' 'heads/foo'
187 invalid_ref_normalized 'foo'
188 invalid_ref_normalized NOT_MINGW '/foo'
189 invalid_ref_normalized 'heads/foo/../bar'
190 invalid_ref_normalized 'heads/./foo'
191 invalid_ref_normalized 'heads\foo'
192 invalid_ref_normalized 'heads/foo.lock'
193 invalid_ref_normalized 'heads///foo.lock'
194 invalid_ref_normalized 'foo.lock/bar'
195 invalid_ref_normalized 'foo.lock///bar'