Merge branch '2.29-r2' of github.com:bitigchi/git-po
[alt-git.git] / t / t1507-rev-parse-upstream.sh
blobdfc0d96d8a8a834743781a08a8ea1c5f9dd63bda
1 #!/bin/sh
3 test_description='test <branch>@{upstream} syntax'
5 . ./test-lib.sh
8 test_expect_success 'setup' '
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 &&
18 git branch --track my-side origin/side &&
19 git branch --track local-master master &&
20 git branch --track fun@ny origin/side &&
21 git branch --track @funny origin/side &&
22 git branch --track funny@ origin/side &&
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
31 commit_subject () {
32 (cd clone &&
33 git show -s --pretty=tformat:%s "$@")
36 error_message () {
37 (cd clone &&
38 test_must_fail git rev-parse --verify "$@" 2>../error)
41 test_expect_success '@{upstream} resolves to correct full name' '
42 echo refs/remotes/origin/master >expect &&
43 git -C clone rev-parse --symbolic-full-name @{upstream} >actual &&
44 test_cmp expect actual &&
45 git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual &&
46 test_cmp expect actual &&
47 git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual &&
48 test_cmp expect actual
51 test_expect_success '@{u} resolves to correct full name' '
52 echo refs/remotes/origin/master >expect &&
53 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
54 test_cmp expect actual &&
55 git -C clone rev-parse --symbolic-full-name @{U} >actual &&
56 test_cmp expect actual
59 test_expect_success 'my-side@{upstream} resolves to correct full name' '
60 echo refs/remotes/origin/side >expect &&
61 git -C clone rev-parse --symbolic-full-name my-side@{u} >actual &&
62 test_cmp expect actual
65 test_expect_success 'upstream of branch with @ in middle' '
66 git -C clone rev-parse --symbolic-full-name fun@ny@{u} >actual &&
67 echo refs/remotes/origin/side >expect &&
68 test_cmp expect actual &&
69 git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual &&
70 test_cmp expect actual
73 test_expect_success 'upstream of branch with @ at start' '
74 git -C clone rev-parse --symbolic-full-name @funny@{u} >actual &&
75 echo refs/remotes/origin/side >expect &&
76 test_cmp expect actual
79 test_expect_success 'upstream of branch with @ at end' '
80 git -C clone rev-parse --symbolic-full-name funny@@{u} >actual &&
81 echo refs/remotes/origin/side >expect &&
82 test_cmp expect actual
85 test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
86 test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream}
89 test_expect_success 'my-side@{u} resolves to correct commit' '
90 git checkout side &&
91 test_commit 5 &&
92 (cd clone && git fetch) &&
93 echo 2 >expect &&
94 commit_subject my-side >actual &&
95 test_cmp expect actual &&
96 echo 5 >expect &&
97 commit_subject my-side@{u} >actual
100 test_expect_success 'not-tracking@{u} fails' '
101 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} &&
102 (cd clone && git checkout --no-track -b non-tracking) &&
103 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u}
106 test_expect_success '<branch>@{u}@{1} resolves correctly' '
107 test_commit 6 &&
108 (cd clone && git fetch) &&
109 echo 5 >expect &&
110 commit_subject my-side@{u}@{1} >actual &&
111 test_cmp expect actual &&
112 commit_subject my-side@{U}@{1} >actual &&
113 test_cmp expect actual
116 test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
117 git checkout HEAD^0 &&
118 test_must_fail git rev-parse @{u} &&
119 test_must_fail git rev-parse @{U}
122 test_expect_success 'checkout -b new my-side@{u} forks from the same' '
124 cd clone &&
125 git checkout -b new my-side@{u} &&
126 git rev-parse --symbolic-full-name my-side@{u} >expect &&
127 git rev-parse --symbolic-full-name new@{u} >actual &&
128 test_cmp expect actual
132 test_expect_success 'merge my-side@{u} records the correct name' '
134 cd clone &&
135 git checkout master &&
136 test_might_fail git branch -D new &&
137 git branch -t new my-side@{u} &&
138 git merge -s ours new@{u} &&
139 git show -s --pretty=tformat:%s >actual &&
140 echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect &&
141 test_cmp expect actual
145 test_expect_success 'branch -d other@{u}' '
146 git checkout -t -b other master &&
147 git branch -d @{u} &&
148 git for-each-ref refs/heads/master >actual &&
149 test_must_be_empty actual
152 test_expect_success 'checkout other@{u}' '
153 git branch -f master HEAD &&
154 git checkout -t -b another master &&
155 git checkout @{u} &&
156 git symbolic-ref HEAD >actual &&
157 echo refs/heads/master >expect &&
158 test_cmp expect actual
161 test_expect_success 'branch@{u} works when tracking a local branch' '
162 echo refs/heads/master >expect &&
163 git -C clone rev-parse --symbolic-full-name local-master@{u} >actual &&
164 test_cmp expect actual
167 test_expect_success 'branch@{u} error message when no upstream' '
168 cat >expect <<-EOF &&
169 fatal: no upstream configured for branch ${SQ}non-tracking${SQ}
171 error_message non-tracking@{u} &&
172 test_i18ncmp expect error
175 test_expect_success '@{u} error message when no upstream' '
176 cat >expect <<-EOF &&
177 fatal: no upstream configured for branch ${SQ}master${SQ}
179 test_must_fail git rev-parse --verify @{u} 2>actual &&
180 test_i18ncmp expect actual
183 test_expect_success 'branch@{u} error message with misspelt branch' '
184 cat >expect <<-EOF &&
185 fatal: no such branch: ${SQ}no-such-branch${SQ}
187 error_message no-such-branch@{u} &&
188 test_i18ncmp expect error
191 test_expect_success '@{u} error message when not on a branch' '
192 cat >expect <<-EOF &&
193 fatal: HEAD does not point to a branch
195 git checkout HEAD^0 &&
196 test_must_fail git rev-parse --verify @{u} 2>actual &&
197 test_i18ncmp expect actual
200 test_expect_success 'branch@{u} error message if upstream branch not fetched' '
201 cat >expect <<-EOF &&
202 fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch
204 error_message bad-upstream@{u} &&
205 test_i18ncmp expect error
208 test_expect_success 'pull works when tracking a local branch' '
210 cd clone &&
211 git checkout local-master &&
212 git pull
216 # makes sense if the previous one succeeded
217 test_expect_success '@{u} works when tracking a local branch' '
218 echo refs/heads/master >expect &&
219 git -C clone rev-parse --symbolic-full-name @{u} >actual &&
220 test_cmp expect actual
223 test_expect_success 'log -g other@{u}' '
224 commit=$(git rev-parse HEAD) &&
225 cat >expect <<-EOF &&
226 commit $commit
227 Reflog: master@{0} (C O Mitter <committer@example.com>)
228 Reflog message: branch: Created from HEAD
229 Author: A U Thor <author@example.com>
230 Date: Thu Apr 7 15:15:13 2005 -0700
234 git log -1 -g other@{u} >actual &&
235 test_cmp expect actual
238 test_expect_success 'log -g other@{u}@{now}' '
239 commit=$(git rev-parse HEAD) &&
240 cat >expect <<-EOF &&
241 commit $commit
242 Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
243 Reflog message: branch: Created from HEAD
244 Author: A U Thor <author@example.com>
245 Date: Thu Apr 7 15:15:13 2005 -0700
249 git log -1 -g other@{u}@{now} >actual &&
250 test_cmp expect actual
253 test_expect_success '@{reflog}-parsing does not look beyond colon' '
254 echo content >@{yesterday} &&
255 git add @{yesterday} &&
256 git commit -m "funny reflog file" &&
257 git hash-object @{yesterday} >expect &&
258 git rev-parse HEAD:@{yesterday} >actual
261 test_expect_success '@{upstream}-parsing does not look beyond colon' '
262 echo content >@{upstream} &&
263 git add @{upstream} &&
264 git commit -m "funny upstream file" &&
265 git hash-object @{upstream} >expect &&
266 git rev-parse HEAD:@{upstream} >actual
269 test_done