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