3 test_description
='basic symbolic-ref tests'
5 TEST_PASSES_SANITIZE_LEAK
=true
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.
16 test_expect_success
'setup' '
17 git symbolic-ref HEAD refs/heads/foo &&
19 "$TAR" cf .git.tar .git/
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 &&
25 git symbolic-ref HEAD >actual &&
26 test_cmp expect actual
29 test_expect_success
'symbolic-ref refuses non-ref for HEAD' '
30 test_must_fail git symbolic-ref HEAD foo
35 test_expect_success
'symbolic-ref refuses bare sha1' '
36 rev=$(git rev-parse HEAD) &&
37 test_must_fail git symbolic-ref HEAD "$rev"
42 test_expect_success
'HEAD cannot be removed' '
43 test_must_fail git symbolic-ref -d HEAD
48 test_expect_success
'symbolic-ref can be deleted' '
49 git symbolic-ref NOTHEAD refs/heads/foo &&
50 git symbolic-ref -d NOTHEAD &&
51 git rev-parse refs/heads/foo &&
52 test_must_fail git symbolic-ref NOTHEAD
56 test_expect_success
'symbolic-ref can delete dangling symref' '
57 git symbolic-ref NOTHEAD refs/heads/missing &&
58 git symbolic-ref -d NOTHEAD &&
59 test_must_fail git rev-parse refs/heads/missing &&
60 test_must_fail git symbolic-ref NOTHEAD
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
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 &&
74 git rev-parse --verify refs/heads/foo &&
75 test_cmp expect actual
79 test_expect_success
'create large ref name' '
80 # make 256+ character ref; some systems may not handle that,
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
91 echo >&2 "long refs not supported"
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
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
108 test_expect_success
'symbolic-ref reports failure in exit code' '
109 test_when_finished "rm -f .git/HEAD.lock" &&
111 test_must_fail git symbolic-ref HEAD refs/heads/whatever
114 test_expect_success
'symbolic-ref writes reflog entry' '
115 git checkout -b log1 &&
117 git checkout -b log2 &&
119 git checkout --orphan orphan &&
120 git symbolic-ref -m create HEAD refs/heads/log1 &&
121 git symbolic-ref -m update HEAD refs/heads/log2 &&
122 cat >expect <<-\EOF &&
126 git log --format=%gs -g -2 >actual &&
127 test_cmp expect actual
130 test_expect_success
'symbolic-ref does not create ref d/f conflicts' '
131 git checkout -b df &&
133 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df &&
134 git pack-refs --all --prune &&
135 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df
138 test_expect_success
'symbolic-ref can overwrite pointer to invalid name' '
139 test_when_finished reset_to_sane &&
140 head=$(git rev-parse HEAD) &&
141 git symbolic-ref HEAD refs/heads/outer &&
142 test_when_finished "git update-ref -d refs/heads/outer/inner" &&
143 git update-ref refs/heads/outer/inner $head &&
144 git symbolic-ref HEAD refs/heads/unrelated
147 test_expect_success
'symbolic-ref can resolve d/f name (EISDIR)' '
148 test_when_finished reset_to_sane &&
149 head=$(git rev-parse HEAD) &&
150 git symbolic-ref HEAD refs/heads/outer/inner &&
151 test_when_finished "git update-ref -d refs/heads/outer" &&
152 git update-ref refs/heads/outer $head &&
153 echo refs/heads/outer/inner >expect &&
154 git symbolic-ref HEAD >actual &&
155 test_cmp expect actual
158 test_expect_success
'symbolic-ref can resolve d/f name (ENOTDIR)' '
159 test_when_finished reset_to_sane &&
160 head=$(git rev-parse HEAD) &&
161 git symbolic-ref HEAD refs/heads/outer &&
162 test_when_finished "git update-ref -d refs/heads/outer/inner" &&
163 git update-ref refs/heads/outer/inner $head &&
164 echo refs/heads/outer >expect &&
165 git symbolic-ref HEAD >actual &&
166 test_cmp expect actual
169 test_expect_success
'symbolic-ref refuses invalid target for non-HEAD' '
170 test_must_fail git symbolic-ref refs/heads/invalid foo..bar
173 test_expect_success
'symbolic-ref allows top-level target for non-HEAD' '
174 git symbolic-ref refs/heads/top-level FETCH_HEAD &&
175 git update-ref FETCH_HEAD HEAD &&
176 test_cmp_rev top-level HEAD
179 test_expect_success
'symbolic-ref pointing at another' '
180 git update-ref refs/heads/maint-2.37 HEAD &&
181 git symbolic-ref refs/heads/maint refs/heads/maint-2.37 &&
182 git checkout maint &&
184 git symbolic-ref HEAD >actual &&
185 echo refs/heads/maint-2.37 >expect &&
186 test_cmp expect actual &&
188 git symbolic-ref --no-recurse HEAD >actual &&
189 echo refs/heads/maint >expect &&
190 test_cmp expect actual
193 test_expect_success
'symbolic-ref --short handles complex utf8 case' '
194 name="测试-加-增加-加-增加" &&
195 git symbolic-ref TEST_SYMREF "refs/heads/$name" &&
196 # In the real world, we saw problems with this case only
197 # when the locale includes UTF-8. Set it here to try to make things as
198 # hard as possible for us to pass, but in practice we should do the
199 # right thing regardless (and of course some platforms may not even
201 LC_ALL=en_US.UTF-8 git symbolic-ref --short TEST_SYMREF >actual &&
202 echo "$name" >expect &&
203 test_cmp expect actual
206 test_expect_success
'symbolic-ref --short handles name with suffix' '
207 git symbolic-ref TEST_SYMREF "refs/remotes/origin/HEAD" &&
208 git symbolic-ref --short TEST_SYMREF >actual &&
209 echo "origin" >expect &&
210 test_cmp expect actual
213 test_expect_success
'symbolic-ref --short handles almost-matching name' '
214 git symbolic-ref TEST_SYMREF "refs/headsXfoo" &&
215 git symbolic-ref --short TEST_SYMREF >actual &&
216 echo "headsXfoo" >expect &&
217 test_cmp expect actual
220 test_expect_success
'symbolic-ref --short handles name with percent' '
221 git symbolic-ref TEST_SYMREF "refs/heads/%foo" &&
222 git symbolic-ref --short TEST_SYMREF >actual &&
223 echo "%foo" >expect &&
224 test_cmp expect actual