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