t4150: am --resolved fails if index has no changes
[git/mingw/j6t.git] / t / t1507-rev-parse-upstream.sh
blob46ef1f22dca14423ecff8da45d608a8885f23dba
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 sq="'"
33 full_name () {
34 (cd clone &&
35 git rev-parse --symbolic-full-name "$@")
38 commit_subject () {
39 (cd clone &&
40 git show -s --pretty=format:%s "$@")
43 error_message () {
44 (cd clone &&
45 test_must_fail git rev-parse --verify "$@")
48 test_expect_success '@{upstream} resolves to correct full name' '
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})"
56 test_expect_success 'my-side@{upstream} resolves to correct full name' '
57 test refs/remotes/origin/side = "$(full_name my-side@{u})"
60 test_expect_success 'upstream of branch with @ in middle' '
61 full_name fun@ny@{u} >actual &&
62 echo refs/remotes/origin/side >expect &&
63 test_cmp expect actual
66 test_expect_success 'upstream of branch with @ at start' '
67 full_name @funny@{u} >actual &&
68 echo refs/remotes/origin/side >expect &&
69 test_cmp expect actual
72 test_expect_success 'upstream of branch with @ at end' '
73 full_name funny@@{u} >actual &&
74 echo refs/remotes/origin/side >expect &&
75 test_cmp expect actual
78 test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
79 test_must_fail full_name refs/heads/my-side@{upstream}
82 test_expect_success 'my-side@{u} resolves to correct commit' '
83 git checkout side &&
84 test_commit 5 &&
85 (cd clone && git fetch) &&
86 test 2 = "$(commit_subject my-side)" &&
87 test 5 = "$(commit_subject my-side@{u})"
90 test_expect_success 'not-tracking@{u} fails' '
91 test_must_fail full_name non-tracking@{u} &&
92 (cd clone && git checkout --no-track -b non-tracking) &&
93 test_must_fail full_name non-tracking@{u}
96 test_expect_success '<branch>@{u}@{1} resolves correctly' '
97 test_commit 6 &&
98 (cd clone && git fetch) &&
99 test 5 = $(commit_subject my-side@{u}@{1})
102 test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
103 git checkout HEAD^0 &&
104 test_must_fail git rev-parse @{u}
107 test_expect_success 'checkout -b new my-side@{u} forks from the same' '
109 cd clone &&
110 git checkout -b new my-side@{u} &&
111 git rev-parse --symbolic-full-name my-side@{u} >expect &&
112 git rev-parse --symbolic-full-name new@{u} >actual &&
113 test_cmp expect actual
117 test_expect_success 'merge my-side@{u} records the correct name' '
119 cd clone || exit
120 git checkout master || exit
121 git branch -D new ;# can fail but is ok
122 git branch -t new my-side@{u} &&
123 git merge -s ours new@{u} &&
124 git show -s --pretty=tformat:%s >actual &&
125 echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect &&
126 test_cmp expect actual
130 test_expect_success 'branch -d other@{u}' '
131 git checkout -t -b other master &&
132 git branch -d @{u} &&
133 git for-each-ref refs/heads/master >actual &&
134 >expect &&
135 test_cmp expect actual
138 test_expect_success 'checkout other@{u}' '
139 git branch -f master HEAD &&
140 git checkout -t -b another master &&
141 git checkout @{u} &&
142 git symbolic-ref HEAD >actual &&
143 echo refs/heads/master >expect &&
144 test_cmp expect actual
147 test_expect_success 'branch@{u} works when tracking a local branch' '
148 test refs/heads/master = "$(full_name local-master@{u})"
151 test_expect_success 'branch@{u} error message when no upstream' '
152 cat >expect <<-EOF &&
153 fatal: no upstream configured for branch ${sq}non-tracking${sq}
155 error_message non-tracking@{u} 2>actual &&
156 test_i18ncmp expect actual
159 test_expect_success '@{u} error message when no upstream' '
160 cat >expect <<-EOF &&
161 fatal: no upstream configured for branch ${sq}master${sq}
163 test_must_fail git rev-parse --verify @{u} 2>actual &&
164 test_i18ncmp expect actual
167 test_expect_success 'branch@{u} error message with misspelt branch' '
168 cat >expect <<-EOF &&
169 fatal: no such branch: ${sq}no-such-branch${sq}
171 error_message no-such-branch@{u} 2>actual &&
172 test_i18ncmp expect actual
175 test_expect_success '@{u} error message when not on a branch' '
176 cat >expect <<-EOF &&
177 fatal: HEAD does not point to a branch
179 git checkout HEAD^0 &&
180 test_must_fail git rev-parse --verify @{u} 2>actual &&
181 test_i18ncmp expect actual
184 test_expect_success 'branch@{u} error message if upstream branch not fetched' '
185 cat >expect <<-EOF &&
186 fatal: upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
188 error_message bad-upstream@{u} 2>actual &&
189 test_i18ncmp expect actual
192 test_expect_success 'pull works when tracking a local branch' '
194 cd clone &&
195 git checkout local-master &&
196 git pull
200 # makes sense if the previous one succeeded
201 test_expect_success '@{u} works when tracking a local branch' '
202 test refs/heads/master = "$(full_name @{u})"
205 cat >expect <<EOF
206 commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
207 Reflog: master@{0} (C O Mitter <committer@example.com>)
208 Reflog message: branch: Created from HEAD
209 Author: A U Thor <author@example.com>
210 Date: Thu Apr 7 15:15:13 2005 -0700
214 test_expect_success 'log -g other@{u}' '
215 git log -1 -g other@{u} >actual &&
216 test_cmp expect actual
219 cat >expect <<EOF
220 commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
221 Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
222 Reflog message: branch: Created from HEAD
223 Author: A U Thor <author@example.com>
224 Date: Thu Apr 7 15:15:13 2005 -0700
229 test_expect_success 'log -g other@{u}@{now}' '
230 git log -1 -g other@{u}@{now} >actual &&
231 test_cmp expect actual
234 test_expect_success '@{reflog}-parsing does not look beyond colon' '
235 echo content >@{yesterday} &&
236 git add @{yesterday} &&
237 git commit -m "funny reflog file" &&
238 git hash-object @{yesterday} >expect &&
239 git rev-parse HEAD:@{yesterday} >actual
242 test_expect_success '@{upstream}-parsing does not look beyond colon' '
243 echo content >@{upstream} &&
244 git add @{upstream} &&
245 git commit -m "funny upstream file" &&
246 git hash-object @{upstream} >expect &&
247 git rev-parse HEAD:@{upstream} >actual
250 test_done