]>
Commit | Line | Data |
---|---|---|
28fb8438 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='test <branch>@{upstream} syntax' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | ||
8 | test_expect_success 'setup' ' | |
9 | ||
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 && | |
1b4aee94 ZJS |
18 | git branch --track my-side origin/side && |
19 | git branch --track local-master master && | |
9892d5d4 JK |
20 | git branch --track fun@ny origin/side && |
21 | git branch --track @funny origin/side && | |
22 | git branch --track funny@ origin/side && | |
1b4aee94 ZJS |
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 | |
28 | ) | |
28fb8438 JS |
29 | ' |
30 | ||
1b4aee94 ZJS |
31 | sq="'" |
32 | ||
28fb8438 JS |
33 | full_name () { |
34 | (cd clone && | |
35 | git rev-parse --symbolic-full-name "$@") | |
36 | } | |
37 | ||
38 | commit_subject () { | |
39 | (cd clone && | |
40 | git show -s --pretty=format:%s "$@") | |
41 | } | |
42 | ||
1b4aee94 ZJS |
43 | error_message () { |
44 | (cd clone && | |
45 | test_must_fail git rev-parse --verify "$@") | |
46 | } | |
47 | ||
28fb8438 JS |
48 | test_expect_success '@{upstream} resolves to correct full name' ' |
49 | test refs/remotes/origin/master = "$(full_name @{upstream})" | |
50 | ' | |
51 | ||
52 | test_expect_success '@{u} resolves to correct full name' ' | |
53 | test refs/remotes/origin/master = "$(full_name @{u})" | |
54 | ' | |
55 | ||
56 | test_expect_success 'my-side@{upstream} resolves to correct full name' ' | |
57 | test refs/remotes/origin/side = "$(full_name my-side@{u})" | |
58 | ' | |
59 | ||
9892d5d4 JK |
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 | |
64 | ' | |
65 | ||
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 | |
70 | ' | |
71 | ||
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 | |
76 | ' | |
77 | ||
617cf931 KK |
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} | |
80 | ' | |
81 | ||
28fb8438 JS |
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})" | |
88 | ' | |
89 | ||
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} | |
94 | ' | |
95 | ||
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}) | |
100 | ' | |
101 | ||
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} | |
105 | ' | |
106 | ||
69add8e6 JH |
107 | test_expect_success 'checkout -b new my-side@{u} forks from the same' ' |
108 | ( | |
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 | |
114 | ) | |
115 | ' | |
116 | ||
ae0ba8e2 | 117 | test_expect_success 'merge my-side@{u} records the correct name' ' |
69add8e6 | 118 | ( |
69add8e6 JH |
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} && | |
ad2f7255 | 124 | git show -s --pretty=tformat:%s >actual && |
13931236 | 125 | echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect && |
69add8e6 JH |
126 | test_cmp expect actual |
127 | ) | |
128 | ' | |
129 | ||
ae0ba8e2 | 130 | test_expect_success 'branch -d other@{u}' ' |
69add8e6 JH |
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 | |
136 | ' | |
137 | ||
ae0ba8e2 | 138 | test_expect_success 'checkout other@{u}' ' |
69add8e6 JH |
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 | |
145 | ' | |
146 | ||
1b4aee94 ZJS |
147 | test_expect_success 'branch@{u} works when tracking a local branch' ' |
148 | test refs/heads/master = "$(full_name local-master@{u})" | |
149 | ' | |
150 | ||
151 | test_expect_success 'branch@{u} error message when no upstream' ' | |
152 | cat >expect <<-EOF && | |
3a429d0a | 153 | fatal: no upstream configured for branch ${sq}non-tracking${sq} |
1b4aee94 ZJS |
154 | EOF |
155 | error_message non-tracking@{u} 2>actual && | |
64720288 | 156 | test_i18ncmp expect actual |
1b4aee94 ZJS |
157 | ' |
158 | ||
159 | test_expect_success '@{u} error message when no upstream' ' | |
160 | cat >expect <<-EOF && | |
3a429d0a | 161 | fatal: no upstream configured for branch ${sq}master${sq} |
1b4aee94 ZJS |
162 | EOF |
163 | test_must_fail git rev-parse --verify @{u} 2>actual && | |
64720288 | 164 | test_i18ncmp expect actual |
1b4aee94 ZJS |
165 | ' |
166 | ||
167 | test_expect_success 'branch@{u} error message with misspelt branch' ' | |
168 | cat >expect <<-EOF && | |
3a429d0a | 169 | fatal: no such branch: ${sq}no-such-branch${sq} |
1b4aee94 ZJS |
170 | EOF |
171 | error_message no-such-branch@{u} 2>actual && | |
64720288 | 172 | test_i18ncmp expect actual |
1b4aee94 ZJS |
173 | ' |
174 | ||
175 | test_expect_success '@{u} error message when not on a branch' ' | |
176 | cat >expect <<-EOF && | |
17bf4ff3 | 177 | fatal: HEAD does not point to a branch |
1b4aee94 ZJS |
178 | EOF |
179 | git checkout HEAD^0 && | |
180 | test_must_fail git rev-parse --verify @{u} 2>actual && | |
64720288 | 181 | test_i18ncmp expect actual |
1b4aee94 ZJS |
182 | ' |
183 | ||
184 | test_expect_success 'branch@{u} error message if upstream branch not fetched' ' | |
185 | cat >expect <<-EOF && | |
3a429d0a | 186 | fatal: upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch |
1b4aee94 ZJS |
187 | EOF |
188 | error_message bad-upstream@{u} 2>actual && | |
64720288 | 189 | test_i18ncmp expect actual |
1b4aee94 ZJS |
190 | ' |
191 | ||
192 | test_expect_success 'pull works when tracking a local branch' ' | |
193 | ( | |
194 | cd clone && | |
195 | git checkout local-master && | |
196 | git pull | |
197 | ) | |
198 | ' | |
199 | ||
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})" | |
203 | ' | |
204 | ||
105e4733 JH |
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 | |
211 | ||
212 | 3 | |
213 | EOF | |
214 | test_expect_success 'log -g other@{u}' ' | |
215 | git log -1 -g other@{u} >actual && | |
216 | test_cmp expect actual | |
217 | ' | |
218 | ||
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 | |
225 | ||
226 | 3 | |
227 | EOF | |
228 | ||
229 | test_expect_success 'log -g other@{u}@{now}' ' | |
230 | git log -1 -g other@{u}@{now} >actual && | |
231 | test_cmp expect actual | |
232 | ' | |
233 | ||
3f6eb30f JK |
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 | |
240 | ' | |
241 | ||
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 | |
248 | ' | |
249 | ||
28fb8438 | 250 | test_done |