mailinfo: treat header values as C strings
[git/debian.git] / t / t1507-rev-parse-upstream.sh
blob8b4cf8a6e3c2c9363210cd7a2bd619acd9e1c0b7
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=format:%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 test refs/remotes/origin/master = "$(full_name @{upstream})" &&
48 test refs/remotes/origin/master = "$(full_name @{UPSTREAM})" &&
49 test refs/remotes/origin/master = "$(full_name @{UpSTReam})"
52 test_expect_success '@{u} resolves to correct full name' '
53 test refs/remotes/origin/master = "$(full_name @{u})" &&
54 test refs/remotes/origin/master = "$(full_name @{U})"
57 test_expect_success 'my-side@{upstream} resolves to correct full name' '
58 test refs/remotes/origin/side = "$(full_name my-side@{u})"
61 test_expect_success 'upstream of branch with @ in middle' '
62 full_name fun@ny@{u} >actual &&
63 echo refs/remotes/origin/side >expect &&
64 test_cmp expect actual &&
65 full_name fun@ny@{U} >actual &&
66 test_cmp expect actual
69 test_expect_success 'upstream of branch with @ at start' '
70 full_name @funny@{u} >actual &&
71 echo refs/remotes/origin/side >expect &&
72 test_cmp expect actual
75 test_expect_success 'upstream of branch with @ at end' '
76 full_name funny@@{u} >actual &&
77 echo refs/remotes/origin/side >expect &&
78 test_cmp expect actual
81 test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
82 test_must_fail full_name refs/heads/my-side@{upstream}
85 test_expect_success 'my-side@{u} resolves to correct commit' '
86 git checkout side &&
87 test_commit 5 &&
88 (cd clone && git fetch) &&
89 test 2 = "$(commit_subject my-side)" &&
90 test 5 = "$(commit_subject my-side@{u})"
93 test_expect_success 'not-tracking@{u} fails' '
94 test_must_fail full_name non-tracking@{u} &&
95 (cd clone && git checkout --no-track -b non-tracking) &&
96 test_must_fail full_name non-tracking@{u}
99 test_expect_success '<branch>@{u}@{1} resolves correctly' '
100 test_commit 6 &&
101 (cd clone && git fetch) &&
102 test 5 = $(commit_subject my-side@{u}@{1}) &&
103 test 5 = $(commit_subject my-side@{U}@{1})
106 test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
107 git checkout HEAD^0 &&
108 test_must_fail git rev-parse @{u} &&
109 test_must_fail git rev-parse @{U}
112 test_expect_success 'checkout -b new my-side@{u} forks from the same' '
114 cd clone &&
115 git checkout -b new my-side@{u} &&
116 git rev-parse --symbolic-full-name my-side@{u} >expect &&
117 git rev-parse --symbolic-full-name new@{u} >actual &&
118 test_cmp expect actual
122 test_expect_success 'merge my-side@{u} records the correct name' '
124 cd clone &&
125 git checkout master &&
126 test_might_fail git branch -D new &&
127 git branch -t new my-side@{u} &&
128 git merge -s ours new@{u} &&
129 git show -s --pretty=tformat:%s >actual &&
130 echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect &&
131 test_cmp expect actual
135 test_expect_success 'branch -d other@{u}' '
136 git checkout -t -b other master &&
137 git branch -d @{u} &&
138 git for-each-ref refs/heads/master >actual &&
139 test_must_be_empty actual
142 test_expect_success 'checkout other@{u}' '
143 git branch -f master HEAD &&
144 git checkout -t -b another master &&
145 git checkout @{u} &&
146 git symbolic-ref HEAD >actual &&
147 echo refs/heads/master >expect &&
148 test_cmp expect actual
151 test_expect_success 'branch@{u} works when tracking a local branch' '
152 test refs/heads/master = "$(full_name local-master@{u})"
155 test_expect_success 'branch@{u} error message when no upstream' '
156 cat >expect <<-EOF &&
157 fatal: no upstream configured for branch ${SQ}non-tracking${SQ}
159 error_message non-tracking@{u} &&
160 test_i18ncmp expect error
163 test_expect_success '@{u} error message when no upstream' '
164 cat >expect <<-EOF &&
165 fatal: no upstream configured for branch ${SQ}master${SQ}
167 test_must_fail git rev-parse --verify @{u} 2>actual &&
168 test_i18ncmp expect actual
171 test_expect_success 'branch@{u} error message with misspelt branch' '
172 cat >expect <<-EOF &&
173 fatal: no such branch: ${SQ}no-such-branch${SQ}
175 error_message no-such-branch@{u} &&
176 test_i18ncmp expect error
179 test_expect_success '@{u} error message when not on a branch' '
180 cat >expect <<-EOF &&
181 fatal: HEAD does not point to a branch
183 git checkout HEAD^0 &&
184 test_must_fail git rev-parse --verify @{u} 2>actual &&
185 test_i18ncmp expect actual
188 test_expect_success 'branch@{u} error message if upstream branch not fetched' '
189 cat >expect <<-EOF &&
190 fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch
192 error_message bad-upstream@{u} &&
193 test_i18ncmp expect error
196 test_expect_success 'pull works when tracking a local branch' '
198 cd clone &&
199 git checkout local-master &&
200 git pull
204 # makes sense if the previous one succeeded
205 test_expect_success '@{u} works when tracking a local branch' '
206 test refs/heads/master = "$(full_name @{u})"
209 commit=$(git rev-parse HEAD)
210 cat >expect <<EOF
211 commit $commit
212 Reflog: master@{0} (C O Mitter <committer@example.com>)
213 Reflog message: branch: Created from HEAD
214 Author: A U Thor <author@example.com>
215 Date: Thu Apr 7 15:15:13 2005 -0700
219 test_expect_success 'log -g other@{u}' '
220 git log -1 -g other@{u} >actual &&
221 test_cmp expect actual
224 cat >expect <<EOF
225 commit $commit
226 Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
227 Reflog message: branch: Created from HEAD
228 Author: A U Thor <author@example.com>
229 Date: Thu Apr 7 15:15:13 2005 -0700
234 test_expect_success 'log -g other@{u}@{now}' '
235 git log -1 -g other@{u}@{now} >actual &&
236 test_cmp expect actual
239 test_expect_success '@{reflog}-parsing does not look beyond colon' '
240 echo content >@{yesterday} &&
241 git add @{yesterday} &&
242 git commit -m "funny reflog file" &&
243 git hash-object @{yesterday} >expect &&
244 git rev-parse HEAD:@{yesterday} >actual
247 test_expect_success '@{upstream}-parsing does not look beyond colon' '
248 echo content >@{upstream} &&
249 git add @{upstream} &&
250 git commit -m "funny upstream file" &&
251 git hash-object @{upstream} >expect &&
252 git rev-parse HEAD:@{upstream} >actual
255 test_done