t1010: fix unnoticed failure on Windows
[git.git] / t / t1401-symbolic-ref.sh
blob132a1b885acbce46cb9f8a1b52fc2833fc8a7990
1 #!/bin/sh
3 test_description='basic symbolic-ref tests'
4 . ./test-lib.sh
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
14 test_expect_success 'setup' '
15 git symbolic-ref HEAD refs/heads/foo &&
16 test_commit file &&
17 "$TAR" cf .git.tar .git/
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
27 test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
28 test_must_fail git symbolic-ref HEAD foo
31 reset_to_sane
33 test_expect_success 'symbolic-ref refuses bare sha1' '
34 test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
37 reset_to_sane
39 test_expect_success 'HEAD cannot be removed' '
40 test_must_fail git symbolic-ref -d HEAD
43 reset_to_sane
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
51 reset_to_sane
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
59 reset_to_sane
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
66 reset_to_sane
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
74 reset_to_sane
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"
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
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
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
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
123 git log --format=%gs -g -2 >actual &&
124 test_cmp expect actual
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
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
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
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
166 test_done