]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1401-symbolic-ref.sh
Doc: no midx and partial clone relation
[thirdparty/git.git] / t / t1401-symbolic-ref.sh
CommitLineData
afe5d3d5
JK
1#!/bin/sh
2
3test_description='basic symbolic-ref tests'
4. ./test-lib.sh
5
6# If the tests munging HEAD fail, they can break detection of
7# the git repo, meaning that further tests will operate on
8# the surrounding git repo instead of the trash directory.
9reset_to_sane() {
9910cbb6
HWN
10 rm -rf .git &&
11 "$TAR" xf .git.tar
afe5d3d5
JK
12}
13
9910cbb6
HWN
14test_expect_success 'setup' '
15 git symbolic-ref HEAD refs/heads/foo &&
16 test_commit file &&
17 "$TAR" cf .git.tar .git/
18'
19
b1259ecf
HWN
20test_expect_success 'symbolic-ref read/write roundtrip' '
21 git symbolic-ref HEAD refs/heads/read-write-roundtrip &&
22 echo refs/heads/read-write-roundtrip >expect &&
afe5d3d5
JK
23 git symbolic-ref HEAD >actual &&
24 test_cmp expect actual
25'
26
27test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
28 test_must_fail git symbolic-ref HEAD foo
29'
b1259ecf 30
afe5d3d5
JK
31reset_to_sane
32
afe5d3d5 33test_expect_success 'symbolic-ref refuses bare sha1' '
8a7b73c1 34 test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
afe5d3d5 35'
b1259ecf 36
afe5d3d5
JK
37reset_to_sane
38
12cfa792
JH
39test_expect_success 'HEAD cannot be removed' '
40 test_must_fail git symbolic-ref -d HEAD
41'
42
43reset_to_sane
44
45test_expect_success 'symbolic-ref can be deleted' '
46 git symbolic-ref NOTHEAD refs/heads/foo &&
47 git symbolic-ref -d NOTHEAD &&
b1259ecf
HWN
48 git rev-parse refs/heads/foo &&
49 test_must_fail git symbolic-ref NOTHEAD
9ab55daa
JH
50'
51reset_to_sane
52
12cfa792
JH
53test_expect_success 'symbolic-ref can delete dangling symref' '
54 git symbolic-ref NOTHEAD refs/heads/missing &&
55 git symbolic-ref -d NOTHEAD &&
b1259ecf
HWN
56 test_must_fail git rev-parse refs/heads/missing &&
57 test_must_fail git symbolic-ref NOTHEAD
9ab55daa
JH
58'
59reset_to_sane
60
61test_expect_success 'symbolic-ref fails to delete missing FOO' '
62 echo "fatal: Cannot delete FOO, not a symbolic ref" >expect &&
63 test_must_fail git symbolic-ref -d FOO >actual 2>&1 &&
64 test_cmp expect actual
65'
66reset_to_sane
67
68test_expect_success 'symbolic-ref fails to delete real ref' '
69 echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&
70 test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 &&
cbc5cf7c 71 git rev-parse --verify refs/heads/foo &&
9ab55daa
JH
72 test_cmp expect actual
73'
74reset_to_sane
75
495127db
JK
76test_expect_success 'create large ref name' '
77 # make 256+ character ref; some systems may not handle that,
78 # so be gentle
79 long=0123456789abcdef &&
80 long=$long/$long/$long/$long &&
81 long=$long/$long/$long/$long &&
82 long_ref=refs/heads/$long &&
83 tree=$(git write-tree) &&
84 commit=$(echo foo | git commit-tree $tree) &&
85 if git update-ref $long_ref $commit; then
86 test_set_prereq LONG_REF
87 else
88 echo >&2 "long refs not supported"
89 fi
90'
91
92test_expect_success LONG_REF 'symbolic-ref can point to large ref name' '
93 git symbolic-ref HEAD $long_ref &&
94 echo $long_ref >expect &&
95 git symbolic-ref HEAD >actual &&
96 test_cmp expect actual
97'
98
99test_expect_success LONG_REF 'we can parse long symbolic ref' '
100 echo $commit >expect &&
101 git rev-parse --verify HEAD >actual &&
102 test_cmp expect actual
103'
104
3e4068ed
JK
105test_expect_success 'symbolic-ref reports failure in exit code' '
106 test_when_finished "rm -f .git/HEAD.lock" &&
107 >.git/HEAD.lock &&
108 test_must_fail git symbolic-ref HEAD refs/heads/whatever
109'
110
f91b2732
JK
111test_expect_success 'symbolic-ref writes reflog entry' '
112 git checkout -b log1 &&
113 test_commit one &&
114 git checkout -b log2 &&
115 test_commit two &&
116 git checkout --orphan orphan &&
117 git symbolic-ref -m create HEAD refs/heads/log1 &&
118 git symbolic-ref -m update HEAD refs/heads/log2 &&
119 cat >expect <<-\EOF &&
120 update
121 create
122 EOF
71abeb75 123 git log --format=%gs -g -2 >actual &&
f91b2732
JK
124 test_cmp expect actual
125'
126
370e5ad6
JK
127test_expect_success 'symbolic-ref does not create ref d/f conflicts' '
128 git checkout -b df &&
129 test_commit df &&
130 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df &&
131 git pack-refs --all --prune &&
132 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df
133'
134
a1c1d817
JK
135test_expect_success 'symbolic-ref can overwrite pointer to invalid name' '
136 test_when_finished reset_to_sane &&
2859dcd4
JK
137 head=$(git rev-parse HEAD) &&
138 git symbolic-ref HEAD refs/heads/outer &&
a1c1d817 139 test_when_finished "git update-ref -d refs/heads/outer/inner" &&
2859dcd4
JK
140 git update-ref refs/heads/outer/inner $head &&
141 git symbolic-ref HEAD refs/heads/unrelated
142'
143
a1c1d817
JK
144test_expect_success 'symbolic-ref can resolve d/f name (EISDIR)' '
145 test_when_finished reset_to_sane &&
146 head=$(git rev-parse HEAD) &&
147 git symbolic-ref HEAD refs/heads/outer/inner &&
148 test_when_finished "git update-ref -d refs/heads/outer" &&
149 git update-ref refs/heads/outer $head &&
150 echo refs/heads/outer/inner >expect &&
151 git symbolic-ref HEAD >actual &&
152 test_cmp expect actual
153'
154
155test_expect_success 'symbolic-ref can resolve d/f name (ENOTDIR)' '
156 test_when_finished reset_to_sane &&
157 head=$(git rev-parse HEAD) &&
158 git symbolic-ref HEAD refs/heads/outer &&
159 test_when_finished "git update-ref -d refs/heads/outer/inner" &&
160 git update-ref refs/heads/outer/inner $head &&
161 echo refs/heads/outer >expect &&
162 git symbolic-ref HEAD >actual &&
163 test_cmp expect actual
164'
165
afe5d3d5 166test_done