diagnose.c: add option to configure archive contents
[alt-git.git] / t / t1401-symbolic-ref.sh
blob9fb0b90f252aa17a04a52678eb48a3a9bf9883ee
1 #!/bin/sh
3 test_description='basic symbolic-ref tests'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
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
16 test_expect_success 'setup' '
17 git symbolic-ref HEAD refs/heads/foo &&
18 test_commit file &&
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
33 reset_to_sane
35 test_expect_success 'symbolic-ref refuses bare sha1' '
36 test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
39 reset_to_sane
41 test_expect_success 'HEAD cannot be removed' '
42 test_must_fail git symbolic-ref -d HEAD
45 reset_to_sane
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
53 reset_to_sane
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
61 reset_to_sane
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
68 reset_to_sane
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
76 reset_to_sane
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"
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
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
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
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
125 git log --format=%gs -g -2 >actual &&
126 test_cmp expect actual
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
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
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
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
168 test_done