]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1401-symbolic-ref.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t1401-symbolic-ref.sh
1 #!/bin/sh
2
3 test_description='basic symbolic-ref tests'
4
5 TEST_PASSES_SANITIZE_LEAK=true
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() {
12 rm -rf .git &&
13 "$TAR" xf .git.tar
14 }
15
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
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
27 '
28
29 test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
30 test_must_fail git symbolic-ref HEAD foo
31 '
32
33 reset_to_sane
34
35 test_expect_success 'symbolic-ref refuses bare sha1' '
36 test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
37 '
38
39 reset_to_sane
40
41 test_expect_success 'HEAD cannot be removed' '
42 test_must_fail git symbolic-ref -d HEAD
43 '
44
45 reset_to_sane
46
47 test_expect_success 'symbolic-ref can be deleted' '
48 git symbolic-ref NOTHEAD refs/heads/foo &&
49 git symbolic-ref -d NOTHEAD &&
50 git rev-parse refs/heads/foo &&
51 test_must_fail git symbolic-ref NOTHEAD
52 '
53 reset_to_sane
54
55 test_expect_success 'symbolic-ref can delete dangling symref' '
56 git symbolic-ref NOTHEAD refs/heads/missing &&
57 git symbolic-ref -d NOTHEAD &&
58 test_must_fail git rev-parse refs/heads/missing &&
59 test_must_fail git symbolic-ref NOTHEAD
60 '
61 reset_to_sane
62
63 test_expect_success 'symbolic-ref fails to delete missing FOO' '
64 echo "fatal: Cannot delete FOO, not a symbolic ref" >expect &&
65 test_must_fail git symbolic-ref -d FOO >actual 2>&1 &&
66 test_cmp expect actual
67 '
68 reset_to_sane
69
70 test_expect_success 'symbolic-ref fails to delete real ref' '
71 echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&
72 test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 &&
73 git rev-parse --verify refs/heads/foo &&
74 test_cmp expect actual
75 '
76 reset_to_sane
77
78 test_expect_success 'create large ref name' '
79 # make 256+ character ref; some systems may not handle that,
80 # so be gentle
81 long=0123456789abcdef &&
82 long=$long/$long/$long/$long &&
83 long=$long/$long/$long/$long &&
84 long_ref=refs/heads/$long &&
85 tree=$(git write-tree) &&
86 commit=$(echo foo | git commit-tree $tree) &&
87 if git update-ref $long_ref $commit; then
88 test_set_prereq LONG_REF
89 else
90 echo >&2 "long refs not supported"
91 fi
92 '
93
94 test_expect_success LONG_REF 'symbolic-ref can point to large ref name' '
95 git symbolic-ref HEAD $long_ref &&
96 echo $long_ref >expect &&
97 git symbolic-ref HEAD >actual &&
98 test_cmp expect actual
99 '
100
101 test_expect_success LONG_REF 'we can parse long symbolic ref' '
102 echo $commit >expect &&
103 git rev-parse --verify HEAD >actual &&
104 test_cmp expect actual
105 '
106
107 test_expect_success 'symbolic-ref reports failure in exit code' '
108 test_when_finished "rm -f .git/HEAD.lock" &&
109 >.git/HEAD.lock &&
110 test_must_fail git symbolic-ref HEAD refs/heads/whatever
111 '
112
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
125 git log --format=%gs -g -2 >actual &&
126 test_cmp expect actual
127 '
128
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
137 test_expect_success 'symbolic-ref can overwrite pointer to invalid name' '
138 test_when_finished reset_to_sane &&
139 head=$(git rev-parse HEAD) &&
140 git symbolic-ref HEAD refs/heads/outer &&
141 test_when_finished "git update-ref -d refs/heads/outer/inner" &&
142 git update-ref refs/heads/outer/inner $head &&
143 git symbolic-ref HEAD refs/heads/unrelated
144 '
145
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
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' '
173 git symbolic-ref refs/heads/top-level FETCH_HEAD &&
174 git update-ref FETCH_HEAD HEAD &&
175 test_cmp_rev top-level HEAD
176 '
177
178 test_done