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