t1507: stop losing return codes of git commands
[git/debian.git] / t / t1507-rev-parse-upstream.sh
blobd81f289acef0c904ecc7a96bb32a8858aca2a3e1
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 full_name () {
32 (cd clone &&
33 git rev-parse --symbolic-full-name "$@")
36 commit_subject () {
37 (cd clone &&
38 git show -s --pretty=tformat:%s "$@")
41 error_message () {
42 (cd clone &&
43 test_must_fail git rev-parse --verify "$@" 2>../error)
46 test_expect_success '@{upstream} resolves to correct full name' '
47 echo refs/remotes/origin/master >expect &&
48 full_name @{upstream} >actual &&
49 test_cmp expect actual &&
50 full_name @{UPSTREAM} >actual &&
51 test_cmp expect actual &&
52 full_name @{UpSTReam} >actual &&
53 test_cmp expect actual
56 test_expect_success '@{u} resolves to correct full name' '
57 echo refs/remotes/origin/master >expect &&
58 full_name @{u} >actual &&
59 test_cmp expect actual &&
60 full_name @{U} >actual &&
61 test_cmp expect actual
64 test_expect_success 'my-side@{upstream} resolves to correct full name' '
65 echo refs/remotes/origin/side >expect &&
66 full_name my-side@{u} >actual &&
67 test_cmp expect actual
70 test_expect_success 'upstream of branch with @ in middle' '
71 full_name fun@ny@{u} >actual &&
72 echo refs/remotes/origin/side >expect &&
73 test_cmp expect actual &&
74 full_name fun@ny@{U} >actual &&
75 test_cmp expect actual
78 test_expect_success 'upstream of branch with @ at start' '
79 full_name @funny@{u} >actual &&
80 echo refs/remotes/origin/side >expect &&
81 test_cmp expect actual
84 test_expect_success 'upstream of branch with @ at end' '
85 full_name funny@@{u} >actual &&
86 echo refs/remotes/origin/side >expect &&
87 test_cmp expect actual
90 test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
91 test_must_fail full_name refs/heads/my-side@{upstream}
94 test_expect_success 'my-side@{u} resolves to correct commit' '
95 git checkout side &&
96 test_commit 5 &&
97 (cd clone && git fetch) &&
98 echo 2 >expect &&
99 commit_subject my-side >actual &&
100 test_cmp expect actual &&
101 echo 5 >expect &&
102 commit_subject my-side@{u} >actual
105 test_expect_success 'not-tracking@{u} fails' '
106 test_must_fail full_name non-tracking@{u} &&
107 (cd clone && git checkout --no-track -b non-tracking) &&
108 test_must_fail 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 master &&
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 master &&
152 git branch -d @{u} &&
153 git for-each-ref refs/heads/master >actual &&
154 test_must_be_empty actual
157 test_expect_success 'checkout other@{u}' '
158 git branch -f master HEAD &&
159 git checkout -t -b another master &&
160 git checkout @{u} &&
161 git symbolic-ref HEAD >actual &&
162 echo refs/heads/master >expect &&
163 test_cmp expect actual
166 test_expect_success 'branch@{u} works when tracking a local branch' '
167 echo refs/heads/master >expect &&
168 full_name local-master@{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_i18ncmp expect error
180 test_expect_success '@{u} error message when no upstream' '
181 cat >expect <<-EOF &&
182 fatal: no upstream configured for branch ${SQ}master${SQ}
184 test_must_fail git rev-parse --verify @{u} 2>actual &&
185 test_i18ncmp expect actual
188 test_expect_success 'branch@{u} error message with misspelt branch' '
189 cat >expect <<-EOF &&
190 fatal: no such branch: ${SQ}no-such-branch${SQ}
192 error_message no-such-branch@{u} &&
193 test_i18ncmp expect error
196 test_expect_success '@{u} error message when not on a branch' '
197 cat >expect <<-EOF &&
198 fatal: HEAD does not point to a branch
200 git checkout HEAD^0 &&
201 test_must_fail git rev-parse --verify @{u} 2>actual &&
202 test_i18ncmp expect actual
205 test_expect_success 'branch@{u} error message if upstream branch not fetched' '
206 cat >expect <<-EOF &&
207 fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch
209 error_message bad-upstream@{u} &&
210 test_i18ncmp expect error
213 test_expect_success 'pull works when tracking a local branch' '
215 cd clone &&
216 git checkout local-master &&
217 git pull
221 # makes sense if the previous one succeeded
222 test_expect_success '@{u} works when tracking a local branch' '
223 echo refs/heads/master >expect &&
224 full_name @{u} >actual &&
225 test_cmp expect actual
228 commit=$(git rev-parse HEAD)
229 cat >expect <<EOF
230 commit $commit
231 Reflog: master@{0} (C O Mitter <committer@example.com>)
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
238 test_expect_success 'log -g other@{u}' '
239 git log -1 -g other@{u} >actual &&
240 test_cmp expect actual
243 cat >expect <<EOF
244 commit $commit
245 Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
246 Reflog message: branch: Created from HEAD
247 Author: A U Thor <author@example.com>
248 Date: Thu Apr 7 15:15:13 2005 -0700
253 test_expect_success 'log -g other@{u}@{now}' '
254 git log -1 -g other@{u}@{now} >actual &&
255 test_cmp expect actual
258 test_expect_success '@{reflog}-parsing does not look beyond colon' '
259 echo content >@{yesterday} &&
260 git add @{yesterday} &&
261 git commit -m "funny reflog file" &&
262 git hash-object @{yesterday} >expect &&
263 git rev-parse HEAD:@{yesterday} >actual
266 test_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 &&
271 git rev-parse HEAD:@{upstream} >actual
274 test_done