]>
Commit | Line | Data |
---|---|---|
afe5d3d5 JK |
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 | ||
afe5d3d5 | 30 | test_expect_success 'symbolic-ref refuses bare sha1' ' |
a48fcd83 | 31 | echo content >file && git add file && git commit -m one && |
8a7b73c1 | 32 | test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD) |
afe5d3d5 JK |
33 | ' |
34 | reset_to_sane | |
35 | ||
12cfa792 JH |
36 | test_expect_success 'HEAD cannot be removed' ' |
37 | test_must_fail git symbolic-ref -d HEAD | |
38 | ' | |
39 | ||
40 | reset_to_sane | |
41 | ||
42 | test_expect_success 'symbolic-ref can be deleted' ' | |
43 | git symbolic-ref NOTHEAD refs/heads/foo && | |
44 | git symbolic-ref -d NOTHEAD && | |
9ab55daa | 45 | test_path_is_file .git/refs/heads/foo && |
12cfa792 | 46 | test_path_is_missing .git/NOTHEAD |
9ab55daa JH |
47 | ' |
48 | reset_to_sane | |
49 | ||
12cfa792 JH |
50 | test_expect_success 'symbolic-ref can delete dangling symref' ' |
51 | git symbolic-ref NOTHEAD refs/heads/missing && | |
52 | git symbolic-ref -d NOTHEAD && | |
9ab55daa | 53 | test_path_is_missing .git/refs/heads/missing && |
12cfa792 | 54 | test_path_is_missing .git/NOTHEAD |
9ab55daa JH |
55 | ' |
56 | reset_to_sane | |
57 | ||
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 | |
62 | ' | |
63 | reset_to_sane | |
64 | ||
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 && | |
cbc5cf7c | 68 | git rev-parse --verify refs/heads/foo && |
9ab55daa JH |
69 | test_cmp expect actual |
70 | ' | |
71 | reset_to_sane | |
72 | ||
495127db JK |
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" | |
86 | fi | |
87 | ' | |
88 | ||
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 | |
94 | ' | |
95 | ||
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 | |
100 | ' | |
101 | ||
3e4068ed JK |
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 | |
106 | ' | |
107 | ||
f91b2732 JK |
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 | |
119 | EOF | |
71abeb75 | 120 | git log --format=%gs -g -2 >actual && |
f91b2732 JK |
121 | test_cmp expect actual |
122 | ' | |
123 | ||
370e5ad6 JK |
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 | |
130 | ' | |
131 | ||
a1c1d817 JK |
132 | test_expect_success 'symbolic-ref can overwrite pointer to invalid name' ' |
133 | test_when_finished reset_to_sane && | |
2859dcd4 JK |
134 | head=$(git rev-parse HEAD) && |
135 | git symbolic-ref HEAD refs/heads/outer && | |
a1c1d817 | 136 | test_when_finished "git update-ref -d refs/heads/outer/inner" && |
2859dcd4 JK |
137 | git update-ref refs/heads/outer/inner $head && |
138 | git symbolic-ref HEAD refs/heads/unrelated | |
139 | ' | |
140 | ||
a1c1d817 JK |
141 | test_expect_success 'symbolic-ref can resolve d/f name (EISDIR)' ' |
142 | test_when_finished reset_to_sane && | |
143 | head=$(git rev-parse HEAD) && | |
144 | git symbolic-ref HEAD refs/heads/outer/inner && | |
145 | test_when_finished "git update-ref -d refs/heads/outer" && | |
146 | git update-ref refs/heads/outer $head && | |
147 | echo refs/heads/outer/inner >expect && | |
148 | git symbolic-ref HEAD >actual && | |
149 | test_cmp expect actual | |
150 | ' | |
151 | ||
152 | test_expect_success 'symbolic-ref can resolve d/f name (ENOTDIR)' ' | |
153 | test_when_finished reset_to_sane && | |
154 | head=$(git rev-parse HEAD) && | |
155 | git symbolic-ref HEAD refs/heads/outer && | |
156 | test_when_finished "git update-ref -d refs/heads/outer/inner" && | |
157 | git update-ref refs/heads/outer/inner $head && | |
158 | echo refs/heads/outer >expect && | |
159 | git symbolic-ref HEAD >actual && | |
160 | test_cmp expect actual | |
161 | ' | |
162 | ||
afe5d3d5 | 163 | test_done |