]>
Commit | Line | Data |
---|---|---|
28fb8438 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='test <branch>@{upstream} syntax' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | ||
8 | test_expect_success 'setup' ' | |
9 | ||
10 | test_commit 1 && | |
11 | git checkout -b side && | |
12 | test_commit 2 && | |
13 | git checkout master && | |
14 | git clone . clone && | |
15 | test_commit 3 && | |
16 | (cd clone && | |
17 | test_commit 4 && | |
1b4aee94 ZJS |
18 | git branch --track my-side origin/side && |
19 | git branch --track local-master master && | |
9892d5d4 JK |
20 | git branch --track fun@ny origin/side && |
21 | git branch --track @funny origin/side && | |
22 | git branch --track funny@ origin/side && | |
1b4aee94 ZJS |
23 | git remote add -t master master-only .. && |
24 | git fetch master-only && | |
25 | git branch bad-upstream && | |
26 | git config branch.bad-upstream.remote master-only && | |
27 | git config branch.bad-upstream.merge refs/heads/side | |
28 | ) | |
28fb8438 JS |
29 | ' |
30 | ||
31 | full_name () { | |
32 | (cd clone && | |
33 | git rev-parse --symbolic-full-name "$@") | |
34 | } | |
35 | ||
36 | commit_subject () { | |
37 | (cd clone && | |
38 | git show -s --pretty=format:%s "$@") | |
39 | } | |
40 | ||
1b4aee94 ZJS |
41 | error_message () { |
42 | (cd clone && | |
c3a44562 | 43 | test_must_fail git rev-parse --verify "$@" 2>../error) |
1b4aee94 ZJS |
44 | } |
45 | ||
28fb8438 | 46 | test_expect_success '@{upstream} resolves to correct full name' ' |
244ea1b5 ÆAB |
47 | test refs/remotes/origin/master = "$(full_name @{upstream})" && |
48 | test refs/remotes/origin/master = "$(full_name @{UPSTREAM})" && | |
49 | test refs/remotes/origin/master = "$(full_name @{UpSTReam})" | |
28fb8438 JS |
50 | ' |
51 | ||
52 | test_expect_success '@{u} resolves to correct full name' ' | |
244ea1b5 ÆAB |
53 | test refs/remotes/origin/master = "$(full_name @{u})" && |
54 | test refs/remotes/origin/master = "$(full_name @{U})" | |
28fb8438 JS |
55 | ' |
56 | ||
57 | test_expect_success 'my-side@{upstream} resolves to correct full name' ' | |
58 | test refs/remotes/origin/side = "$(full_name my-side@{u})" | |
59 | ' | |
60 | ||
9892d5d4 JK |
61 | test_expect_success 'upstream of branch with @ in middle' ' |
62 | full_name fun@ny@{u} >actual && | |
63 | echo refs/remotes/origin/side >expect && | |
244ea1b5 ÆAB |
64 | test_cmp expect actual && |
65 | full_name fun@ny@{U} >actual && | |
9892d5d4 JK |
66 | test_cmp expect actual |
67 | ' | |
68 | ||
69 | test_expect_success 'upstream of branch with @ at start' ' | |
70 | full_name @funny@{u} >actual && | |
71 | echo refs/remotes/origin/side >expect && | |
72 | test_cmp expect actual | |
73 | ' | |
74 | ||
75 | test_expect_success 'upstream of branch with @ at end' ' | |
76 | full_name funny@@{u} >actual && | |
77 | echo refs/remotes/origin/side >expect && | |
78 | test_cmp expect actual | |
79 | ' | |
80 | ||
617cf931 KK |
81 | test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' ' |
82 | test_must_fail full_name refs/heads/my-side@{upstream} | |
83 | ' | |
84 | ||
28fb8438 JS |
85 | test_expect_success 'my-side@{u} resolves to correct commit' ' |
86 | git checkout side && | |
87 | test_commit 5 && | |
88 | (cd clone && git fetch) && | |
89 | test 2 = "$(commit_subject my-side)" && | |
90 | test 5 = "$(commit_subject my-side@{u})" | |
91 | ' | |
92 | ||
93 | test_expect_success 'not-tracking@{u} fails' ' | |
94 | test_must_fail full_name non-tracking@{u} && | |
95 | (cd clone && git checkout --no-track -b non-tracking) && | |
96 | test_must_fail full_name non-tracking@{u} | |
97 | ' | |
98 | ||
99 | test_expect_success '<branch>@{u}@{1} resolves correctly' ' | |
100 | test_commit 6 && | |
101 | (cd clone && git fetch) && | |
244ea1b5 ÆAB |
102 | test 5 = $(commit_subject my-side@{u}@{1}) && |
103 | test 5 = $(commit_subject my-side@{U}@{1}) | |
28fb8438 JS |
104 | ' |
105 | ||
106 | test_expect_success '@{u} without specifying branch fails on a detached HEAD' ' | |
107 | git checkout HEAD^0 && | |
244ea1b5 ÆAB |
108 | test_must_fail git rev-parse @{u} && |
109 | test_must_fail git rev-parse @{U} | |
28fb8438 JS |
110 | ' |
111 | ||
69add8e6 JH |
112 | test_expect_success 'checkout -b new my-side@{u} forks from the same' ' |
113 | ( | |
114 | cd clone && | |
115 | git checkout -b new my-side@{u} && | |
116 | git rev-parse --symbolic-full-name my-side@{u} >expect && | |
117 | git rev-parse --symbolic-full-name new@{u} >actual && | |
118 | test_cmp expect actual | |
119 | ) | |
120 | ' | |
121 | ||
ae0ba8e2 | 122 | test_expect_success 'merge my-side@{u} records the correct name' ' |
69add8e6 | 123 | ( |
83279748 ES |
124 | cd clone && |
125 | git checkout master && | |
126 | test_might_fail git branch -D new && | |
69add8e6 JH |
127 | git branch -t new my-side@{u} && |
128 | git merge -s ours new@{u} && | |
ad2f7255 | 129 | git show -s --pretty=tformat:%s >actual && |
bd482d6e | 130 | echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect && |
69add8e6 JH |
131 | test_cmp expect actual |
132 | ) | |
133 | ' | |
134 | ||
ae0ba8e2 | 135 | test_expect_success 'branch -d other@{u}' ' |
69add8e6 JH |
136 | git checkout -t -b other master && |
137 | git branch -d @{u} && | |
138 | git for-each-ref refs/heads/master >actual && | |
d3c6751b | 139 | test_must_be_empty actual |
69add8e6 JH |
140 | ' |
141 | ||
ae0ba8e2 | 142 | test_expect_success 'checkout other@{u}' ' |
69add8e6 JH |
143 | git branch -f master HEAD && |
144 | git checkout -t -b another master && | |
145 | git checkout @{u} && | |
146 | git symbolic-ref HEAD >actual && | |
147 | echo refs/heads/master >expect && | |
148 | test_cmp expect actual | |
149 | ' | |
150 | ||
1b4aee94 ZJS |
151 | test_expect_success 'branch@{u} works when tracking a local branch' ' |
152 | test refs/heads/master = "$(full_name local-master@{u})" | |
153 | ' | |
154 | ||
155 | test_expect_success 'branch@{u} error message when no upstream' ' | |
156 | cat >expect <<-EOF && | |
bd482d6e | 157 | fatal: no upstream configured for branch ${SQ}non-tracking${SQ} |
1b4aee94 | 158 | EOF |
c3a44562 SG |
159 | error_message non-tracking@{u} && |
160 | test_i18ncmp expect error | |
1b4aee94 ZJS |
161 | ' |
162 | ||
163 | test_expect_success '@{u} error message when no upstream' ' | |
164 | cat >expect <<-EOF && | |
bd482d6e | 165 | fatal: no upstream configured for branch ${SQ}master${SQ} |
1b4aee94 ZJS |
166 | EOF |
167 | test_must_fail git rev-parse --verify @{u} 2>actual && | |
64720288 | 168 | test_i18ncmp expect actual |
1b4aee94 ZJS |
169 | ' |
170 | ||
171 | test_expect_success 'branch@{u} error message with misspelt branch' ' | |
172 | cat >expect <<-EOF && | |
bd482d6e | 173 | fatal: no such branch: ${SQ}no-such-branch${SQ} |
1b4aee94 | 174 | EOF |
c3a44562 SG |
175 | error_message no-such-branch@{u} && |
176 | test_i18ncmp expect error | |
1b4aee94 ZJS |
177 | ' |
178 | ||
179 | test_expect_success '@{u} error message when not on a branch' ' | |
180 | cat >expect <<-EOF && | |
17bf4ff3 | 181 | fatal: HEAD does not point to a branch |
1b4aee94 ZJS |
182 | EOF |
183 | git checkout HEAD^0 && | |
184 | test_must_fail git rev-parse --verify @{u} 2>actual && | |
64720288 | 185 | test_i18ncmp expect actual |
1b4aee94 ZJS |
186 | ' |
187 | ||
188 | test_expect_success 'branch@{u} error message if upstream branch not fetched' ' | |
189 | cat >expect <<-EOF && | |
bd482d6e | 190 | fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch |
1b4aee94 | 191 | EOF |
c3a44562 SG |
192 | error_message bad-upstream@{u} && |
193 | test_i18ncmp expect error | |
1b4aee94 ZJS |
194 | ' |
195 | ||
196 | test_expect_success 'pull works when tracking a local branch' ' | |
197 | ( | |
198 | cd clone && | |
199 | git checkout local-master && | |
200 | git pull | |
201 | ) | |
202 | ' | |
203 | ||
204 | # makes sense if the previous one succeeded | |
205 | test_expect_success '@{u} works when tracking a local branch' ' | |
206 | test refs/heads/master = "$(full_name @{u})" | |
207 | ' | |
208 | ||
60e0dc0b | 209 | commit=$(git rev-parse HEAD) |
105e4733 | 210 | cat >expect <<EOF |
60e0dc0b | 211 | commit $commit |
105e4733 JH |
212 | Reflog: master@{0} (C O Mitter <committer@example.com>) |
213 | Reflog message: branch: Created from HEAD | |
214 | Author: A U Thor <author@example.com> | |
215 | Date: Thu Apr 7 15:15:13 2005 -0700 | |
216 | ||
217 | 3 | |
218 | EOF | |
219 | test_expect_success 'log -g other@{u}' ' | |
220 | git log -1 -g other@{u} >actual && | |
221 | test_cmp expect actual | |
222 | ' | |
223 | ||
224 | cat >expect <<EOF | |
60e0dc0b | 225 | commit $commit |
105e4733 JH |
226 | Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>) |
227 | Reflog message: branch: Created from HEAD | |
228 | Author: A U Thor <author@example.com> | |
229 | Date: Thu Apr 7 15:15:13 2005 -0700 | |
230 | ||
231 | 3 | |
232 | EOF | |
233 | ||
234 | test_expect_success 'log -g other@{u}@{now}' ' | |
235 | git log -1 -g other@{u}@{now} >actual && | |
236 | test_cmp expect actual | |
237 | ' | |
238 | ||
3f6eb30f JK |
239 | test_expect_success '@{reflog}-parsing does not look beyond colon' ' |
240 | echo content >@{yesterday} && | |
241 | git add @{yesterday} && | |
242 | git commit -m "funny reflog file" && | |
243 | git hash-object @{yesterday} >expect && | |
244 | git rev-parse HEAD:@{yesterday} >actual | |
245 | ' | |
246 | ||
247 | test_expect_success '@{upstream}-parsing does not look beyond colon' ' | |
248 | echo content >@{upstream} && | |
249 | git add @{upstream} && | |
250 | git commit -m "funny upstream file" && | |
251 | git hash-object @{upstream} >expect && | |
252 | git rev-parse HEAD:@{upstream} >actual | |
253 | ' | |
254 | ||
28fb8438 | 255 | test_done |