3 test_description='test <branch>@{upstream} syntax'
8 test_expect_success 'setup' '
11 git checkout -b side &&
13 git checkout master &&
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
35 git rev-parse --symbolic-full-name "$@")
40 git show -s --pretty=format:%s "$@")
45 test_must_fail git rev-parse --verify "$@" 2>../error)
48 test_expect_success '@{upstream} resolves to correct full name' '
49 test refs/remotes/origin/master = "$(full_name @{upstream})" &&
50 test refs/remotes/origin/master = "$(full_name @{UPSTREAM})" &&
51 test refs/remotes/origin/master = "$(full_name @{UpSTReam})"
54 test_expect_success '@{u} resolves to correct full name' '
55 test refs/remotes/origin/master = "$(full_name @{u})" &&
56 test refs/remotes/origin/master = "$(full_name @{U})"
59 test_expect_success 'my-side@{upstream} resolves to correct full name' '
60 test refs/remotes/origin/side = "$(full_name my-side@{u})"
63 test_expect_success 'upstream of branch with @ in middle' '
64 full_name fun@ny@{u} >actual &&
65 echo refs/remotes/origin/side >expect &&
66 test_cmp expect actual &&
67 full_name fun@ny@{U} >actual &&
68 test_cmp expect actual
71 test_expect_success 'upstream of branch with @ at start' '
72 full_name @funny@{u} >actual &&
73 echo refs/remotes/origin/side >expect &&
74 test_cmp expect actual
77 test_expect_success 'upstream of branch with @ at end' '
78 full_name funny@@{u} >actual &&
79 echo refs/remotes/origin/side >expect &&
80 test_cmp expect actual
83 test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
84 test_must_fail full_name refs/heads/my-side@{upstream}
87 test_expect_success 'my-side@{u} resolves to correct commit' '
90 (cd clone && git fetch) &&
91 test 2 = "$(commit_subject my-side)" &&
92 test 5 = "$(commit_subject my-side@{u})"
95 test_expect_success 'not-tracking@{u} fails' '
96 test_must_fail full_name non-tracking@{u} &&
97 (cd clone && git checkout --no-track -b non-tracking) &&
98 test_must_fail full_name non-tracking@{u}
101 test_expect_success '<branch>@{u}@{1} resolves correctly' '
103 (cd clone && git fetch) &&
104 test 5 = $(commit_subject my-side@{u}@{1}) &&
105 test 5 = $(commit_subject my-side@{U}@{1})
108 test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
109 git checkout HEAD^0 &&
110 test_must_fail git rev-parse @{u} &&
111 test_must_fail git rev-parse @{U}
114 test_expect_success 'checkout -b new my-side@{u} forks from the same' '
117 git checkout -b new my-side@{u} &&
118 git rev-parse --symbolic-full-name my-side@{u} >expect &&
119 git rev-parse --symbolic-full-name new@{u} >actual &&
120 test_cmp expect actual
124 test_expect_success 'merge my-side@{u} records the correct name' '
127 git checkout master || exit
128 git branch -D new ;# can fail but is ok
129 git branch -t new my-side@{u} &&
130 git merge -s ours new@{u} &&
131 git show -s --pretty=tformat:%s >actual &&
132 echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect &&
133 test_cmp expect actual
137 test_expect_success 'branch -d other@{u}' '
138 git checkout -t -b other master &&
139 git branch -d @{u} &&
140 git for-each-ref refs/heads/master >actual &&
142 test_cmp expect actual
145 test_expect_success 'checkout other@{u}' '
146 git branch -f master HEAD &&
147 git checkout -t -b another master &&
149 git symbolic-ref HEAD >actual &&
150 echo refs/heads/master >expect &&
151 test_cmp expect actual
154 test_expect_success 'branch@{u} works when tracking a local branch' '
155 test refs/heads/master = "$(full_name local-master@{u})"
158 test_expect_success 'branch@{u} error message when no upstream' '
159 cat >expect <<-EOF &&
160 fatal: no upstream configured for branch ${sq}non-tracking${sq}
162 error_message non-tracking@{u} &&
163 test_i18ncmp expect error
166 test_expect_success '@{u} error message when no upstream' '
167 cat >expect <<-EOF &&
168 fatal: no upstream configured for branch ${sq}master${sq}
170 test_must_fail git rev-parse --verify @{u} 2>actual &&
171 test_i18ncmp expect actual
174 test_expect_success 'branch@{u} error message with misspelt branch' '
175 cat >expect <<-EOF &&
176 fatal: no such branch: ${sq}no-such-branch${sq}
178 error_message no-such-branch@{u} &&
179 test_i18ncmp expect error
182 test_expect_success '@{u} error message when not on a branch' '
183 cat >expect <<-EOF &&
184 fatal: HEAD does not point to a branch
186 git checkout HEAD^0 &&
187 test_must_fail git rev-parse --verify @{u} 2>actual &&
188 test_i18ncmp expect actual
191 test_expect_success 'branch@{u} error message if upstream branch not fetched' '
192 cat >expect <<-EOF &&
193 fatal: upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
195 error_message bad-upstream@{u} &&
196 test_i18ncmp expect error
199 test_expect_success 'pull works when tracking a local branch' '
202 git checkout local-master &&
207 # makes sense if the previous one succeeded
208 test_expect_success '@{u} works when tracking a local branch' '
209 test refs/heads/master = "$(full_name @{u})"
212 commit=$(git rev-parse HEAD)
215 Reflog: master@{0} (C O Mitter <committer@example.com>)
216 Reflog message: branch: Created from HEAD
217 Author: A U Thor <author@example.com>
218 Date: Thu Apr 7 15:15:13 2005 -0700
222 test_expect_success 'log -g other@{u}' '
223 git log -1 -g other@{u} >actual &&
224 test_cmp expect actual
229 Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
230 Reflog message: branch: Created from HEAD
231 Author: A U Thor <author@example.com>
232 Date: Thu Apr 7 15:15:13 2005 -0700
237 test_expect_success 'log -g other@{u}@{now}' '
238 git log -1 -g other@{u}@{now} >actual &&
239 test_cmp expect actual
242 test_expect_success '@{reflog}-parsing does not look beyond colon' '
243 echo content >@{yesterday} &&
244 git add @{yesterday} &&
245 git commit -m "funny reflog file" &&
246 git hash-object @{yesterday} >expect &&
247 git rev-parse HEAD:@{yesterday} >actual
250 test_expect_success '@{upstream}-parsing does not look beyond colon' '
251 echo content >@{upstream} &&
252 git add @{upstream} &&
253 git commit -m "funny upstream file" &&
254 git hash-object @{upstream} >expect &&
255 git rev-parse HEAD:@{upstream} >actual