blob: c34714ffe3fbe5545da1d05b9a74cfc6113e43dd [file] [log] [blame]
Johannes Schindelin28fb8432009-09-10 17:25:57 +02001#!/bin/sh
2
3test_description='test <branch>@{upstream} syntax'
4
Johannes Schindelin06d53142020-11-18 23:44:21 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Johannes Schindelin28fb8432009-09-10 17:25:57 +02008. ./test-lib.sh
9
10
11test_expect_success 'setup' '
12
13 test_commit 1 &&
14 git checkout -b side &&
15 test_commit 2 &&
Johannes Schindelin06d53142020-11-18 23:44:21 +000016 git checkout main &&
Johannes Schindelin28fb8432009-09-10 17:25:57 +020017 git clone . clone &&
18 test_commit 3 &&
19 (cd clone &&
20 test_commit 4 &&
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +020021 git branch --track my-side origin/side &&
Johannes Schindelin06d53142020-11-18 23:44:21 +000022 git branch --track local-main main &&
Jeff King9892d5d2014-01-15 03:40:46 -050023 git branch --track fun@ny origin/side &&
24 git branch --track @funny origin/side &&
25 git branch --track funny@ origin/side &&
Johannes Schindelin06d53142020-11-18 23:44:21 +000026 git remote add -t main main-only .. &&
27 git fetch main-only &&
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +020028 git branch bad-upstream &&
Johannes Schindelin06d53142020-11-18 23:44:21 +000029 git config branch.bad-upstream.remote main-only &&
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +020030 git config branch.bad-upstream.merge refs/heads/side
31 )
Johannes Schindelin28fb8432009-09-10 17:25:57 +020032'
33
Johannes Schindelin28fb8432009-09-10 17:25:57 +020034commit_subject () {
35 (cd clone &&
Denton Liu5236fce2019-12-20 10:16:00 -080036 git show -s --pretty=tformat:%s "$@")
Johannes Schindelin28fb8432009-09-10 17:25:57 +020037}
38
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +020039error_message () {
40 (cd clone &&
SZEDER Gáborc3a44562018-02-24 00:39:43 +010041 test_must_fail git rev-parse --verify "$@" 2>../error)
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +020042}
43
Johannes Schindelin28fb8432009-09-10 17:25:57 +020044test_expect_success '@{upstream} resolves to correct full name' '
Johannes Schindelin06d53142020-11-18 23:44:21 +000045 echo refs/remotes/origin/main >expect &&
Denton Liub4417172019-12-20 10:16:02 -080046 git -C clone rev-parse --symbolic-full-name @{upstream} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080047 test_cmp expect actual &&
Denton Liub4417172019-12-20 10:16:02 -080048 git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080049 test_cmp expect actual &&
Denton Liub4417172019-12-20 10:16:02 -080050 git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080051 test_cmp expect actual
Johannes Schindelin28fb8432009-09-10 17:25:57 +020052'
53
54test_expect_success '@{u} resolves to correct full name' '
Johannes Schindelin06d53142020-11-18 23:44:21 +000055 echo refs/remotes/origin/main >expect &&
Denton Liub4417172019-12-20 10:16:02 -080056 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080057 test_cmp expect actual &&
Denton Liub4417172019-12-20 10:16:02 -080058 git -C clone rev-parse --symbolic-full-name @{U} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080059 test_cmp expect actual
Johannes Schindelin28fb8432009-09-10 17:25:57 +020060'
61
62test_expect_success 'my-side@{upstream} resolves to correct full name' '
Denton Liu5236fce2019-12-20 10:16:00 -080063 echo refs/remotes/origin/side >expect &&
Denton Liub4417172019-12-20 10:16:02 -080064 git -C clone rev-parse --symbolic-full-name my-side@{u} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -080065 test_cmp expect actual
Johannes Schindelin28fb8432009-09-10 17:25:57 +020066'
67
Jeff King9892d5d2014-01-15 03:40:46 -050068test_expect_success 'upstream of branch with @ in middle' '
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 echo refs/remotes/origin/side >expect &&
Ævar Arnfjörð Bjarmason244ea1b2017-03-27 11:16:55 +000071 test_cmp expect actual &&
Denton Liub4417172019-12-20 10:16:02 -080072 git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual &&
Jeff King9892d5d2014-01-15 03:40:46 -050073 test_cmp expect actual
74'
75
76test_expect_success 'upstream of branch with @ at start' '
Denton Liub4417172019-12-20 10:16:02 -080077 git -C clone rev-parse --symbolic-full-name @funny@{u} >actual &&
Jeff King9892d5d2014-01-15 03:40:46 -050078 echo refs/remotes/origin/side >expect &&
79 test_cmp expect actual
80'
81
82test_expect_success 'upstream of branch with @ at end' '
Denton Liub4417172019-12-20 10:16:02 -080083 git -C clone rev-parse --symbolic-full-name funny@@{u} >actual &&
Jeff King9892d5d2014-01-15 03:40:46 -050084 echo refs/remotes/origin/side >expect &&
85 test_cmp expect actual
86'
87
Kacper Kornet617cf932013-03-17 23:17:09 +010088test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
Denton Liub4417172019-12-20 10:16:02 -080089 test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream}
Kacper Kornet617cf932013-03-17 23:17:09 +010090'
91
Johannes Schindelin28fb8432009-09-10 17:25:57 +020092test_expect_success 'my-side@{u} resolves to correct commit' '
93 git checkout side &&
94 test_commit 5 &&
95 (cd clone && git fetch) &&
Denton Liu5236fce2019-12-20 10:16:00 -080096 echo 2 >expect &&
97 commit_subject my-side >actual &&
98 test_cmp expect actual &&
99 echo 5 >expect &&
100 commit_subject my-side@{u} >actual
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200101'
102
103test_expect_success 'not-tracking@{u} fails' '
Denton Liub4417172019-12-20 10:16:02 -0800104 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} &&
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200105 (cd clone && git checkout --no-track -b non-tracking) &&
Denton Liub4417172019-12-20 10:16:02 -0800106 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u}
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200107'
108
109test_expect_success '<branch>@{u}@{1} resolves correctly' '
110 test_commit 6 &&
111 (cd clone && git fetch) &&
Denton Liu5236fce2019-12-20 10:16:00 -0800112 echo 5 >expect &&
113 commit_subject my-side@{u}@{1} >actual &&
114 test_cmp expect actual &&
115 commit_subject my-side@{U}@{1} >actual &&
116 test_cmp expect actual
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200117'
118
119test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
120 git checkout HEAD^0 &&
Ævar Arnfjörð Bjarmason244ea1b2017-03-27 11:16:55 +0000121 test_must_fail git rev-parse @{u} &&
122 test_must_fail git rev-parse @{U}
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200123'
124
Junio C Hamano69add8e2010-01-20 01:08:48 -0800125test_expect_success 'checkout -b new my-side@{u} forks from the same' '
126(
127 cd clone &&
128 git checkout -b new my-side@{u} &&
129 git rev-parse --symbolic-full-name my-side@{u} >expect &&
130 git rev-parse --symbolic-full-name new@{u} >actual &&
131 test_cmp expect actual
132)
133'
134
Junio C Hamanoae0ba8e2010-01-19 23:17:11 -0800135test_expect_success 'merge my-side@{u} records the correct name' '
Junio C Hamano69add8e2010-01-20 01:08:48 -0800136(
Eric Sunshine83279742018-07-01 20:23:41 -0400137 cd clone &&
Johannes Schindelin06d53142020-11-18 23:44:21 +0000138 git checkout main &&
Eric Sunshine83279742018-07-01 20:23:41 -0400139 test_might_fail git branch -D new &&
Junio C Hamano69add8e2010-01-20 01:08:48 -0800140 git branch -t new my-side@{u} &&
141 git merge -s ours new@{u} &&
Max Kirillovad2f7252014-05-15 01:12:45 +0300142 git show -s --pretty=tformat:%s >actual &&
Junio C Hamano21531922020-07-30 10:06:42 -0700143 echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect &&
Junio C Hamano69add8e2010-01-20 01:08:48 -0800144 test_cmp expect actual
145)
146'
147
Junio C Hamanoae0ba8e2010-01-19 23:17:11 -0800148test_expect_success 'branch -d other@{u}' '
Johannes Schindelin06d53142020-11-18 23:44:21 +0000149 git checkout -t -b other main &&
Junio C Hamano69add8e2010-01-20 01:08:48 -0800150 git branch -d @{u} &&
Johannes Schindelin06d53142020-11-18 23:44:21 +0000151 git for-each-ref refs/heads/main >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000152 test_must_be_empty actual
Junio C Hamano69add8e2010-01-20 01:08:48 -0800153'
154
Junio C Hamanoae0ba8e2010-01-19 23:17:11 -0800155test_expect_success 'checkout other@{u}' '
Johannes Schindelin06d53142020-11-18 23:44:21 +0000156 git branch -f main HEAD &&
157 git checkout -t -b another main &&
Junio C Hamano69add8e2010-01-20 01:08:48 -0800158 git checkout @{u} &&
159 git symbolic-ref HEAD >actual &&
Johannes Schindelin06d53142020-11-18 23:44:21 +0000160 echo refs/heads/main >expect &&
Junio C Hamano69add8e2010-01-20 01:08:48 -0800161 test_cmp expect actual
162'
163
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200164test_expect_success 'branch@{u} works when tracking a local branch' '
Johannes Schindelin06d53142020-11-18 23:44:21 +0000165 echo refs/heads/main >expect &&
166 git -C clone rev-parse --symbolic-full-name local-main@{u} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -0800167 test_cmp expect actual
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200168'
169
170test_expect_success 'branch@{u} error message when no upstream' '
171 cat >expect <<-EOF &&
Denton Liubd482d62019-09-05 15:10:05 -0700172 fatal: no upstream configured for branch ${SQ}non-tracking${SQ}
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200173 EOF
SZEDER Gáborc3a44562018-02-24 00:39:43 +0100174 error_message non-tracking@{u} &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100175 test_cmp expect error
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200176'
177
178test_expect_success '@{u} error message when no upstream' '
179 cat >expect <<-EOF &&
Johannes Schindelin06d53142020-11-18 23:44:21 +0000180 fatal: no upstream configured for branch ${SQ}main${SQ}
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200181 EOF
182 test_must_fail git rev-parse --verify @{u} 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100183 test_cmp expect actual
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200184'
185
186test_expect_success 'branch@{u} error message with misspelt branch' '
187 cat >expect <<-EOF &&
Denton Liubd482d62019-09-05 15:10:05 -0700188 fatal: no such branch: ${SQ}no-such-branch${SQ}
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200189 EOF
SZEDER Gáborc3a44562018-02-24 00:39:43 +0100190 error_message no-such-branch@{u} &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100191 test_cmp expect error
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200192'
193
194test_expect_success '@{u} error message when not on a branch' '
195 cat >expect <<-EOF &&
Ramkumar Ramachandra17bf4ff2013-05-22 16:09:54 +0530196 fatal: HEAD does not point to a branch
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200197 EOF
198 git checkout HEAD^0 &&
199 test_must_fail git rev-parse --verify @{u} 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100200 test_cmp expect actual
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200201'
202
203test_expect_success 'branch@{u} error message if upstream branch not fetched' '
204 cat >expect <<-EOF &&
Denton Liubd482d62019-09-05 15:10:05 -0700205 fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200206 EOF
SZEDER Gáborc3a44562018-02-24 00:39:43 +0100207 error_message bad-upstream@{u} &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100208 test_cmp expect error
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200209'
210
211test_expect_success 'pull works when tracking a local branch' '
212(
213 cd clone &&
Johannes Schindelin06d53142020-11-18 23:44:21 +0000214 git checkout local-main &&
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200215 git pull
216)
217'
218
219# makes sense if the previous one succeeded
220test_expect_success '@{u} works when tracking a local branch' '
Johannes Schindelin06d53142020-11-18 23:44:21 +0000221 echo refs/heads/main >expect &&
Denton Liub4417172019-12-20 10:16:02 -0800222 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
Denton Liu5236fce2019-12-20 10:16:00 -0800223 test_cmp expect actual
Zbigniew Jędrzejewski-Szmek1b4aee92012-04-14 09:54:31 +0200224'
225
Junio C Hamano105e4732010-01-26 13:48:28 -0800226test_expect_success 'log -g other@{u}' '
Denton Liu9291e632019-12-20 10:16:01 -0800227 commit=$(git rev-parse HEAD) &&
228 cat >expect <<-EOF &&
229 commit $commit
Johannes Schindelin06d53142020-11-18 23:44:21 +0000230 Reflog: main@{0} (C O Mitter <committer@example.com>)
Denton Liu9291e632019-12-20 10:16:01 -0800231 Reflog message: branch: Created from HEAD
232 Author: A U Thor <author@example.com>
233 Date: Thu Apr 7 15:15:13 2005 -0700
234
235 3
236 EOF
Junio C Hamano105e4732010-01-26 13:48:28 -0800237 git log -1 -g other@{u} >actual &&
238 test_cmp expect actual
239'
240
Junio C Hamano105e4732010-01-26 13:48:28 -0800241test_expect_success 'log -g other@{u}@{now}' '
Denton Liu9291e632019-12-20 10:16:01 -0800242 commit=$(git rev-parse HEAD) &&
243 cat >expect <<-EOF &&
244 commit $commit
Johannes Schindelin06d53142020-11-18 23:44:21 +0000245 Reflog: main@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
Denton Liu9291e632019-12-20 10:16:01 -0800246 Reflog message: branch: Created from HEAD
247 Author: A U Thor <author@example.com>
248 Date: Thu Apr 7 15:15:13 2005 -0700
249
250 3
251 EOF
Junio C Hamano105e4732010-01-26 13:48:28 -0800252 git log -1 -g other@{u}@{now} >actual &&
253 test_cmp expect actual
254'
255
Jeff King3f6eb302014-01-15 03:37:23 -0500256test_expect_success '@{reflog}-parsing does not look beyond colon' '
257 echo content >@{yesterday} &&
258 git add @{yesterday} &&
259 git commit -m "funny reflog file" &&
260 git hash-object @{yesterday} >expect &&
261 git rev-parse HEAD:@{yesterday} >actual
262'
263
264test_expect_success '@{upstream}-parsing does not look beyond colon' '
265 echo content >@{upstream} &&
266 git add @{upstream} &&
267 git commit -m "funny upstream file" &&
268 git hash-object @{upstream} >expect &&
269 git rev-parse HEAD:@{upstream} >actual
270'
271
Johannes Schindelin28fb8432009-09-10 17:25:57 +0200272test_done