Start the 2.46 cycle
[git.git] / t / t1507-rev-parse-upstream.sh
blobb9af6b3ac035a04858ae0c7e0963166af665bd81
1 #!/bin/sh
3 test_description='test <branch>@{upstream} syntax'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
12 test_expect_success 'setup' '
14 test_commit 1 &&
15 git checkout -b side &&
16 test_commit 2 &&
17 git checkout main &&
18 git clone . clone &&
19 test_commit 3 &&
20 (cd clone &&
21 test_commit 4 &&
22 git branch --track my-side origin/side &&
23 git branch --track local-main main &&
24 git branch --track fun@ny origin/side &&
25 git branch --track @funny origin/side &&
26 git branch --track funny@ origin/side &&
27 git remote add -t main main-only .. &&
28 git fetch main-only &&
29 git branch bad-upstream &&
30 git config branch.bad-upstream.remote main-only &&
31 git config branch.bad-upstream.merge refs/heads/side
35 commit_subject () {
36 (cd clone &&
37 git show -s --pretty=tformat:%s "$@")
40 error_message () {
41 (cd clone &&
42 test_must_fail git rev-parse --verify "$@" 2>../error)
45 test_expect_success '@{upstream} resolves to correct full name' '
46 echo refs/remotes/origin/main >expect &&
47 git -C clone rev-parse --symbolic-full-name @{upstream} >actual &&
48 test_cmp expect actual &&
49 git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual &&
50 test_cmp expect actual &&
51 git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual &&
52 test_cmp expect actual
55 test_expect_success '@{u} resolves to correct full name' '
56 echo refs/remotes/origin/main >expect &&
57 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
58 test_cmp expect actual &&
59 git -C clone rev-parse --symbolic-full-name @{U} >actual &&
60 test_cmp expect actual
63 test_expect_success 'my-side@{upstream} resolves to correct full name' '
64 echo refs/remotes/origin/side >expect &&
65 git -C clone rev-parse --symbolic-full-name my-side@{u} >actual &&
66 test_cmp expect actual
69 test_expect_success 'upstream of branch with @ in middle' '
70 git -C clone rev-parse --symbolic-full-name fun@ny@{u} >actual &&
71 echo refs/remotes/origin/side >expect &&
72 test_cmp expect actual &&
73 git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual &&
74 test_cmp expect actual
77 test_expect_success 'upstream of branch with @ at start' '
78 git -C clone rev-parse --symbolic-full-name @funny@{u} >actual &&
79 echo refs/remotes/origin/side >expect &&
80 test_cmp expect actual
83 test_expect_success 'upstream of branch with @ at end' '
84 git -C clone rev-parse --symbolic-full-name funny@@{u} >actual &&
85 echo refs/remotes/origin/side >expect &&
86 test_cmp expect actual
89 test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
90 test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream}
93 test_expect_success 'my-side@{u} resolves to correct commit' '
94 git checkout side &&
95 test_commit 5 &&
96 (cd clone && git fetch) &&
97 echo 2 >expect &&
98 commit_subject my-side >actual &&
99 test_cmp expect actual &&
100 echo 5 >expect &&
101 commit_subject my-side@{u} >actual &&
102 test_cmp expect actual
105 test_expect_success 'not-tracking@{u} fails' '
106 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} &&
107 (cd clone && git checkout --no-track -b non-tracking) &&
108 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u}
111 test_expect_success '<branch>@{u}@{1} resolves correctly' '
112 test_commit 6 &&
113 (cd clone && git fetch) &&
114 echo 5 >expect &&
115 commit_subject my-side@{u}@{1} >actual &&
116 test_cmp expect actual &&
117 commit_subject my-side@{U}@{1} >actual &&
118 test_cmp expect actual
121 test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
122 git checkout HEAD^0 &&
123 test_must_fail git rev-parse @{u} &&
124 test_must_fail git rev-parse @{U}
127 test_expect_success 'checkout -b new my-side@{u} forks from the same' '
129 cd clone &&
130 git checkout -b new my-side@{u} &&
131 git rev-parse --symbolic-full-name my-side@{u} >expect &&
132 git rev-parse --symbolic-full-name new@{u} >actual &&
133 test_cmp expect actual
137 test_expect_success 'merge my-side@{u} records the correct name' '
139 cd clone &&
140 git checkout main &&
141 test_might_fail git branch -D new &&
142 git branch -t new my-side@{u} &&
143 git merge -s ours new@{u} &&
144 git show -s --pretty=tformat:%s >actual &&
145 echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect &&
146 test_cmp expect actual
150 test_expect_success 'branch -d other@{u}' '
151 git checkout -t -b other main &&
152 git branch -d @{u} &&
153 git for-each-ref refs/heads/main >actual &&
154 test_must_be_empty actual
157 test_expect_success 'checkout other@{u}' '
158 git branch -f main HEAD &&
159 git checkout -t -b another main &&
160 git checkout @{u} &&
161 git symbolic-ref HEAD >actual &&
162 echo refs/heads/main >expect &&
163 test_cmp expect actual
166 test_expect_success 'branch@{u} works when tracking a local branch' '
167 echo refs/heads/main >expect &&
168 git -C clone rev-parse --symbolic-full-name local-main@{u} >actual &&
169 test_cmp expect actual
172 test_expect_success 'branch@{u} error message when no upstream' '
173 cat >expect <<-EOF &&
174 fatal: no upstream configured for branch ${SQ}non-tracking${SQ}
176 error_message non-tracking@{u} &&
177 test_cmp expect error
180 test_expect_success '@{u} error message when no upstream' '
181 cat >expect <<-EOF &&
182 fatal: no upstream configured for branch ${SQ}main${SQ}
184 test_must_fail git rev-parse --verify @{u} 2>actual &&
185 test_cmp expect actual
188 test_expect_success '@{u} silent error when no upstream' '
189 test_must_fail git rev-parse --verify --quiet @{u} 2>actual &&
190 test_must_be_empty actual
193 test_expect_success 'branch@{u} error message with misspelt branch' '
194 cat >expect <<-EOF &&
195 fatal: no such branch: ${SQ}no-such-branch${SQ}
197 error_message no-such-branch@{u} &&
198 test_cmp expect error
201 test_expect_success '@{u} error message when not on a branch' '
202 cat >expect <<-EOF &&
203 fatal: HEAD does not point to a branch
205 git checkout HEAD^0 &&
206 test_must_fail git rev-parse --verify @{u} 2>actual &&
207 test_cmp expect actual
210 test_expect_success 'branch@{u} error message if upstream branch not fetched' '
211 cat >expect <<-EOF &&
212 fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch
214 error_message bad-upstream@{u} &&
215 test_cmp expect error
218 test_expect_success 'pull works when tracking a local branch' '
220 cd clone &&
221 git checkout local-main &&
222 git pull
226 # makes sense if the previous one succeeded
227 test_expect_success '@{u} works when tracking a local branch' '
228 echo refs/heads/main >expect &&
229 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
230 test_cmp expect actual
233 test_expect_success 'log -g other@{u}' '
234 commit=$(git rev-parse HEAD) &&
235 cat >expect <<-EOF &&
236 commit $commit
237 Reflog: main@{0} (C O Mitter <committer@example.com>)
238 Reflog message: branch: Created from HEAD
239 Author: A U Thor <author@example.com>
240 Date: Thu Apr 7 15:15:13 2005 -0700
244 git log -1 -g other@{u} >actual &&
245 test_cmp expect actual
248 test_expect_success 'log -g other@{u}@{now}' '
249 commit=$(git rev-parse HEAD) &&
250 cat >expect <<-EOF &&
251 commit $commit
252 Reflog: main@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
253 Reflog message: branch: Created from HEAD
254 Author: A U Thor <author@example.com>
255 Date: Thu Apr 7 15:15:13 2005 -0700
259 git log -1 -g other@{u}@{now} >actual &&
260 test_cmp expect actual
263 test_expect_success '@{reflog}-parsing does not look beyond colon' '
264 echo content >@{yesterday} &&
265 git add @{yesterday} &&
266 git commit -m "funny reflog file" &&
267 git hash-object @{yesterday} >expect &&
268 git rev-parse HEAD:@{yesterday} >actual &&
269 test_cmp expect actual
272 test_expect_success '@{upstream}-parsing does not look beyond colon' '
273 echo content >@{upstream} &&
274 git add @{upstream} &&
275 git commit -m "funny upstream file" &&
276 git hash-object @{upstream} >expect &&
277 git rev-parse HEAD:@{upstream} >actual &&
278 test_cmp expect actual
281 test_done