]>
Commit | Line | Data |
---|---|---|
28fb8438 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='test <branch>@{upstream} syntax' | |
4 | ||
06d53148 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
80d32e84 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
28fb8438 JS |
9 | . ./test-lib.sh |
10 | ||
11 | ||
12 | test_expect_success 'setup' ' | |
13 | ||
14 | test_commit 1 && | |
15 | git checkout -b side && | |
16 | test_commit 2 && | |
06d53148 | 17 | git checkout main && |
28fb8438 JS |
18 | git clone . clone && |
19 | test_commit 3 && | |
20 | (cd clone && | |
21 | test_commit 4 && | |
1b4aee94 | 22 | git branch --track my-side origin/side && |
06d53148 | 23 | git branch --track local-main main && |
9892d5d4 JK |
24 | git branch --track fun@ny origin/side && |
25 | git branch --track @funny origin/side && | |
26 | git branch --track funny@ origin/side && | |
06d53148 JS |
27 | git remote add -t main main-only .. && |
28 | git fetch main-only && | |
1b4aee94 | 29 | git branch bad-upstream && |
06d53148 | 30 | git config branch.bad-upstream.remote main-only && |
1b4aee94 ZJS |
31 | git config branch.bad-upstream.merge refs/heads/side |
32 | ) | |
28fb8438 JS |
33 | ' |
34 | ||
28fb8438 JS |
35 | commit_subject () { |
36 | (cd clone && | |
5236fce6 | 37 | git show -s --pretty=tformat:%s "$@") |
28fb8438 JS |
38 | } |
39 | ||
1b4aee94 ZJS |
40 | error_message () { |
41 | (cd clone && | |
c3a44562 | 42 | test_must_fail git rev-parse --verify "$@" 2>../error) |
1b4aee94 ZJS |
43 | } |
44 | ||
28fb8438 | 45 | test_expect_success '@{upstream} resolves to correct full name' ' |
06d53148 | 46 | echo refs/remotes/origin/main >expect && |
b4417172 | 47 | git -C clone rev-parse --symbolic-full-name @{upstream} >actual && |
5236fce6 | 48 | test_cmp expect actual && |
b4417172 | 49 | git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual && |
5236fce6 | 50 | test_cmp expect actual && |
b4417172 | 51 | git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual && |
5236fce6 | 52 | test_cmp expect actual |
28fb8438 JS |
53 | ' |
54 | ||
55 | test_expect_success '@{u} resolves to correct full name' ' | |
06d53148 | 56 | echo refs/remotes/origin/main >expect && |
b4417172 | 57 | git -C clone rev-parse --symbolic-full-name @{u} >actual && |
5236fce6 | 58 | test_cmp expect actual && |
b4417172 | 59 | git -C clone rev-parse --symbolic-full-name @{U} >actual && |
5236fce6 | 60 | test_cmp expect actual |
28fb8438 JS |
61 | ' |
62 | ||
63 | test_expect_success 'my-side@{upstream} resolves to correct full name' ' | |
5236fce6 | 64 | echo refs/remotes/origin/side >expect && |
b4417172 | 65 | git -C clone rev-parse --symbolic-full-name my-side@{u} >actual && |
5236fce6 | 66 | test_cmp expect actual |
28fb8438 JS |
67 | ' |
68 | ||
9892d5d4 | 69 | test_expect_success 'upstream of branch with @ in middle' ' |
b4417172 | 70 | git -C clone rev-parse --symbolic-full-name fun@ny@{u} >actual && |
9892d5d4 | 71 | echo refs/remotes/origin/side >expect && |
244ea1b5 | 72 | test_cmp expect actual && |
b4417172 | 73 | git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual && |
9892d5d4 JK |
74 | test_cmp expect actual |
75 | ' | |
76 | ||
77 | test_expect_success 'upstream of branch with @ at start' ' | |
b4417172 | 78 | git -C clone rev-parse --symbolic-full-name @funny@{u} >actual && |
9892d5d4 JK |
79 | echo refs/remotes/origin/side >expect && |
80 | test_cmp expect actual | |
81 | ' | |
82 | ||
83 | test_expect_success 'upstream of branch with @ at end' ' | |
b4417172 | 84 | git -C clone rev-parse --symbolic-full-name funny@@{u} >actual && |
9892d5d4 JK |
85 | echo refs/remotes/origin/side >expect && |
86 | test_cmp expect actual | |
87 | ' | |
88 | ||
617cf931 | 89 | test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' ' |
b4417172 | 90 | test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream} |
617cf931 KK |
91 | ' |
92 | ||
28fb8438 JS |
93 | test_expect_success 'my-side@{u} resolves to correct commit' ' |
94 | git checkout side && | |
95 | test_commit 5 && | |
96 | (cd clone && git fetch) && | |
5236fce6 DL |
97 | echo 2 >expect && |
98 | commit_subject my-side >actual && | |
99 | test_cmp expect actual && | |
100 | echo 5 >expect && | |
159f4b9c FC |
101 | commit_subject my-side@{u} >actual && |
102 | test_cmp expect actual | |
28fb8438 JS |
103 | ' |
104 | ||
105 | test_expect_success 'not-tracking@{u} fails' ' | |
b4417172 | 106 | test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} && |
28fb8438 | 107 | (cd clone && git checkout --no-track -b non-tracking) && |
b4417172 | 108 | test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} |
28fb8438 JS |
109 | ' |
110 | ||
111 | test_expect_success '<branch>@{u}@{1} resolves correctly' ' | |
112 | test_commit 6 && | |
113 | (cd clone && git fetch) && | |
5236fce6 DL |
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 | |
28fb8438 JS |
119 | ' |
120 | ||
121 | test_expect_success '@{u} without specifying branch fails on a detached HEAD' ' | |
122 | git checkout HEAD^0 && | |
244ea1b5 ÆAB |
123 | test_must_fail git rev-parse @{u} && |
124 | test_must_fail git rev-parse @{U} | |
28fb8438 JS |
125 | ' |
126 | ||
69add8e6 JH |
127 | test_expect_success 'checkout -b new my-side@{u} forks from the same' ' |
128 | ( | |
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 | |
134 | ) | |
135 | ' | |
136 | ||
ae0ba8e2 | 137 | test_expect_success 'merge my-side@{u} records the correct name' ' |
69add8e6 | 138 | ( |
83279748 | 139 | cd clone && |
06d53148 | 140 | git checkout main && |
83279748 | 141 | test_might_fail git branch -D new && |
69add8e6 JH |
142 | git branch -t new my-side@{u} && |
143 | git merge -s ours new@{u} && | |
ad2f7255 | 144 | git show -s --pretty=tformat:%s >actual && |
21531927 | 145 | echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect && |
69add8e6 JH |
146 | test_cmp expect actual |
147 | ) | |
148 | ' | |
149 | ||
ae0ba8e2 | 150 | test_expect_success 'branch -d other@{u}' ' |
06d53148 | 151 | git checkout -t -b other main && |
69add8e6 | 152 | git branch -d @{u} && |
06d53148 | 153 | git for-each-ref refs/heads/main >actual && |
d3c6751b | 154 | test_must_be_empty actual |
69add8e6 JH |
155 | ' |
156 | ||
ae0ba8e2 | 157 | test_expect_success 'checkout other@{u}' ' |
06d53148 JS |
158 | git branch -f main HEAD && |
159 | git checkout -t -b another main && | |
69add8e6 JH |
160 | git checkout @{u} && |
161 | git symbolic-ref HEAD >actual && | |
06d53148 | 162 | echo refs/heads/main >expect && |
69add8e6 JH |
163 | test_cmp expect actual |
164 | ' | |
165 | ||
1b4aee94 | 166 | test_expect_success 'branch@{u} works when tracking a local branch' ' |
06d53148 JS |
167 | echo refs/heads/main >expect && |
168 | git -C clone rev-parse --symbolic-full-name local-main@{u} >actual && | |
5236fce6 | 169 | test_cmp expect actual |
1b4aee94 ZJS |
170 | ' |
171 | ||
172 | test_expect_success 'branch@{u} error message when no upstream' ' | |
173 | cat >expect <<-EOF && | |
bd482d6e | 174 | fatal: no upstream configured for branch ${SQ}non-tracking${SQ} |
1b4aee94 | 175 | EOF |
c3a44562 | 176 | error_message non-tracking@{u} && |
1108cea7 | 177 | test_cmp expect error |
1b4aee94 ZJS |
178 | ' |
179 | ||
180 | test_expect_success '@{u} error message when no upstream' ' | |
181 | cat >expect <<-EOF && | |
06d53148 | 182 | fatal: no upstream configured for branch ${SQ}main${SQ} |
1b4aee94 ZJS |
183 | EOF |
184 | test_must_fail git rev-parse --verify @{u} 2>actual && | |
1108cea7 | 185 | test_cmp expect actual |
1b4aee94 ZJS |
186 | ' |
187 | ||
dfbfdc52 FC |
188 | test_expect_success '@{u} silent error when no upstream' ' |
189 | test_must_fail git rev-parse --verify --quiet @{u} 2>actual && | |
190 | test_must_be_empty actual | |
191 | ' | |
192 | ||
1b4aee94 ZJS |
193 | test_expect_success 'branch@{u} error message with misspelt branch' ' |
194 | cat >expect <<-EOF && | |
bd482d6e | 195 | fatal: no such branch: ${SQ}no-such-branch${SQ} |
1b4aee94 | 196 | EOF |
c3a44562 | 197 | error_message no-such-branch@{u} && |
1108cea7 | 198 | test_cmp expect error |
1b4aee94 ZJS |
199 | ' |
200 | ||
201 | test_expect_success '@{u} error message when not on a branch' ' | |
202 | cat >expect <<-EOF && | |
17bf4ff3 | 203 | fatal: HEAD does not point to a branch |
1b4aee94 ZJS |
204 | EOF |
205 | git checkout HEAD^0 && | |
206 | test_must_fail git rev-parse --verify @{u} 2>actual && | |
1108cea7 | 207 | test_cmp expect actual |
1b4aee94 ZJS |
208 | ' |
209 | ||
210 | test_expect_success 'branch@{u} error message if upstream branch not fetched' ' | |
211 | cat >expect <<-EOF && | |
bd482d6e | 212 | fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch |
1b4aee94 | 213 | EOF |
c3a44562 | 214 | error_message bad-upstream@{u} && |
1108cea7 | 215 | test_cmp expect error |
1b4aee94 ZJS |
216 | ' |
217 | ||
218 | test_expect_success 'pull works when tracking a local branch' ' | |
219 | ( | |
220 | cd clone && | |
06d53148 | 221 | git checkout local-main && |
1b4aee94 ZJS |
222 | git pull |
223 | ) | |
224 | ' | |
225 | ||
226 | # makes sense if the previous one succeeded | |
227 | test_expect_success '@{u} works when tracking a local branch' ' | |
06d53148 | 228 | echo refs/heads/main >expect && |
b4417172 | 229 | git -C clone rev-parse --symbolic-full-name @{u} >actual && |
5236fce6 | 230 | test_cmp expect actual |
1b4aee94 ZJS |
231 | ' |
232 | ||
105e4733 | 233 | test_expect_success 'log -g other@{u}' ' |
9291e632 DL |
234 | commit=$(git rev-parse HEAD) && |
235 | cat >expect <<-EOF && | |
236 | commit $commit | |
06d53148 | 237 | Reflog: main@{0} (C O Mitter <committer@example.com>) |
9291e632 DL |
238 | Reflog message: branch: Created from HEAD |
239 | Author: A U Thor <author@example.com> | |
240 | Date: Thu Apr 7 15:15:13 2005 -0700 | |
241 | ||
242 | 3 | |
243 | EOF | |
105e4733 JH |
244 | git log -1 -g other@{u} >actual && |
245 | test_cmp expect actual | |
246 | ' | |
247 | ||
105e4733 | 248 | test_expect_success 'log -g other@{u}@{now}' ' |
9291e632 DL |
249 | commit=$(git rev-parse HEAD) && |
250 | cat >expect <<-EOF && | |
251 | commit $commit | |
06d53148 | 252 | Reflog: main@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>) |
9291e632 DL |
253 | Reflog message: branch: Created from HEAD |
254 | Author: A U Thor <author@example.com> | |
255 | Date: Thu Apr 7 15:15:13 2005 -0700 | |
256 | ||
257 | 3 | |
258 | EOF | |
105e4733 JH |
259 | git log -1 -g other@{u}@{now} >actual && |
260 | test_cmp expect actual | |
261 | ' | |
262 | ||
3f6eb30f JK |
263 | test_expect_success '@{reflog}-parsing does not look beyond colon' ' |
264 | echo content >@{yesterday} && | |
265 | git add @{yesterday} && | |
266 | git commit -m "funny reflog file" && | |
267 | git hash-object @{yesterday} >expect && | |
a93cbe8d AR |
268 | git rev-parse HEAD:@{yesterday} >actual && |
269 | test_cmp expect actual | |
3f6eb30f JK |
270 | ' |
271 | ||
272 | test_expect_success '@{upstream}-parsing does not look beyond colon' ' | |
273 | echo content >@{upstream} && | |
274 | git add @{upstream} && | |
275 | git commit -m "funny upstream file" && | |
276 | git hash-object @{upstream} >expect && | |
a93cbe8d AR |
277 | git rev-parse HEAD:@{upstream} >actual && |
278 | test_cmp expect actual | |
3f6eb30f JK |
279 | ' |
280 | ||
28fb8438 | 281 | test_done |