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