packed-backend: rip out some now-unused code
[alt-git.git] / t / t1401-symbolic-ref.sh
blobeec3e90f9c04e9b88ebb8c2ee6f12b96b75bac2b
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 echo ref: refs/heads/foo >.git/HEAD
13 test_expect_success 'symbolic-ref writes HEAD' '
14 git symbolic-ref HEAD refs/heads/foo &&
15 echo ref: refs/heads/foo >expect &&
16 test_cmp expect .git/HEAD
19 test_expect_success 'symbolic-ref reads HEAD' '
20 echo refs/heads/foo >expect &&
21 git symbolic-ref HEAD >actual &&
22 test_cmp expect actual
25 test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
26 test_must_fail git symbolic-ref HEAD foo
28 reset_to_sane
30 test_expect_success 'symbolic-ref refuses bare sha1' '
31 echo content >file && git add file && git commit -m one &&
32 test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
34 reset_to_sane
36 test_expect_success 'HEAD cannot be removed' '
37 test_must_fail git symbolic-ref -d HEAD
40 reset_to_sane
42 test_expect_success 'symbolic-ref can be deleted' '
43 git symbolic-ref NOTHEAD refs/heads/foo &&
44 git symbolic-ref -d NOTHEAD &&
45 test_path_is_file .git/refs/heads/foo &&
46 test_path_is_missing .git/NOTHEAD
48 reset_to_sane
50 test_expect_success 'symbolic-ref can delete dangling symref' '
51 git symbolic-ref NOTHEAD refs/heads/missing &&
52 git symbolic-ref -d NOTHEAD &&
53 test_path_is_missing .git/refs/heads/missing &&
54 test_path_is_missing .git/NOTHEAD
56 reset_to_sane
58 test_expect_success 'symbolic-ref fails to delete missing FOO' '
59 echo "fatal: Cannot delete FOO, not a symbolic ref" >expect &&
60 test_must_fail git symbolic-ref -d FOO >actual 2>&1 &&
61 test_cmp expect actual
63 reset_to_sane
65 test_expect_success 'symbolic-ref fails to delete real ref' '
66 echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&
67 test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 &&
68 test_path_is_file .git/refs/heads/foo &&
69 test_cmp expect actual
71 reset_to_sane
73 test_expect_success 'create large ref name' '
74 # make 256+ character ref; some systems may not handle that,
75 # so be gentle
76 long=0123456789abcdef &&
77 long=$long/$long/$long/$long &&
78 long=$long/$long/$long/$long &&
79 long_ref=refs/heads/$long &&
80 tree=$(git write-tree) &&
81 commit=$(echo foo | git commit-tree $tree) &&
82 if git update-ref $long_ref $commit; then
83 test_set_prereq LONG_REF
84 else
85 echo >&2 "long refs not supported"
89 test_expect_success LONG_REF 'symbolic-ref can point to large ref name' '
90 git symbolic-ref HEAD $long_ref &&
91 echo $long_ref >expect &&
92 git symbolic-ref HEAD >actual &&
93 test_cmp expect actual
96 test_expect_success LONG_REF 'we can parse long symbolic ref' '
97 echo $commit >expect &&
98 git rev-parse --verify HEAD >actual &&
99 test_cmp expect actual
102 test_expect_success 'symbolic-ref reports failure in exit code' '
103 test_when_finished "rm -f .git/HEAD.lock" &&
104 >.git/HEAD.lock &&
105 test_must_fail git symbolic-ref HEAD refs/heads/whatever
108 test_expect_success 'symbolic-ref writes reflog entry' '
109 git checkout -b log1 &&
110 test_commit one &&
111 git checkout -b log2 &&
112 test_commit two &&
113 git checkout --orphan orphan &&
114 git symbolic-ref -m create HEAD refs/heads/log1 &&
115 git symbolic-ref -m update HEAD refs/heads/log2 &&
116 cat >expect <<-\EOF &&
117 update
118 create
120 git log --format=%gs -g -2 >actual &&
121 test_cmp expect actual
124 test_expect_success 'symbolic-ref does not create ref d/f conflicts' '
125 git checkout -b df &&
126 test_commit df &&
127 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df &&
128 git pack-refs --all --prune &&
129 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df
132 test_expect_success 'symbolic-ref handles existing pointer to invalid name' '
133 head=$(git rev-parse HEAD) &&
134 git symbolic-ref HEAD refs/heads/outer &&
135 git update-ref refs/heads/outer/inner $head &&
136 git symbolic-ref HEAD refs/heads/unrelated
139 test_done