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