]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1401-symbolic-ref.sh
help: make sure local html page exists before calling external processes
[thirdparty/git.git] / t / t1401-symbolic-ref.sh
1 #!/bin/sh
2
3 test_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.
9 reset_to_sane() {
10 rm -rf .git &&
11 "$TAR" xf .git.tar
12 }
13
14 test_expect_success 'setup' '
15 git symbolic-ref HEAD refs/heads/foo &&
16 test_commit file &&
17 "$TAR" cf .git.tar .git/
18 '
19
20 test_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 &&
23 git symbolic-ref HEAD >actual &&
24 test_cmp expect actual
25 '
26
27 test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
28 test_must_fail git symbolic-ref HEAD foo
29 '
30
31 reset_to_sane
32
33 test_expect_success 'symbolic-ref refuses bare sha1' '
34 test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
35 '
36
37 reset_to_sane
38
39 test_expect_success 'HEAD cannot be removed' '
40 test_must_fail git symbolic-ref -d HEAD
41 '
42
43 reset_to_sane
44
45 test_expect_success 'symbolic-ref can be deleted' '
46 git symbolic-ref NOTHEAD refs/heads/foo &&
47 git symbolic-ref -d NOTHEAD &&
48 git rev-parse refs/heads/foo &&
49 test_must_fail git symbolic-ref NOTHEAD
50 '
51 reset_to_sane
52
53 test_expect_success 'symbolic-ref can delete dangling symref' '
54 git symbolic-ref NOTHEAD refs/heads/missing &&
55 git symbolic-ref -d NOTHEAD &&
56 test_must_fail git rev-parse refs/heads/missing &&
57 test_must_fail git symbolic-ref NOTHEAD
58 '
59 reset_to_sane
60
61 test_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 '
66 reset_to_sane
67
68 test_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 &&
71 git rev-parse --verify refs/heads/foo &&
72 test_cmp expect actual
73 '
74 reset_to_sane
75
76 test_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
92 test_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
99 test_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
105 test_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
111 test_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
123 git log --format=%gs -g -2 >actual &&
124 test_cmp expect actual
125 '
126
127 test_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
135 test_expect_success 'symbolic-ref can overwrite pointer to invalid name' '
136 test_when_finished reset_to_sane &&
137 head=$(git rev-parse HEAD) &&
138 git symbolic-ref HEAD refs/heads/outer &&
139 test_when_finished "git update-ref -d refs/heads/outer/inner" &&
140 git update-ref refs/heads/outer/inner $head &&
141 git symbolic-ref HEAD refs/heads/unrelated
142 '
143
144 test_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
155 test_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
166 test_done