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 test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
41 test_expect_success
'HEAD cannot be removed' '
42 test_must_fail git symbolic-ref -d HEAD
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
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
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
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
78 test_expect_success
'create large ref name' '
79 # make 256+ character ref; some systems may not handle that,
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
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" &&
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 &&
116 git checkout -b log2 &&
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 &&
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 &&
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