]>
Commit | Line | Data |
---|---|---|
afe5d3d5 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='basic symbolic-ref tests' | |
81ffbf83 ÆAB |
4 | |
5 | TEST_PASSES_SANITIZE_LEAK=true | |
afe5d3d5 JK |
6 | . ./test-lib.sh |
7 | ||
8 | # If the tests munging HEAD fail, they can break detection of | |
9 | # the git repo, meaning that further tests will operate on | |
10 | # the surrounding git repo instead of the trash directory. | |
11 | reset_to_sane() { | |
9910cbb6 HWN |
12 | rm -rf .git && |
13 | "$TAR" xf .git.tar | |
afe5d3d5 JK |
14 | } |
15 | ||
9910cbb6 HWN |
16 | test_expect_success 'setup' ' |
17 | git symbolic-ref HEAD refs/heads/foo && | |
18 | test_commit file && | |
19 | "$TAR" cf .git.tar .git/ | |
20 | ' | |
21 | ||
b1259ecf HWN |
22 | test_expect_success 'symbolic-ref read/write roundtrip' ' |
23 | git symbolic-ref HEAD refs/heads/read-write-roundtrip && | |
24 | echo refs/heads/read-write-roundtrip >expect && | |
afe5d3d5 JK |
25 | git symbolic-ref HEAD >actual && |
26 | test_cmp expect actual | |
27 | ' | |
28 | ||
29 | test_expect_success 'symbolic-ref refuses non-ref for HEAD' ' | |
30 | test_must_fail git symbolic-ref HEAD foo | |
31 | ' | |
b1259ecf | 32 | |
afe5d3d5 JK |
33 | reset_to_sane |
34 | ||
afe5d3d5 | 35 | test_expect_success 'symbolic-ref refuses bare sha1' ' |
9fdc79ec ÆAB |
36 | rev=$(git rev-parse HEAD) && |
37 | test_must_fail git symbolic-ref HEAD "$rev" | |
afe5d3d5 | 38 | ' |
b1259ecf | 39 | |
afe5d3d5 JK |
40 | reset_to_sane |
41 | ||
12cfa792 JH |
42 | test_expect_success 'HEAD cannot be removed' ' |
43 | test_must_fail git symbolic-ref -d HEAD | |
44 | ' | |
45 | ||
46 | reset_to_sane | |
47 | ||
48 | test_expect_success 'symbolic-ref can be deleted' ' | |
49 | git symbolic-ref NOTHEAD refs/heads/foo && | |
50 | git symbolic-ref -d NOTHEAD && | |
b1259ecf HWN |
51 | git rev-parse refs/heads/foo && |
52 | test_must_fail git symbolic-ref NOTHEAD | |
9ab55daa JH |
53 | ' |
54 | reset_to_sane | |
55 | ||
12cfa792 JH |
56 | test_expect_success 'symbolic-ref can delete dangling symref' ' |
57 | git symbolic-ref NOTHEAD refs/heads/missing && | |
58 | git symbolic-ref -d NOTHEAD && | |
b1259ecf HWN |
59 | test_must_fail git rev-parse refs/heads/missing && |
60 | test_must_fail git symbolic-ref NOTHEAD | |
9ab55daa JH |
61 | ' |
62 | reset_to_sane | |
63 | ||
64 | test_expect_success 'symbolic-ref fails to delete missing FOO' ' | |
65 | echo "fatal: Cannot delete FOO, not a symbolic ref" >expect && | |
66 | test_must_fail git symbolic-ref -d FOO >actual 2>&1 && | |
67 | test_cmp expect actual | |
68 | ' | |
69 | reset_to_sane | |
70 | ||
71 | test_expect_success 'symbolic-ref fails to delete real ref' ' | |
72 | echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect && | |
73 | test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 && | |
cbc5cf7c | 74 | git rev-parse --verify refs/heads/foo && |
9ab55daa JH |
75 | test_cmp expect actual |
76 | ' | |
77 | reset_to_sane | |
78 | ||
495127db JK |
79 | test_expect_success 'create large ref name' ' |
80 | # make 256+ character ref; some systems may not handle that, | |
81 | # so be gentle | |
82 | long=0123456789abcdef && | |
83 | long=$long/$long/$long/$long && | |
84 | long=$long/$long/$long/$long && | |
85 | long_ref=refs/heads/$long && | |
86 | tree=$(git write-tree) && | |
87 | commit=$(echo foo | git commit-tree $tree) && | |
88 | if git update-ref $long_ref $commit; then | |
89 | test_set_prereq LONG_REF | |
90 | else | |
91 | echo >&2 "long refs not supported" | |
92 | fi | |
93 | ' | |
94 | ||
95 | test_expect_success LONG_REF 'symbolic-ref can point to large ref name' ' | |
96 | git symbolic-ref HEAD $long_ref && | |
97 | echo $long_ref >expect && | |
98 | git symbolic-ref HEAD >actual && | |
99 | test_cmp expect actual | |
100 | ' | |
101 | ||
102 | test_expect_success LONG_REF 'we can parse long symbolic ref' ' | |
103 | echo $commit >expect && | |
104 | git rev-parse --verify HEAD >actual && | |
105 | test_cmp expect actual | |
106 | ' | |
107 | ||
3e4068ed | 108 | test_expect_success 'symbolic-ref reports failure in exit code' ' |
a26f1fb6 JT |
109 | # Create d/f conflict to simulate failure. |
110 | test_must_fail git symbolic-ref refs/heads refs/heads/foo | |
3e4068ed JK |
111 | ' |
112 | ||
f91b2732 JK |
113 | test_expect_success 'symbolic-ref writes reflog entry' ' |
114 | git checkout -b log1 && | |
115 | test_commit one && | |
116 | git checkout -b log2 && | |
117 | test_commit two && | |
118 | git checkout --orphan orphan && | |
119 | git symbolic-ref -m create HEAD refs/heads/log1 && | |
120 | git symbolic-ref -m update HEAD refs/heads/log2 && | |
121 | cat >expect <<-\EOF && | |
122 | update | |
123 | create | |
124 | EOF | |
71abeb75 | 125 | git log --format=%gs -g -2 >actual && |
f91b2732 JK |
126 | test_cmp expect actual |
127 | ' | |
128 | ||
370e5ad6 JK |
129 | test_expect_success 'symbolic-ref does not create ref d/f conflicts' ' |
130 | git checkout -b df && | |
131 | test_commit df && | |
132 | test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df && | |
133 | git pack-refs --all --prune && | |
134 | test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df | |
135 | ' | |
136 | ||
a1c1d817 JK |
137 | test_expect_success 'symbolic-ref can overwrite pointer to invalid name' ' |
138 | test_when_finished reset_to_sane && | |
2859dcd4 JK |
139 | head=$(git rev-parse HEAD) && |
140 | git symbolic-ref HEAD refs/heads/outer && | |
a1c1d817 | 141 | test_when_finished "git update-ref -d refs/heads/outer/inner" && |
2859dcd4 JK |
142 | git update-ref refs/heads/outer/inner $head && |
143 | git symbolic-ref HEAD refs/heads/unrelated | |
144 | ' | |
145 | ||
a1c1d817 JK |
146 | test_expect_success 'symbolic-ref can resolve d/f name (EISDIR)' ' |
147 | test_when_finished reset_to_sane && | |
148 | head=$(git rev-parse HEAD) && | |
149 | git symbolic-ref HEAD refs/heads/outer/inner && | |
150 | test_when_finished "git update-ref -d refs/heads/outer" && | |
151 | git update-ref refs/heads/outer $head && | |
152 | echo refs/heads/outer/inner >expect && | |
153 | git symbolic-ref HEAD >actual && | |
154 | test_cmp expect actual | |
155 | ' | |
156 | ||
157 | test_expect_success 'symbolic-ref can resolve d/f name (ENOTDIR)' ' | |
158 | test_when_finished reset_to_sane && | |
159 | head=$(git rev-parse HEAD) && | |
160 | git symbolic-ref HEAD refs/heads/outer && | |
161 | test_when_finished "git update-ref -d refs/heads/outer/inner" && | |
162 | git update-ref refs/heads/outer/inner $head && | |
163 | echo refs/heads/outer >expect && | |
164 | git symbolic-ref HEAD >actual && | |
165 | test_cmp expect actual | |
166 | ' | |
167 | ||
04ede972 LT |
168 | test_expect_success 'symbolic-ref refuses invalid target for non-HEAD' ' |
169 | test_must_fail git symbolic-ref refs/heads/invalid foo..bar | |
170 | ' | |
171 | ||
172 | test_expect_success 'symbolic-ref allows top-level target for non-HEAD' ' | |
b49831ca PS |
173 | git symbolic-ref refs/heads/top-level ORIG_HEAD && |
174 | git update-ref ORIG_HEAD HEAD && | |
04ede972 LT |
175 | test_cmp_rev top-level HEAD |
176 | ' | |
177 | ||
b77e3bdd JH |
178 | test_expect_success 'symbolic-ref pointing at another' ' |
179 | git update-ref refs/heads/maint-2.37 HEAD && | |
180 | git symbolic-ref refs/heads/maint refs/heads/maint-2.37 && | |
181 | git checkout maint && | |
182 | ||
183 | git symbolic-ref HEAD >actual && | |
184 | echo refs/heads/maint-2.37 >expect && | |
185 | test_cmp expect actual && | |
186 | ||
187 | git symbolic-ref --no-recurse HEAD >actual && | |
188 | echo refs/heads/maint >expect && | |
189 | test_cmp expect actual | |
190 | ' | |
191 | ||
613bef56 JK |
192 | test_expect_success 'symbolic-ref --short handles complex utf8 case' ' |
193 | name="测试-加-增加-加-增加" && | |
194 | git symbolic-ref TEST_SYMREF "refs/heads/$name" && | |
195 | # In the real world, we saw problems with this case only | |
196 | # when the locale includes UTF-8. Set it here to try to make things as | |
197 | # hard as possible for us to pass, but in practice we should do the | |
198 | # right thing regardless (and of course some platforms may not even | |
199 | # have this locale). | |
200 | LC_ALL=en_US.UTF-8 git symbolic-ref --short TEST_SYMREF >actual && | |
201 | echo "$name" >expect && | |
202 | test_cmp expect actual | |
203 | ' | |
204 | ||
205 | test_expect_success 'symbolic-ref --short handles name with suffix' ' | |
206 | git symbolic-ref TEST_SYMREF "refs/remotes/origin/HEAD" && | |
207 | git symbolic-ref --short TEST_SYMREF >actual && | |
208 | echo "origin" >expect && | |
209 | test_cmp expect actual | |
210 | ' | |
211 | ||
212 | test_expect_success 'symbolic-ref --short handles almost-matching name' ' | |
213 | git symbolic-ref TEST_SYMREF "refs/headsXfoo" && | |
214 | git symbolic-ref --short TEST_SYMREF >actual && | |
215 | echo "headsXfoo" >expect && | |
216 | test_cmp expect actual | |
217 | ' | |
218 | ||
219 | test_expect_success 'symbolic-ref --short handles name with percent' ' | |
220 | git symbolic-ref TEST_SYMREF "refs/heads/%foo" && | |
221 | git symbolic-ref --short TEST_SYMREF >actual && | |
222 | echo "%foo" >expect && | |
223 | test_cmp expect actual | |
224 | ' | |
225 | ||
afe5d3d5 | 226 | test_done |