1#!/bin/sh
23
test_description='basic symbolic-ref tests'
4. ./test-lib.sh
56
# 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.
9reset_to_sane() {
10echo ref: refs/heads/foo >.git/HEAD
11}
1213
test_expect_success 'symbolic-ref writes HEAD' '
14git symbolic-ref HEAD refs/heads/foo &&
15echo ref: refs/heads/foo >expect &&
16test_cmp expect .git/HEAD
17'
1819
test_expect_success 'symbolic-ref reads HEAD' '
20echo refs/heads/foo >expect &&
21git symbolic-ref HEAD >actual &&
22test_cmp expect actual
23'
2425
test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
26test_must_fail git symbolic-ref HEAD foo
27'
28reset_to_sane
2930
test_expect_success 'symbolic-ref refuses bare sha1' '
31echo content >file && git add file && git commit -m one &&
32test_must_fail git symbolic-ref HEAD `git rev-parse HEAD`
33'
34reset_to_sane
3536
test_expect_success 'symbolic-ref deletes HEAD' '
37git symbolic-ref -d HEAD &&
38test_path_is_file .git/refs/heads/foo &&
39test_path_is_missing .git/HEAD
40'
41reset_to_sane
4243
test_expect_success 'symbolic-ref deletes dangling HEAD' '
44git symbolic-ref HEAD refs/heads/missing &&
45git symbolic-ref -d HEAD &&
46test_path_is_missing .git/refs/heads/missing &&
47test_path_is_missing .git/HEAD
48'
49reset_to_sane
5051
test_expect_success 'symbolic-ref fails to delete missing FOO' '
52echo "fatal: Cannot delete FOO, not a symbolic ref" >expect &&
53test_must_fail git symbolic-ref -d FOO >actual 2>&1 &&
54test_cmp expect actual
55'
56reset_to_sane
5758
test_expect_success 'symbolic-ref fails to delete real ref' '
59echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&
60test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 &&
61test_path_is_file .git/refs/heads/foo &&
62test_cmp expect actual
63'
64reset_to_sane
6566
test_expect_success 'create large ref name' '
67# make 256+ character ref; some systems may not handle that,
68# so be gentle
69long=0123456789abcdef &&
70long=$long/$long/$long/$long &&
71long=$long/$long/$long/$long &&
72long_ref=refs/heads/$long &&
73tree=$(git write-tree) &&
74commit=$(echo foo | git commit-tree $tree) &&
75if git update-ref $long_ref $commit; then
76test_set_prereq LONG_REF
77else
78echo >&2 "long refs not supported"
79fi
80'
8182
test_expect_success LONG_REF 'symbolic-ref can point to large ref name' '
83git symbolic-ref HEAD $long_ref &&
84echo $long_ref >expect &&
85git symbolic-ref HEAD >actual &&
86test_cmp expect actual
87'
8889
test_expect_success LONG_REF 'we can parse long symbolic ref' '
90echo $commit >expect &&
91git rev-parse --verify HEAD >actual &&
92test_cmp expect actual
93'
9495
test_expect_success 'symbolic-ref reports failure in exit code' '
96test_when_finished "rm -f .git/HEAD.lock" &&
97>.git/HEAD.lock &&
98test_must_fail git symbolic-ref HEAD refs/heads/whatever
99'
100101
test_expect_success 'symbolic-ref writes reflog entry' '
102git checkout -b log1 &&
103test_commit one &&
104git checkout -b log2 &&
105test_commit two &&
106git checkout --orphan orphan &&
107git symbolic-ref -m create HEAD refs/heads/log1 &&
108git symbolic-ref -m update HEAD refs/heads/log2 &&
109cat >expect <<-\EOF &&
110update
111create
112EOF
113git log --format=%gs -g >actual &&
114test_cmp expect actual
115'
116117
test_done