Merge branch 'bc/clone-empty-repo-via-protocol-v0'
[alt-git.git] / t / t1507-rev-parse-upstream.sh
blobcb9ef7e329eb06a693ead9ab747f9efd37021c94
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-lib.sh
11 test_expect_success 'setup' '
13 test_commit 1 &&
14 git checkout -b side &&
15 test_commit 2 &&
16 git checkout main &&
17 git clone . clone &&
18 test_commit 3 &&
19 (cd clone &&
20 test_commit 4 &&
21 git branch --track my-side origin/side &&
22 git branch --track local-main main &&
23 git branch --track fun@ny origin/side &&
24 git branch --track @funny origin/side &&
25 git branch --track funny@ origin/side &&
26 git remote add -t main main-only .. &&
27 git fetch main-only &&
28 git branch bad-upstream &&
29 git config branch.bad-upstream.remote main-only &&
30 git config branch.bad-upstream.merge refs/heads/side
34 commit_subject () {
35 (cd clone &&
36 git show -s --pretty=tformat:%s "$@")
39 error_message () {
40 (cd clone &&
41 test_must_fail git rev-parse --verify "$@" 2>../error)
44 test_expect_success '@{upstream} resolves to correct full name' '
45 echo refs/remotes/origin/main >expect &&
46 git -C clone rev-parse --symbolic-full-name @{upstream} >actual &&
47 test_cmp expect actual &&
48 git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual &&
49 test_cmp expect actual &&
50 git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual &&
51 test_cmp expect actual
54 test_expect_success '@{u} resolves to correct full name' '
55 echo refs/remotes/origin/main >expect &&
56 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
57 test_cmp expect actual &&
58 git -C clone rev-parse --symbolic-full-name @{U} >actual &&
59 test_cmp expect actual
62 test_expect_success 'my-side@{upstream} resolves to correct full name' '
63 echo refs/remotes/origin/side >expect &&
64 git -C clone rev-parse --symbolic-full-name my-side@{u} >actual &&
65 test_cmp expect actual
68 test_expect_success 'upstream of branch with @ in middle' '
69 git -C clone rev-parse --symbolic-full-name fun@ny@{u} >actual &&
70 echo refs/remotes/origin/side >expect &&
71 test_cmp expect actual &&
72 git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual &&
73 test_cmp expect actual
76 test_expect_success 'upstream of branch with @ at start' '
77 git -C clone rev-parse --symbolic-full-name @funny@{u} >actual &&
78 echo refs/remotes/origin/side >expect &&
79 test_cmp expect actual
82 test_expect_success 'upstream of branch with @ at end' '
83 git -C clone rev-parse --symbolic-full-name funny@@{u} >actual &&
84 echo refs/remotes/origin/side >expect &&
85 test_cmp expect actual
88 test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
89 test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream}
92 test_expect_success 'my-side@{u} resolves to correct commit' '
93 git checkout side &&
94 test_commit 5 &&
95 (cd clone && git fetch) &&
96 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 &&
101 test_cmp expect actual
104 test_expect_success 'not-tracking@{u} fails' '
105 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} &&
106 (cd clone && git checkout --no-track -b non-tracking) &&
107 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u}
110 test_expect_success '<branch>@{u}@{1} resolves correctly' '
111 test_commit 6 &&
112 (cd clone && git fetch) &&
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
120 test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
121 git checkout HEAD^0 &&
122 test_must_fail git rev-parse @{u} &&
123 test_must_fail git rev-parse @{U}
126 test_expect_success 'checkout -b new my-side@{u} forks from the same' '
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
136 test_expect_success 'merge my-side@{u} records the correct name' '
138 cd clone &&
139 git checkout main &&
140 test_might_fail git branch -D new &&
141 git branch -t new my-side@{u} &&
142 git merge -s ours new@{u} &&
143 git show -s --pretty=tformat:%s >actual &&
144 echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect &&
145 test_cmp expect actual
149 test_expect_success 'branch -d other@{u}' '
150 git checkout -t -b other main &&
151 git branch -d @{u} &&
152 git for-each-ref refs/heads/main >actual &&
153 test_must_be_empty actual
156 test_expect_success 'checkout other@{u}' '
157 git branch -f main HEAD &&
158 git checkout -t -b another main &&
159 git checkout @{u} &&
160 git symbolic-ref HEAD >actual &&
161 echo refs/heads/main >expect &&
162 test_cmp expect actual
165 test_expect_success 'branch@{u} works when tracking a local branch' '
166 echo refs/heads/main >expect &&
167 git -C clone rev-parse --symbolic-full-name local-main@{u} >actual &&
168 test_cmp expect actual
171 test_expect_success 'branch@{u} error message when no upstream' '
172 cat >expect <<-EOF &&
173 fatal: no upstream configured for branch ${SQ}non-tracking${SQ}
175 error_message non-tracking@{u} &&
176 test_cmp expect error
179 test_expect_success '@{u} error message when no upstream' '
180 cat >expect <<-EOF &&
181 fatal: no upstream configured for branch ${SQ}main${SQ}
183 test_must_fail git rev-parse --verify @{u} 2>actual &&
184 test_cmp expect actual
187 test_expect_success '@{u} silent error when no upstream' '
188 test_must_fail git rev-parse --verify --quiet @{u} 2>actual &&
189 test_must_be_empty actual
192 test_expect_success 'branch@{u} error message with misspelt branch' '
193 cat >expect <<-EOF &&
194 fatal: no such branch: ${SQ}no-such-branch${SQ}
196 error_message no-such-branch@{u} &&
197 test_cmp expect error
200 test_expect_success '@{u} error message when not on a branch' '
201 cat >expect <<-EOF &&
202 fatal: HEAD does not point to a branch
204 git checkout HEAD^0 &&
205 test_must_fail git rev-parse --verify @{u} 2>actual &&
206 test_cmp expect actual
209 test_expect_success 'branch@{u} error message if upstream branch not fetched' '
210 cat >expect <<-EOF &&
211 fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch
213 error_message bad-upstream@{u} &&
214 test_cmp expect error
217 test_expect_success 'pull works when tracking a local branch' '
219 cd clone &&
220 git checkout local-main &&
221 git pull
225 # makes sense if the previous one succeeded
226 test_expect_success '@{u} works when tracking a local branch' '
227 echo refs/heads/main >expect &&
228 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
229 test_cmp expect actual
232 test_expect_success 'log -g other@{u}' '
233 commit=$(git rev-parse HEAD) &&
234 cat >expect <<-EOF &&
235 commit $commit
236 Reflog: main@{0} (C O Mitter <committer@example.com>)
237 Reflog message: branch: Created from HEAD
238 Author: A U Thor <author@example.com>
239 Date: Thu Apr 7 15:15:13 2005 -0700
243 git log -1 -g other@{u} >actual &&
244 test_cmp expect actual
247 test_expect_success 'log -g other@{u}@{now}' '
248 commit=$(git rev-parse HEAD) &&
249 cat >expect <<-EOF &&
250 commit $commit
251 Reflog: main@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
252 Reflog message: branch: Created from HEAD
253 Author: A U Thor <author@example.com>
254 Date: Thu Apr 7 15:15:13 2005 -0700
258 git log -1 -g other@{u}@{now} >actual &&
259 test_cmp expect actual
262 test_expect_success '@{reflog}-parsing does not look beyond colon' '
263 echo content >@{yesterday} &&
264 git add @{yesterday} &&
265 git commit -m "funny reflog file" &&
266 git hash-object @{yesterday} >expect &&
267 git rev-parse HEAD:@{yesterday} >actual &&
268 test_cmp expect actual
271 test_expect_success '@{upstream}-parsing does not look beyond colon' '
272 echo content >@{upstream} &&
273 git add @{upstream} &&
274 git commit -m "funny upstream file" &&
275 git hash-object @{upstream} >expect &&
276 git rev-parse HEAD:@{upstream} >actual &&
277 test_cmp expect actual
280 test_done