]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1401-symbolic-ref.sh
Merge branch 'nd/dwim-wildcards-as-pathspecs'
[thirdparty/git.git] / t / t1401-symbolic-ref.sh
1 #!/bin/sh
2
3 test_description='basic symbolic-ref tests'
4 . ./test-lib.sh
5
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
11 }
12
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
17 '
18
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
23 '
24
25 test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
26 test_must_fail git symbolic-ref HEAD foo
27 '
28 reset_to_sane
29
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)
33 '
34 reset_to_sane
35
36 test_expect_success 'symbolic-ref deletes HEAD' '
37 git symbolic-ref -d HEAD &&
38 test_path_is_file .git/refs/heads/foo &&
39 test_path_is_missing .git/HEAD
40 '
41 reset_to_sane
42
43 test_expect_success 'symbolic-ref deletes dangling HEAD' '
44 git symbolic-ref HEAD refs/heads/missing &&
45 git symbolic-ref -d HEAD &&
46 test_path_is_missing .git/refs/heads/missing &&
47 test_path_is_missing .git/HEAD
48 '
49 reset_to_sane
50
51 test_expect_success 'symbolic-ref fails to delete missing FOO' '
52 echo "fatal: Cannot delete FOO, not a symbolic ref" >expect &&
53 test_must_fail git symbolic-ref -d FOO >actual 2>&1 &&
54 test_cmp expect actual
55 '
56 reset_to_sane
57
58 test_expect_success 'symbolic-ref fails to delete real ref' '
59 echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&
60 test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 &&
61 test_path_is_file .git/refs/heads/foo &&
62 test_cmp expect actual
63 '
64 reset_to_sane
65
66 test_expect_success 'create large ref name' '
67 # make 256+ character ref; some systems may not handle that,
68 # so be gentle
69 long=0123456789abcdef &&
70 long=$long/$long/$long/$long &&
71 long=$long/$long/$long/$long &&
72 long_ref=refs/heads/$long &&
73 tree=$(git write-tree) &&
74 commit=$(echo foo | git commit-tree $tree) &&
75 if git update-ref $long_ref $commit; then
76 test_set_prereq LONG_REF
77 else
78 echo >&2 "long refs not supported"
79 fi
80 '
81
82 test_expect_success LONG_REF 'symbolic-ref can point to large ref name' '
83 git symbolic-ref HEAD $long_ref &&
84 echo $long_ref >expect &&
85 git symbolic-ref HEAD >actual &&
86 test_cmp expect actual
87 '
88
89 test_expect_success LONG_REF 'we can parse long symbolic ref' '
90 echo $commit >expect &&
91 git rev-parse --verify HEAD >actual &&
92 test_cmp expect actual
93 '
94
95 test_expect_success 'symbolic-ref reports failure in exit code' '
96 test_when_finished "rm -f .git/HEAD.lock" &&
97 >.git/HEAD.lock &&
98 test_must_fail git symbolic-ref HEAD refs/heads/whatever
99 '
100
101 test_expect_success 'symbolic-ref writes reflog entry' '
102 git checkout -b log1 &&
103 test_commit one &&
104 git checkout -b log2 &&
105 test_commit two &&
106 git checkout --orphan orphan &&
107 git symbolic-ref -m create HEAD refs/heads/log1 &&
108 git symbolic-ref -m update HEAD refs/heads/log2 &&
109 cat >expect <<-\EOF &&
110 update
111 create
112 EOF
113 git log --format=%gs -g >actual &&
114 test_cmp expect actual
115 '
116
117 test_expect_success 'symbolic-ref does not create ref d/f conflicts' '
118 git checkout -b df &&
119 test_commit df &&
120 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df &&
121 git pack-refs --all --prune &&
122 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df
123 '
124
125 test_expect_success 'symbolic-ref handles existing pointer to invalid name' '
126 head=$(git rev-parse HEAD) &&
127 git symbolic-ref HEAD refs/heads/outer &&
128 git update-ref refs/heads/outer/inner $head &&
129 git symbolic-ref HEAD refs/heads/unrelated
130 '
131
132 test_done