blob: dfc0d96d8a8a834743781a08a8ea1c5f9dd63bda [file] [log] [blame]
Johannes Schindelin28fb8432009-09-10 17:25:57 +02001#!/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 &&
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +020018 git branch --track my-side origin/side &&
19 git branch --track local-master master &&
Jeff King9892d5d2014-01-15 03:40:46 -050020 git branch --track fun@ny origin/side &&
21 git branch --track @funny origin/side &&
22 git branch --track funny@ origin/side &&
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +020023 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 )
Johannes Schindelin28fb8432009-09-10 17:25:57 +020029'
30
Johannes Schindelin28fb8432009-09-10 17:25:57 +020031commit_subject () {
32 (cd clone &&
Denton Liu5236fce2019-12-20 10:16:00 -080033 git show -s --pretty=tformat:%s "$@")
Johannes Schindelin28fb8432009-09-10 17:25:57 +020034}
35
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +020036error_message () {
37 (cd clone &&
SZEDER Gáborc3a44562018-02-24 00:39:43 +010038 test_must_fail git rev-parse --verify "$@" 2>../error)
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +020039}
40
Johannes Schindelin28fb8432009-09-10 17:25:57 +020041test_expect_success '@{upstream} resolves to correct full name' '
Denton Liu5236fce2019-12-20 10:16:00 -080042 echo refs/remotes/origin/master >expect &&
Denton Liub4417172019-12-20 10:16:02 -080043 git -C clone rev-parse --symbolic-full-name @{upstream} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080044 test_cmp expect actual &&
Denton Liub4417172019-12-20 10:16:02 -080045 git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080046 test_cmp expect actual &&
Denton Liub4417172019-12-20 10:16:02 -080047 git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080048 test_cmp expect actual
Johannes Schindelin28fb8432009-09-10 17:25:57 +020049'
50
51test_expect_success '@{u} resolves to correct full name' '
Denton Liu5236fce2019-12-20 10:16:00 -080052 echo refs/remotes/origin/master >expect &&
Denton Liub4417172019-12-20 10:16:02 -080053 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080054 test_cmp expect actual &&
Denton Liub4417172019-12-20 10:16:02 -080055 git -C clone rev-parse --symbolic-full-name @{U} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080056 test_cmp expect actual
Johannes Schindelin28fb8432009-09-10 17:25:57 +020057'
58
59test_expect_success 'my-side@{upstream} resolves to correct full name' '
Denton Liu5236fce2019-12-20 10:16:00 -080060 echo refs/remotes/origin/side >expect &&
Denton Liub4417172019-12-20 10:16:02 -080061 git -C clone rev-parse --symbolic-full-name my-side@{u} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080062 test_cmp expect actual
Johannes Schindelin28fb8432009-09-10 17:25:57 +020063'
64
Jeff King9892d5d2014-01-15 03:40:46 -050065test_expect_success 'upstream of branch with @ in middle' '
Denton Liub4417172019-12-20 10:16:02 -080066 git -C clone rev-parse --symbolic-full-name fun@ny@{u} >actual &&
Jeff King9892d5d2014-01-15 03:40:46 -050067 echo refs/remotes/origin/side >expect &&
Ævar Arnfjörð Bjarmason244ea1b2017-03-27 11:16:55 +000068 test_cmp expect actual &&
Denton Liub4417172019-12-20 10:16:02 -080069 git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual &&
Jeff King9892d5d2014-01-15 03:40:46 -050070 test_cmp expect actual
71'
72
73test_expect_success 'upstream of branch with @ at start' '
Denton Liub4417172019-12-20 10:16:02 -080074 git -C clone rev-parse --symbolic-full-name @funny@{u} >actual &&
Jeff King9892d5d2014-01-15 03:40:46 -050075 echo refs/remotes/origin/side >expect &&
76 test_cmp expect actual
77'
78
79test_expect_success 'upstream of branch with @ at end' '
Denton Liub4417172019-12-20 10:16:02 -080080 git -C clone rev-parse --symbolic-full-name funny@@{u} >actual &&
Jeff King9892d5d2014-01-15 03:40:46 -050081 echo refs/remotes/origin/side >expect &&
82 test_cmp expect actual
83'
84
Kacper Kornet617cf932013-03-17 23:17:09 +010085test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
Denton Liub4417172019-12-20 10:16:02 -080086 test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream}
Kacper Kornet617cf932013-03-17 23:17:09 +010087'
88
Johannes Schindelin28fb8432009-09-10 17:25:57 +020089test_expect_success 'my-side@{u} resolves to correct commit' '
90 git checkout side &&
91 test_commit 5 &&
92 (cd clone && git fetch) &&
Denton Liu5236fce2019-12-20 10:16:00 -080093 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
Johannes Schindelin28fb8432009-09-10 17:25:57 +020098'
99
100test_expect_success 'not-tracking@{u} fails' '
Denton Liub4417172019-12-20 10:16:02 -0800101 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} &&
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200102 (cd clone && git checkout --no-track -b non-tracking) &&
Denton Liub4417172019-12-20 10:16:02 -0800103 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u}
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200104'
105
106test_expect_success '<branch>@{u}@{1} resolves correctly' '
107 test_commit 6 &&
108 (cd clone && git fetch) &&
Denton Liu5236fce2019-12-20 10:16:00 -0800109 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
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200114'
115
116test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
117 git checkout HEAD^0 &&
Ævar Arnfjörð Bjarmason244ea1b2017-03-27 11:16:55 +0000118 test_must_fail git rev-parse @{u} &&
119 test_must_fail git rev-parse @{U}
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200120'
121
Junio C Hamano69add8e2010-01-20 01:08:48 -0800122test_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
Junio C Hamanoae0ba8e2010-01-19 23:17:11 -0800132test_expect_success 'merge my-side@{u} records the correct name' '
Junio C Hamano69add8e2010-01-20 01:08:48 -0800133(
Eric Sunshine83279742018-07-01 20:23:41 -0400134 cd clone &&
135 git checkout master &&
136 test_might_fail git branch -D new &&
Junio C Hamano69add8e2010-01-20 01:08:48 -0800137 git branch -t new my-side@{u} &&
138 git merge -s ours new@{u} &&
Max Kirillovad2f7252014-05-15 01:12:45 +0300139 git show -s --pretty=tformat:%s >actual &&
Junio C Hamano21531922020-07-30 10:06:42 -0700140 echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect &&
Junio C Hamano69add8e2010-01-20 01:08:48 -0800141 test_cmp expect actual
142)
143'
144
Junio C Hamanoae0ba8e2010-01-19 23:17:11 -0800145test_expect_success 'branch -d other@{u}' '
Junio C Hamano69add8e2010-01-20 01:08:48 -0800146 git checkout -t -b other master &&
147 git branch -d @{u} &&
148 git for-each-ref refs/heads/master >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000149 test_must_be_empty actual
Junio C Hamano69add8e2010-01-20 01:08:48 -0800150'
151
Junio C Hamanoae0ba8e2010-01-19 23:17:11 -0800152test_expect_success 'checkout other@{u}' '
Junio C Hamano69add8e2010-01-20 01:08:48 -0800153 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
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200161test_expect_success 'branch@{u} works when tracking a local branch' '
Denton Liu5236fce2019-12-20 10:16:00 -0800162 echo refs/heads/master >expect &&
Denton Liub4417172019-12-20 10:16:02 -0800163 git -C clone rev-parse --symbolic-full-name local-master@{u} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -0800164 test_cmp expect actual
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200165'
166
167test_expect_success 'branch@{u} error message when no upstream' '
168 cat >expect <<-EOF &&
Denton Liubd482d62019-09-05 15:10:05 -0700169 fatal: no upstream configured for branch ${SQ}non-tracking${SQ}
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200170 EOF
SZEDER Gáborc3a44562018-02-24 00:39:43 +0100171 error_message non-tracking@{u} &&
172 test_i18ncmp expect error
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200173'
174
175test_expect_success '@{u} error message when no upstream' '
176 cat >expect <<-EOF &&
Denton Liubd482d62019-09-05 15:10:05 -0700177 fatal: no upstream configured for branch ${SQ}master${SQ}
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200178 EOF
179 test_must_fail git rev-parse --verify @{u} 2>actual &&
Zbigniew Jędrzejewski-Szmek64720282012-04-14 09:54:35 +0200180 test_i18ncmp expect actual
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200181'
182
183test_expect_success 'branch@{u} error message with misspelt branch' '
184 cat >expect <<-EOF &&
Denton Liubd482d62019-09-05 15:10:05 -0700185 fatal: no such branch: ${SQ}no-such-branch${SQ}
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200186 EOF
SZEDER Gáborc3a44562018-02-24 00:39:43 +0100187 error_message no-such-branch@{u} &&
188 test_i18ncmp expect error
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200189'
190
191test_expect_success '@{u} error message when not on a branch' '
192 cat >expect <<-EOF &&
Ramkumar Ramachandra17bf4ff2013-05-22 16:09:54 +0530193 fatal: HEAD does not point to a branch
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200194 EOF
195 git checkout HEAD^0 &&
196 test_must_fail git rev-parse --verify @{u} 2>actual &&
Zbigniew Jędrzejewski-Szmek64720282012-04-14 09:54:35 +0200197 test_i18ncmp expect actual
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200198'
199
200test_expect_success 'branch@{u} error message if upstream branch not fetched' '
201 cat >expect <<-EOF &&
Denton Liubd482d62019-09-05 15:10:05 -0700202 fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200203 EOF
SZEDER Gáborc3a44562018-02-24 00:39:43 +0100204 error_message bad-upstream@{u} &&
205 test_i18ncmp expect error
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200206'
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' '
Denton Liu5236fce2019-12-20 10:16:00 -0800218 echo refs/heads/master >expect &&
Denton Liub4417172019-12-20 10:16:02 -0800219 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -0800220 test_cmp expect actual
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200221'
222
Junio C Hamano105e4732010-01-26 13:48:28 -0800223test_expect_success 'log -g other@{u}' '
Denton Liu9291e632019-12-20 10:16:01 -0800224 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
Junio C Hamano105e4732010-01-26 13:48:28 -0800234 git log -1 -g other@{u} >actual &&
235 test_cmp expect actual
236'
237
Junio C Hamano105e4732010-01-26 13:48:28 -0800238test_expect_success 'log -g other@{u}@{now}' '
Denton Liu9291e632019-12-20 10:16:01 -0800239 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
Junio C Hamano105e4732010-01-26 13:48:28 -0800249 git log -1 -g other@{u}@{now} >actual &&
250 test_cmp expect actual
251'
252
Jeff King3f6eb302014-01-15 03:37:23 -0500253test_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
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200269test_done