3 test_description='Test git check-ref-format'
10 test_expect_success "ref name '$1' is valid" \
11 "git check-ref-format '$1'"
13 test_expect_success "ref name '$1' is valid with options $2" \
14 "git check-ref-format $2 '$1'"
20 test_expect_success "ref name '$1' is invalid" \
21 "test_must_fail git check-ref-format '$1'"
23 test_expect_success "ref name '$1' is invalid with options $2" \
24 "test_must_fail git check-ref-format $2 '$1'"
30 invalid_ref '/' --allow-onelevel
31 invalid_ref '/' --normalize
32 invalid_ref '/' '--allow-onelevel --normalize'
33 valid_ref 'foo/bar/baz'
34 valid_ref 'foo/bar/baz' --normalize
35 invalid_ref 'refs///heads/foo'
36 valid_ref 'refs///heads/foo' --normalize
37 invalid_ref 'heads/foo/'
38 invalid_ref '/heads/foo'
39 valid_ref '/heads/foo' --normalize
40 invalid_ref '///heads/foo'
41 valid_ref '///heads/foo' --normalize
43 invalid_ref './foo/bar'
44 invalid_ref 'foo/./bar'
45 invalid_ref 'foo/bar/.'
46 invalid_ref '.refs/foo'
47 invalid_ref 'heads/foo..bar'
48 invalid_ref 'heads/foo?bar'
50 invalid_ref 'heads/foo.lock'
51 invalid_ref 'heads///foo.lock'
52 invalid_ref 'foo.lock/bar'
53 invalid_ref 'foo.lock///bar'
54 valid_ref 'heads/foo@bar'
55 invalid_ref 'heads/v@{ation'
56 invalid_ref 'heads/foo\bar'
57 invalid_ref "$(printf 'heads/foo\t')"
58 invalid_ref "$(printf 'heads/foo\177')"
59 valid_ref "$(printf 'heads/fu\303\237')"
60 invalid_ref 'heads/*foo/bar' --refspec-pattern
61 invalid_ref 'heads/foo*/bar' --refspec-pattern
62 invalid_ref 'heads/f*o/bar' --refspec-pattern
66 valid_ref "$ref" --allow-onelevel
67 invalid_ref "$ref" --refspec-pattern
68 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
69 invalid_ref "$ref" --normalize
70 valid_ref "$ref" '--allow-onelevel --normalize'
74 valid_ref "$ref" --allow-onelevel
75 valid_ref "$ref" --refspec-pattern
76 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
77 valid_ref "$ref" --normalize
81 invalid_ref "$ref" --allow-onelevel
82 valid_ref "$ref" --refspec-pattern
83 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
87 invalid_ref "$ref" --allow-onelevel
88 valid_ref "$ref" --refspec-pattern
89 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
90 invalid_ref "$ref" --normalize
91 valid_ref "$ref" '--refspec-pattern --normalize'
95 invalid_ref "$ref" --allow-onelevel
96 valid_ref "$ref" --refspec-pattern
97 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
101 invalid_ref "$ref" --allow-onelevel
102 invalid_ref "$ref" --refspec-pattern
103 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
106 invalid_ref "$ref" --refspec-pattern
107 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
110 invalid_ref "$ref" --refspec-pattern
111 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
114 invalid_ref "$ref" --refspec-pattern
115 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
119 invalid_ref "$ref" --allow-onelevel
120 invalid_ref "$ref" --refspec-pattern
121 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
122 invalid_ref "$ref" --normalize
123 valid_ref "$ref" '--allow-onelevel --normalize'
124 invalid_ref "$ref" '--refspec-pattern --normalize'
125 valid_ref "$ref" '--refspec-pattern --allow-onelevel --normalize'
127 test_expect_success "check-ref-format --branch @{-1}" '
128 T=$(git write-tree) &&
129 sha1=$(echo A | git commit-tree $T) &&
130 git update-ref refs/heads/master $sha1 &&
131 git update-ref refs/remotes/origin/master $sha1 &&
132 git checkout master &&
133 git checkout origin/master &&
134 git checkout master &&
135 refname=$(git check-ref-format --branch @{-1}) &&
136 test "$refname" = "$sha1" &&
137 refname2=$(git check-ref-format --branch @{-2}) &&
138 test "$refname2" = master'
140 test_expect_success 'check-ref-format --branch from subdir' '
143 T=$(git write-tree) &&
144 sha1=$(echo A | git commit-tree $T) &&
145 git update-ref refs/heads/master $sha1 &&
146 git update-ref refs/remotes/origin/master $sha1 &&
147 git checkout master &&
148 git checkout origin/master &&
149 git checkout master &&
152 git check-ref-format --branch @{-1}
154 test "$refname" = "$sha1"
157 valid_ref_normalized() {
158 test_expect_success "ref name '$1' simplifies to '$2'" "
159 refname=\$(git check-ref-format --normalize '$1') &&
160 test \"\$refname\" = '$2'"
162 invalid_ref_normalized() {
163 test_expect_success "check-ref-format --normalize rejects '$1'" "
164 test_must_fail git check-ref-format --normalize '$1'"
167 valid_ref_normalized 'heads/foo' 'heads/foo'
168 valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
169 valid_ref_normalized '/heads/foo' 'heads/foo'
170 valid_ref_normalized '///heads/foo' 'heads/foo'
171 invalid_ref_normalized 'foo'
172 invalid_ref_normalized '/foo'
173 invalid_ref_normalized 'heads/foo/../bar'
174 invalid_ref_normalized 'heads/./foo'
175 invalid_ref_normalized 'heads\foo'
176 invalid_ref_normalized 'heads/foo.lock'
177 invalid_ref_normalized 'heads///foo.lock'
178 invalid_ref_normalized 'foo.lock/bar'
179 invalid_ref_normalized 'foo.lock///bar'