]>
Commit | Line | Data |
---|---|---|
d09e79cb LT |
1 | #!/bin/sh |
2 | ||
3 | test_description='pulling into void' | |
4 | ||
3ac8f630 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
d09e79cb LT |
8 | . ./test-lib.sh |
9 | ||
3cee9236 | 10 | modify () { |
4c8b046f | 11 | sed -e "$1" "$2" >"$2.x" && |
3cee9236 EN |
12 | mv "$2.x" "$2" |
13 | } | |
14 | ||
5c82bcdd | 15 | test_pull_autostash () { |
f8a17858 DL |
16 | expect_parent_num="$1" && |
17 | shift && | |
5c82bcdd MJ |
18 | git reset --hard before-rebase && |
19 | echo dirty >new_file && | |
20 | git add new_file && | |
21 | git pull "$@" . copy && | |
f8a17858 | 22 | test_cmp_rev HEAD^"$expect_parent_num" copy && |
a1a64fdd DL |
23 | echo dirty >expect && |
24 | test_cmp expect new_file && | |
25 | echo "modified again" >expect && | |
26 | test_cmp expect file | |
5c82bcdd MJ |
27 | } |
28 | ||
44a59fff MJ |
29 | test_pull_autostash_fail () { |
30 | git reset --hard before-rebase && | |
31 | echo dirty >new_file && | |
32 | git add new_file && | |
33 | test_must_fail git pull "$@" . copy 2>err && | |
c7033090 | 34 | test_i18ngrep -E "uncommitted changes.|overwritten by merge:" err |
44a59fff MJ |
35 | } |
36 | ||
d09e79cb | 37 | test_expect_success setup ' |
d09e79cb LT |
38 | echo file >file && |
39 | git add file && | |
40 | git commit -a -m original | |
d09e79cb LT |
41 | ' |
42 | ||
43 | test_expect_success 'pulling into void' ' | |
55691133 JH |
44 | git init cloned && |
45 | ( | |
46 | cd cloned && | |
47 | git pull .. | |
48 | ) && | |
ceeef863 DL |
49 | test_path_is_file file && |
50 | test_path_is_file cloned/file && | |
4fdf71be | 51 | test_cmp file cloned/file |
d09e79cb LT |
52 | ' |
53 | ||
3ac8f630 | 54 | test_expect_success 'pulling into void using main:main' ' |
55691133 | 55 | git init cloned-uho && |
b0ad11ea JH |
56 | ( |
57 | cd cloned-uho && | |
3ac8f630 | 58 | git pull .. main:main |
b0ad11ea | 59 | ) && |
ceeef863 DL |
60 | test_path_is_file file && |
61 | test_path_is_file cloned-uho/file && | |
b0ad11ea JH |
62 | test_cmp file cloned-uho/file |
63 | ' | |
64 | ||
4b3ffe51 JK |
65 | test_expect_success 'pulling into void does not overwrite untracked files' ' |
66 | git init cloned-untracked && | |
67 | ( | |
68 | cd cloned-untracked && | |
69 | echo untracked >file && | |
3ac8f630 | 70 | test_must_fail git pull .. main && |
4b3ffe51 JK |
71 | echo untracked >expect && |
72 | test_cmp expect file | |
73 | ) | |
74 | ' | |
75 | ||
b4dc085a TR |
76 | test_expect_success 'pulling into void does not overwrite staged files' ' |
77 | git init cloned-staged-colliding && | |
78 | ( | |
79 | cd cloned-staged-colliding && | |
80 | echo "alternate content" >file && | |
81 | git add file && | |
3ac8f630 | 82 | test_must_fail git pull .. main && |
b4dc085a TR |
83 | echo "alternate content" >expect && |
84 | test_cmp expect file && | |
85 | git cat-file blob :file >file.index && | |
86 | test_cmp expect file.index | |
87 | ) | |
88 | ' | |
89 | ||
b4dc085a TR |
90 | test_expect_success 'pulling into void does not remove new staged files' ' |
91 | git init cloned-staged-new && | |
92 | ( | |
93 | cd cloned-staged-new && | |
94 | echo "new tracked file" >newfile && | |
95 | git add newfile && | |
3ac8f630 | 96 | git pull .. main && |
b4dc085a TR |
97 | echo "new tracked file" >expect && |
98 | test_cmp expect newfile && | |
99 | git cat-file blob :newfile >newfile.index && | |
100 | test_cmp expect newfile.index | |
101 | ) | |
102 | ' | |
103 | ||
7ad39a27 JH |
104 | test_expect_success 'pulling into void must not create an octopus' ' |
105 | git init cloned-octopus && | |
106 | ( | |
107 | cd cloned-octopus && | |
3ac8f630 | 108 | test_must_fail git pull .. main main && |
ceeef863 | 109 | test_path_is_missing file |
7ad39a27 JH |
110 | ) |
111 | ' | |
112 | ||
9debc324 | 113 | test_expect_success 'test . as a remote' ' |
3ac8f630 | 114 | git branch copy main && |
9debc324 | 115 | git config branch.copy.remote . && |
3ac8f630 | 116 | git config branch.copy.merge refs/heads/main && |
9debc324 PB |
117 | echo updated >file && |
118 | git commit -a -m updated && | |
119 | git checkout copy && | |
a1a64fdd DL |
120 | echo file >expect && |
121 | test_cmp expect file && | |
9debc324 | 122 | git pull && |
a1a64fdd DL |
123 | echo updated >expect && |
124 | test_cmp expect file && | |
80ea984d PT |
125 | git reflog -1 >reflog.actual && |
126 | sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && | |
127 | echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected && | |
128 | test_cmp reflog.expected reflog.fuzzy | |
9debc324 PB |
129 | ' |
130 | ||
131 | test_expect_success 'the default remote . should not break explicit pull' ' | |
3ac8f630 | 132 | git checkout -b second main^ && |
9debc324 PB |
133 | echo modified >file && |
134 | git commit -a -m modified && | |
135 | git checkout copy && | |
136 | git reset --hard HEAD^ && | |
a1a64fdd DL |
137 | echo file >expect && |
138 | test_cmp expect file && | |
031e2f7a | 139 | git pull --no-rebase . second && |
a1a64fdd DL |
140 | echo modified >expect && |
141 | test_cmp expect file && | |
80ea984d PT |
142 | git reflog -1 >reflog.actual && |
143 | sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && | |
031e2f7a | 144 | echo "OBJID HEAD@{0}: pull --no-rebase . second: Fast-forward" >reflog.expected && |
80ea984d | 145 | test_cmp reflog.expected reflog.fuzzy |
9debc324 PB |
146 | ' |
147 | ||
d12f455e PT |
148 | test_expect_success 'fail if wildcard spec does not match any refs' ' |
149 | git checkout -b test copy^ && | |
150 | test_when_finished "git checkout -f copy && git branch -D test" && | |
a1a64fdd DL |
151 | echo file >expect && |
152 | test_cmp expect file && | |
d12f455e PT |
153 | test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err && |
154 | test_i18ngrep "no candidates for merging" err && | |
a1a64fdd | 155 | test_cmp expect file |
d12f455e PT |
156 | ' |
157 | ||
158 | test_expect_success 'fail if no branches specified with non-default remote' ' | |
159 | git remote add test_remote . && | |
160 | test_when_finished "git remote remove test_remote" && | |
161 | git checkout -b test copy^ && | |
162 | test_when_finished "git checkout -f copy && git branch -D test" && | |
a1a64fdd DL |
163 | echo file >expect && |
164 | test_cmp expect file && | |
d12f455e PT |
165 | test_config branch.test.remote origin && |
166 | test_must_fail git pull test_remote 2>err && | |
167 | test_i18ngrep "specify a branch on the command line" err && | |
a1a64fdd | 168 | test_cmp expect file |
d12f455e PT |
169 | ' |
170 | ||
171 | test_expect_success 'fail if not on a branch' ' | |
172 | git remote add origin . && | |
173 | test_when_finished "git remote remove origin" && | |
174 | git checkout HEAD^ && | |
175 | test_when_finished "git checkout -f copy" && | |
a1a64fdd DL |
176 | echo file >expect && |
177 | test_cmp expect file && | |
d12f455e PT |
178 | test_must_fail git pull 2>err && |
179 | test_i18ngrep "not currently on a branch" err && | |
a1a64fdd | 180 | test_cmp expect file |
d12f455e PT |
181 | ' |
182 | ||
183 | test_expect_success 'fail if no configuration for current branch' ' | |
184 | git remote add test_remote . && | |
185 | test_when_finished "git remote remove test_remote" && | |
186 | git checkout -b test copy^ && | |
187 | test_when_finished "git checkout -f copy && git branch -D test" && | |
188 | test_config branch.test.remote test_remote && | |
a1a64fdd DL |
189 | echo file >expect && |
190 | test_cmp expect file && | |
d12f455e PT |
191 | test_must_fail git pull 2>err && |
192 | test_i18ngrep "no tracking information" err && | |
a1a64fdd | 193 | test_cmp expect file |
d12f455e PT |
194 | ' |
195 | ||
eb2a8d9e PT |
196 | test_expect_success 'pull --all: fail if no configuration for current branch' ' |
197 | git remote add test_remote . && | |
198 | test_when_finished "git remote remove test_remote" && | |
199 | git checkout -b test copy^ && | |
200 | test_when_finished "git checkout -f copy && git branch -D test" && | |
201 | test_config branch.test.remote test_remote && | |
a1a64fdd DL |
202 | echo file >expect && |
203 | test_cmp expect file && | |
eb2a8d9e PT |
204 | test_must_fail git pull --all 2>err && |
205 | test_i18ngrep "There is no tracking information" err && | |
a1a64fdd | 206 | test_cmp expect file |
eb2a8d9e PT |
207 | ' |
208 | ||
d12f455e PT |
209 | test_expect_success 'fail if upstream branch does not exist' ' |
210 | git checkout -b test copy^ && | |
211 | test_when_finished "git checkout -f copy && git branch -D test" && | |
212 | test_config branch.test.remote . && | |
213 | test_config branch.test.merge refs/heads/nonexisting && | |
a1a64fdd DL |
214 | echo file >expect && |
215 | test_cmp expect file && | |
d12f455e PT |
216 | test_must_fail git pull 2>err && |
217 | test_i18ngrep "no such ref was fetched" err && | |
a1a64fdd | 218 | test_cmp expect file |
d12f455e PT |
219 | ' |
220 | ||
49ca2fba JK |
221 | test_expect_success 'fetch upstream branch even if refspec excludes it' ' |
222 | # the branch names are not important here except that | |
223 | # the first one must not be a prefix of the second, | |
224 | # since otherwise the ref-prefix protocol extension | |
225 | # would match both | |
226 | git branch in-refspec HEAD^ && | |
227 | git branch not-in-refspec HEAD && | |
228 | git init -b in-refspec downstream && | |
229 | git -C downstream remote add -t in-refspec origin "file://$(pwd)/.git" && | |
230 | git -C downstream config branch.in-refspec.remote origin && | |
231 | git -C downstream config branch.in-refspec.merge refs/heads/not-in-refspec && | |
232 | git -C downstream pull && | |
233 | git rev-parse --verify not-in-refspec >expect && | |
234 | git -C downstream rev-parse --verify HEAD >actual && | |
235 | test_cmp expect actual | |
236 | ' | |
237 | ||
05438afc PT |
238 | test_expect_success 'fail if the index has unresolved entries' ' |
239 | git checkout -b third second^ && | |
240 | test_when_finished "git checkout -f copy && git branch -D third" && | |
a1a64fdd DL |
241 | echo file >expect && |
242 | test_cmp expect file && | |
05438afc | 243 | test_commit modified2 file && |
979f8891 DL |
244 | git ls-files -u >unmerged && |
245 | test_must_be_empty unmerged && | |
031e2f7a | 246 | test_must_fail git pull --no-rebase . second && |
979f8891 DL |
247 | git ls-files -u >unmerged && |
248 | test_file_not_empty unmerged && | |
05438afc PT |
249 | cp file expected && |
250 | test_must_fail git pull . second 2>err && | |
8785c425 | 251 | test_i18ngrep "Pulling is not possible because you have unmerged files." err && |
05438afc PT |
252 | test_cmp expected file && |
253 | git add file && | |
979f8891 DL |
254 | git ls-files -u >unmerged && |
255 | test_must_be_empty unmerged && | |
05438afc PT |
256 | test_must_fail git pull . second 2>err && |
257 | test_i18ngrep "You have not concluded your merge" err && | |
258 | test_cmp expected file | |
259 | ' | |
260 | ||
9f992262 PT |
261 | test_expect_success 'fast-forwards working tree if branch head is updated' ' |
262 | git checkout -b third second^ && | |
263 | test_when_finished "git checkout -f copy && git branch -D third" && | |
a1a64fdd DL |
264 | echo file >expect && |
265 | test_cmp expect file && | |
9f992262 PT |
266 | git pull . second:third 2>err && |
267 | test_i18ngrep "fetch updated the current branch head" err && | |
a1a64fdd DL |
268 | echo modified >expect && |
269 | test_cmp expect file && | |
dd0f1e76 | 270 | test_cmp_rev third second |
9f992262 PT |
271 | ' |
272 | ||
273 | test_expect_success 'fast-forward fails with conflicting work tree' ' | |
274 | git checkout -b third second^ && | |
275 | test_when_finished "git checkout -f copy && git branch -D third" && | |
a1a64fdd DL |
276 | echo file >expect && |
277 | test_cmp expect file && | |
9f992262 PT |
278 | echo conflict >file && |
279 | test_must_fail git pull . second:third 2>err && | |
280 | test_i18ngrep "Cannot fast-forward your working tree" err && | |
a1a64fdd DL |
281 | echo conflict >expect && |
282 | test_cmp expect file && | |
dd0f1e76 | 283 | test_cmp_rev third second |
9f992262 PT |
284 | ' |
285 | ||
cd67e4d4 JS |
286 | test_expect_success '--rebase' ' |
287 | git branch to-rebase && | |
93a9bf87 | 288 | echo modified again >file && |
cd67e4d4 JS |
289 | git commit -m file file && |
290 | git checkout to-rebase && | |
93a9bf87 | 291 | echo new >file2 && |
cd67e4d4 JS |
292 | git add file2 && |
293 | git commit -m "new file" && | |
294 | git tag before-rebase && | |
295 | git pull --rebase . copy && | |
dd0f1e76 | 296 | test_cmp_rev HEAD^ copy && |
5540ed27 DL |
297 | echo new >expect && |
298 | git show HEAD:file2 >actual && | |
299 | test_cmp expect actual | |
cd67e4d4 | 300 | ' |
9570d67c | 301 | |
76340c81 | 302 | test_expect_success '--rebase (merge) fast forward' ' |
33b842a1 JH |
303 | git reset --hard before-rebase && |
304 | git checkout -b ff && | |
305 | echo another modification >file && | |
306 | git commit -m third file && | |
307 | ||
308 | git checkout to-rebase && | |
76340c81 EN |
309 | git -c rebase.backend=merge pull --rebase . ff && |
310 | test_cmp_rev HEAD ff && | |
311 | ||
312 | # The above only validates the result. Did we actually bypass rebase? | |
313 | git reflog -1 >reflog.actual && | |
314 | sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && | |
315 | echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected && | |
316 | test_cmp reflog.expected reflog.fuzzy | |
317 | ' | |
318 | ||
319 | test_expect_success '--rebase (am) fast forward' ' | |
320 | git reset --hard before-rebase && | |
321 | ||
10cdb9f3 | 322 | git -c rebase.backend=apply pull --rebase . ff && |
dd0f1e76 | 323 | test_cmp_rev HEAD ff && |
33b842a1 JH |
324 | |
325 | # The above only validates the result. Did we actually bypass rebase? | |
326 | git reflog -1 >reflog.actual && | |
327 | sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && | |
328 | echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected && | |
329 | test_cmp reflog.expected reflog.fuzzy | |
330 | ' | |
331 | ||
f15e7cf5 TB |
332 | test_expect_success '--rebase --autostash fast forward' ' |
333 | test_when_finished " | |
334 | git reset --hard | |
335 | git checkout to-rebase | |
336 | git branch -D to-rebase-ff | |
337 | git branch -D behind" && | |
338 | git branch behind && | |
339 | git checkout -b to-rebase-ff && | |
340 | echo another modification >>file && | |
341 | git add file && | |
342 | git commit -m mod && | |
343 | ||
344 | git checkout behind && | |
345 | echo dirty >file && | |
346 | git pull --rebase --autostash . to-rebase-ff && | |
dd0f1e76 | 347 | test_cmp_rev HEAD to-rebase-ff |
f15e7cf5 TB |
348 | ' |
349 | ||
3013d98d PB |
350 | test_expect_success '--rebase with rebase.autostash succeeds on ff' ' |
351 | test_when_finished "rm -fr src dst actual" && | |
352 | git init src && | |
353 | test_commit -C src "initial" file "content" && | |
354 | git clone src dst && | |
355 | test_commit -C src --printf "more_content" file "more content\ncontent\n" && | |
356 | echo "dirty" >>dst/file && | |
357 | test_config -C dst rebase.autostash true && | |
358 | git -C dst pull --rebase >actual 2>&1 && | |
359 | grep -q "Fast-forward" actual && | |
360 | grep -q "Applied autostash." actual | |
361 | ' | |
362 | ||
3be18b47 JS |
363 | test_expect_success '--rebase with conflicts shows advice' ' |
364 | test_when_finished "git rebase --abort; git checkout -f to-rebase" && | |
365 | git checkout -b seq && | |
366 | test_seq 5 >seq.txt && | |
367 | git add seq.txt && | |
368 | test_tick && | |
369 | git commit -m "Add seq.txt" && | |
370 | echo 6 >>seq.txt && | |
371 | test_tick && | |
372 | git commit -m "Append to seq.txt" seq.txt && | |
373 | git checkout -b with-conflicts HEAD^ && | |
374 | echo conflicting >>seq.txt && | |
375 | test_tick && | |
376 | git commit -m "Create conflict" seq.txt && | |
377 | test_must_fail git pull --rebase . seq 2>err >out && | |
2ac0d627 | 378 | test_i18ngrep "Resolve all conflicts manually" err |
3be18b47 JS |
379 | ' |
380 | ||
381 | test_expect_success 'failed --rebase shows advice' ' | |
382 | test_when_finished "git rebase --abort; git checkout -f to-rebase" && | |
383 | git checkout -b diverging && | |
384 | test_commit attributes .gitattributes "* text=auto" attrs && | |
385 | sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" && | |
386 | git update-index --cacheinfo 0644 $sha1 file && | |
387 | git commit -m v1-with-cr && | |
388 | # force checkout because `git reset --hard` will not leave clean `file` | |
389 | git checkout -f -b fails-to-rebase HEAD^ && | |
390 | test_commit v2-without-cr file "2" file2-lf && | |
391 | test_must_fail git pull --rebase . diverging 2>err >out && | |
2ac0d627 | 392 | test_i18ngrep "Resolve all conflicts manually" err |
3be18b47 JS |
393 | ' |
394 | ||
9570d67c PT |
395 | test_expect_success '--rebase fails with multiple branches' ' |
396 | git reset --hard before-rebase && | |
3ac8f630 | 397 | test_must_fail git pull --rebase . copy main 2>err && |
dd0f1e76 | 398 | test_cmp_rev HEAD before-rebase && |
9570d67c | 399 | test_i18ngrep "Cannot rebase onto multiple branches" err && |
5540ed27 DL |
400 | echo modified >expect && |
401 | git show HEAD:file >actual && | |
402 | test_cmp expect actual | |
9570d67c PT |
403 | ' |
404 | ||
53c76dc0 KD |
405 | test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' ' |
406 | test_config rebase.autostash true && | |
f8a17858 | 407 | test_pull_autostash 1 --rebase |
53c76dc0 KD |
408 | ' |
409 | ||
f66398eb MJ |
410 | test_expect_success 'pull --rebase --autostash & rebase.autostash=true' ' |
411 | test_config rebase.autostash true && | |
f8a17858 | 412 | test_pull_autostash 1 --rebase --autostash |
f66398eb MJ |
413 | ' |
414 | ||
efa195d5 | 415 | test_expect_success 'pull --rebase --autostash & rebase.autostash=false' ' |
f66398eb | 416 | test_config rebase.autostash false && |
f8a17858 | 417 | test_pull_autostash 1 --rebase --autostash |
f66398eb MJ |
418 | ' |
419 | ||
5c82bcdd | 420 | test_expect_success 'pull --rebase --autostash & rebase.autostash unset' ' |
eff960b3 | 421 | test_unconfig rebase.autostash && |
f8a17858 | 422 | test_pull_autostash 1 --rebase --autostash |
f66398eb MJ |
423 | ' |
424 | ||
425 | test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' ' | |
426 | test_config rebase.autostash true && | |
44a59fff | 427 | test_pull_autostash_fail --rebase --no-autostash |
f66398eb MJ |
428 | ' |
429 | ||
430 | test_expect_success 'pull --rebase --no-autostash & rebase.autostash=false' ' | |
431 | test_config rebase.autostash false && | |
44a59fff | 432 | test_pull_autostash_fail --rebase --no-autostash |
f66398eb MJ |
433 | ' |
434 | ||
435 | test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' ' | |
eff960b3 | 436 | test_unconfig rebase.autostash && |
44a59fff | 437 | test_pull_autostash_fail --rebase --no-autostash |
f66398eb MJ |
438 | ' |
439 | ||
d9f15d37 DL |
440 | test_expect_success 'pull succeeds with dirty working directory and merge.autostash set' ' |
441 | test_config merge.autostash true && | |
031e2f7a | 442 | test_pull_autostash 2 --no-rebase |
d9f15d37 DL |
443 | ' |
444 | ||
445 | test_expect_success 'pull --autostash & merge.autostash=true' ' | |
446 | test_config merge.autostash true && | |
031e2f7a | 447 | test_pull_autostash 2 --autostash --no-rebase |
d9f15d37 DL |
448 | ' |
449 | ||
450 | test_expect_success 'pull --autostash & merge.autostash=false' ' | |
451 | test_config merge.autostash false && | |
031e2f7a | 452 | test_pull_autostash 2 --autostash --no-rebase |
d9f15d37 DL |
453 | ' |
454 | ||
455 | test_expect_success 'pull --autostash & merge.autostash unset' ' | |
456 | test_unconfig merge.autostash && | |
031e2f7a | 457 | test_pull_autostash 2 --autostash --no-rebase |
d9f15d37 DL |
458 | ' |
459 | ||
460 | test_expect_success 'pull --no-autostash & merge.autostash=true' ' | |
461 | test_config merge.autostash true && | |
031e2f7a | 462 | test_pull_autostash_fail --no-autostash --no-rebase |
d9f15d37 DL |
463 | ' |
464 | ||
465 | test_expect_success 'pull --no-autostash & merge.autostash=false' ' | |
466 | test_config merge.autostash false && | |
031e2f7a | 467 | test_pull_autostash_fail --no-autostash --no-rebase |
d9f15d37 DL |
468 | ' |
469 | ||
470 | test_expect_success 'pull --no-autostash & merge.autostash unset' ' | |
471 | test_unconfig merge.autostash && | |
031e2f7a | 472 | test_pull_autostash_fail --no-autostash --no-rebase |
d9f15d37 | 473 | ' |
f66398eb | 474 | |
6b37dff1 ÆAB |
475 | test_expect_success 'pull.rebase' ' |
476 | git reset --hard before-rebase && | |
9d6aa64d | 477 | test_config pull.rebase true && |
6b37dff1 | 478 | git pull . copy && |
dd0f1e76 | 479 | test_cmp_rev HEAD^ copy && |
5540ed27 DL |
480 | echo new >expect && |
481 | git show HEAD:file2 >actual && | |
482 | test_cmp expect actual | |
6b37dff1 | 483 | ' |
cd67e4d4 | 484 | |
450dd1dc MJ |
485 | test_expect_success 'pull --autostash & pull.rebase=true' ' |
486 | test_config pull.rebase true && | |
f8a17858 | 487 | test_pull_autostash 1 --autostash |
450dd1dc MJ |
488 | ' |
489 | ||
490 | test_expect_success 'pull --no-autostash & pull.rebase=true' ' | |
491 | test_config pull.rebase true && | |
492 | test_pull_autostash_fail --no-autostash | |
493 | ' | |
494 | ||
cd67e4d4 JS |
495 | test_expect_success 'branch.to-rebase.rebase' ' |
496 | git reset --hard before-rebase && | |
9d6aa64d | 497 | test_config branch.to-rebase.rebase true && |
cd67e4d4 | 498 | git pull . copy && |
dd0f1e76 | 499 | test_cmp_rev HEAD^ copy && |
5540ed27 DL |
500 | echo new >expect && |
501 | git show HEAD:file2 >actual && | |
502 | test_cmp expect actual | |
cd67e4d4 JS |
503 | ' |
504 | ||
6b37dff1 ÆAB |
505 | test_expect_success 'branch.to-rebase.rebase should override pull.rebase' ' |
506 | git reset --hard before-rebase && | |
9d6aa64d YD |
507 | test_config pull.rebase true && |
508 | test_config branch.to-rebase.rebase false && | |
6b37dff1 | 509 | git pull . copy && |
dd0f1e76 | 510 | test_cmp_rev ! HEAD^ copy && |
5540ed27 DL |
511 | echo new >expect && |
512 | git show HEAD:file2 >actual && | |
513 | test_cmp expect actual | |
6b37dff1 ÆAB |
514 | ' |
515 | ||
53c62b98 | 516 | test_expect_success 'pull --rebase warns on --verify-signatures' ' |
c57e501c AH |
517 | git reset --hard before-rebase && |
518 | git pull --rebase --verify-signatures . copy 2>err && | |
dd0f1e76 | 519 | test_cmp_rev HEAD^ copy && |
5540ed27 DL |
520 | echo new >expect && |
521 | git show HEAD:file2 >actual && | |
522 | test_cmp expect actual && | |
c57e501c AH |
523 | test_i18ngrep "ignoring --verify-signatures for rebase" err |
524 | ' | |
525 | ||
53c62b98 | 526 | test_expect_success 'pull --rebase does not warn on --no-verify-signatures' ' |
c57e501c AH |
527 | git reset --hard before-rebase && |
528 | git pull --rebase --no-verify-signatures . copy 2>err && | |
dd0f1e76 | 529 | test_cmp_rev HEAD^ copy && |
5540ed27 DL |
530 | echo new >expect && |
531 | git show HEAD:file2 >actual && | |
532 | test_cmp expect actual && | |
c57e501c AH |
533 | test_i18ngrep ! "verify-signatures" err |
534 | ' | |
535 | ||
3ac8f630 | 536 | # add a feature branch, keep-merge, that is merged into main, so the |
66713ef3 SH |
537 | # test can try preserving the merge commit (or not) with various |
538 | # --rebase flags/pull.rebase settings. | |
539 | test_expect_success 'preserve merge setup' ' | |
540 | git reset --hard before-rebase && | |
541 | git checkout -b keep-merge second^ && | |
542 | test_commit file3 && | |
543 | git checkout to-rebase && | |
544 | git merge keep-merge && | |
545 | git tag before-preserve-rebase | |
546 | ' | |
547 | ||
548 | test_expect_success 'pull.rebase=false create a new merge commit' ' | |
549 | git reset --hard before-preserve-rebase && | |
550 | test_config pull.rebase false && | |
551 | git pull . copy && | |
dd0f1e76 DL |
552 | test_cmp_rev HEAD^1 before-preserve-rebase && |
553 | test_cmp_rev HEAD^2 copy && | |
5540ed27 DL |
554 | echo file3 >expect && |
555 | git show HEAD:file3.t >actual && | |
556 | test_cmp expect actual | |
66713ef3 SH |
557 | ' |
558 | ||
559 | test_expect_success 'pull.rebase=true flattens keep-merge' ' | |
560 | git reset --hard before-preserve-rebase && | |
561 | test_config pull.rebase true && | |
562 | git pull . copy && | |
dd0f1e76 | 563 | test_cmp_rev HEAD^^ copy && |
5540ed27 DL |
564 | echo file3 >expect && |
565 | git show HEAD:file3.t >actual && | |
566 | test_cmp expect actual | |
66713ef3 SH |
567 | ' |
568 | ||
569 | test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' ' | |
570 | git reset --hard before-preserve-rebase && | |
571 | test_config pull.rebase 1 && | |
572 | git pull . copy && | |
dd0f1e76 | 573 | test_cmp_rev HEAD^^ copy && |
5540ed27 DL |
574 | echo file3 >expect && |
575 | git show HEAD:file3.t >actual && | |
576 | test_cmp expect actual | |
66713ef3 SH |
577 | ' |
578 | ||
f5eb87b9 JS |
579 | test_expect_success 'pull.rebase=interactive' ' |
580 | write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF && | |
581 | echo I was here >fake.out && | |
582 | false | |
583 | EOF | |
584 | test_set_editor "$TRASH_DIRECTORY/fake-editor" && | |
46af44b0 | 585 | test_when_finished "test_might_fail git rebase --abort" && |
f5eb87b9 | 586 | test_must_fail git pull --rebase=interactive . copy && |
a1a64fdd DL |
587 | echo "I was here" >expect && |
588 | test_cmp expect fake.out | |
f5eb87b9 JS |
589 | ' |
590 | ||
46af44b0 JS |
591 | test_expect_success 'pull --rebase=i' ' |
592 | write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF && | |
593 | echo I was here, too >fake.out && | |
594 | false | |
595 | EOF | |
596 | test_set_editor "$TRASH_DIRECTORY/fake-editor" && | |
597 | test_when_finished "test_might_fail git rebase --abort" && | |
598 | test_must_fail git pull --rebase=i . copy && | |
a1a64fdd DL |
599 | echo "I was here, too" >expect && |
600 | test_cmp expect fake.out | |
46af44b0 JS |
601 | ' |
602 | ||
66713ef3 SH |
603 | test_expect_success 'pull.rebase=invalid fails' ' |
604 | git reset --hard before-preserve-rebase && | |
605 | test_config pull.rebase invalid && | |
2a022620 | 606 | test_must_fail git pull . copy |
66713ef3 SH |
607 | ' |
608 | ||
609 | test_expect_success '--rebase=false create a new merge commit' ' | |
610 | git reset --hard before-preserve-rebase && | |
611 | test_config pull.rebase true && | |
612 | git pull --rebase=false . copy && | |
dd0f1e76 DL |
613 | test_cmp_rev HEAD^1 before-preserve-rebase && |
614 | test_cmp_rev HEAD^2 copy && | |
5540ed27 DL |
615 | echo file3 >expect && |
616 | git show HEAD:file3.t >actual && | |
617 | test_cmp expect actual | |
66713ef3 SH |
618 | ' |
619 | ||
620 | test_expect_success '--rebase=true rebases and flattens keep-merge' ' | |
621 | git reset --hard before-preserve-rebase && | |
6df8755c | 622 | test_config pull.rebase merges && |
66713ef3 | 623 | git pull --rebase=true . copy && |
dd0f1e76 | 624 | test_cmp_rev HEAD^^ copy && |
5540ed27 DL |
625 | echo file3 >expect && |
626 | git show HEAD:file3.t >actual && | |
627 | test_cmp expect actual | |
66713ef3 SH |
628 | ' |
629 | ||
66713ef3 SH |
630 | test_expect_success '--rebase=invalid fails' ' |
631 | git reset --hard before-preserve-rebase && | |
2a022620 | 632 | test_must_fail git pull --rebase=invalid . copy |
66713ef3 SH |
633 | ' |
634 | ||
6df8755c | 635 | test_expect_success '--rebase overrides pull.rebase=merges and flattens keep-merge' ' |
66713ef3 | 636 | git reset --hard before-preserve-rebase && |
6df8755c | 637 | test_config pull.rebase merges && |
66713ef3 | 638 | git pull --rebase . copy && |
dd0f1e76 | 639 | test_cmp_rev HEAD^^ copy && |
5540ed27 DL |
640 | echo file3 >expect && |
641 | git show HEAD:file3.t >actual && | |
642 | test_cmp expect actual | |
66713ef3 SH |
643 | ' |
644 | ||
c85c7927 | 645 | test_expect_success '--rebase with rebased upstream' ' |
c85c7927 JS |
646 | git remote add -f me . && |
647 | git checkout copy && | |
e9460a66 | 648 | git tag copy-orig && |
c85c7927 | 649 | git reset --hard HEAD^ && |
93a9bf87 | 650 | echo conflicting modification >file && |
c85c7927 JS |
651 | git commit -m conflict file && |
652 | git checkout to-rebase && | |
93a9bf87 | 653 | echo file >file2 && |
c85c7927 | 654 | git commit -m to-rebase file2 && |
e9460a66 | 655 | git tag to-rebase-orig && |
c85c7927 | 656 | git pull --rebase me copy && |
a1a64fdd DL |
657 | echo "conflicting modification" >expect && |
658 | test_cmp expect file && | |
659 | echo file >expect && | |
660 | test_cmp expect file2 | |
c85c7927 JS |
661 | ' |
662 | ||
eb2a8d9e PT |
663 | test_expect_success '--rebase -f with rebased upstream' ' |
664 | test_when_finished "test_might_fail git rebase --abort" && | |
665 | git reset --hard to-rebase-orig && | |
666 | git pull --rebase -f me copy && | |
a1a64fdd DL |
667 | echo "conflicting modification" >expect && |
668 | test_cmp expect file && | |
669 | echo file >expect && | |
670 | test_cmp expect file2 | |
eb2a8d9e PT |
671 | ' |
672 | ||
e9460a66 | 673 | test_expect_success '--rebase with rebased default upstream' ' |
e9460a66 SB |
674 | git update-ref refs/remotes/me/copy copy-orig && |
675 | git checkout --track -b to-rebase2 me/copy && | |
676 | git reset --hard to-rebase-orig && | |
677 | git pull --rebase && | |
a1a64fdd DL |
678 | echo "conflicting modification" >expect && |
679 | test_cmp expect file && | |
680 | echo file >expect && | |
681 | test_cmp expect file2 | |
e9460a66 SB |
682 | ' |
683 | ||
d44e7126 | 684 | test_expect_success 'rebased upstream + fetch + pull --rebase' ' |
a418441b SB |
685 | |
686 | git update-ref refs/remotes/me/copy copy-orig && | |
687 | git reset --hard to-rebase-orig && | |
688 | git checkout --track -b to-rebase3 me/copy && | |
689 | git reset --hard to-rebase-orig && | |
690 | git fetch && | |
d44e7126 | 691 | git pull --rebase && |
a1a64fdd DL |
692 | echo "conflicting modification" >expect && |
693 | test_cmp expect file && | |
694 | echo file >expect && | |
695 | test_cmp expect file2 | |
a418441b SB |
696 | |
697 | ' | |
698 | ||
f9189cf8 | 699 | test_expect_success 'pull --rebase dies early with dirty working directory' ' |
e9460a66 | 700 | git checkout to-rebase && |
f9189cf8 | 701 | git update-ref refs/remotes/me/copy copy^ && |
c998b381 | 702 | COPY="$(git rev-parse --verify me/copy)" && |
f9189cf8 | 703 | git rebase --onto $COPY copy && |
790f2827 RR |
704 | test_config branch.to-rebase.remote me && |
705 | test_config branch.to-rebase.merge refs/heads/copy && | |
706 | test_config branch.to-rebase.rebase true && | |
93a9bf87 | 707 | echo dirty >>file && |
f9189cf8 JS |
708 | git add file && |
709 | test_must_fail git pull && | |
dd0f1e76 | 710 | test_cmp_rev "$COPY" me/copy && |
f9189cf8 JS |
711 | git checkout HEAD -- file && |
712 | git pull && | |
dd0f1e76 | 713 | test_cmp_rev ! "$COPY" me/copy |
f9189cf8 JS |
714 | ' |
715 | ||
19a7fcbf | 716 | test_expect_success 'pull --rebase works on branch yet to be born' ' |
3ac8f630 | 717 | git rev-parse main >expect && |
19a7fcbf | 718 | mkdir empty_repo && |
e8d1eaf9 DL |
719 | ( |
720 | cd empty_repo && | |
721 | git init && | |
3ac8f630 | 722 | git pull --rebase .. main && |
e8d1eaf9 | 723 | git rev-parse HEAD >../actual |
19a7fcbf JK |
724 | ) && |
725 | test_cmp expect actual | |
726 | ' | |
727 | ||
fa14ee77 PT |
728 | test_expect_success 'pull --rebase fails on unborn branch with staged changes' ' |
729 | test_when_finished "rm -rf empty_repo2" && | |
730 | git init empty_repo2 && | |
731 | ( | |
732 | cd empty_repo2 && | |
733 | echo staged-file >staged-file && | |
734 | git add staged-file && | |
5540ed27 DL |
735 | echo staged-file >expect && |
736 | git ls-files >actual && | |
737 | test_cmp expect actual && | |
3ac8f630 | 738 | test_must_fail git pull --rebase .. main 2>err && |
5540ed27 DL |
739 | git ls-files >actual && |
740 | test_cmp expect actual && | |
5540ed27 DL |
741 | git show :staged-file >actual && |
742 | test_cmp expect actual && | |
fa14ee77 PT |
743 | test_i18ngrep "unborn branch with changes added to the index" err |
744 | ) | |
745 | ' | |
746 | ||
3506dc94 JK |
747 | test_expect_success 'pull --rebase fails on corrupt HEAD' ' |
748 | test_when_finished "rm -rf corrupt" && | |
749 | git init corrupt && | |
750 | ( | |
751 | cd corrupt && | |
752 | test_commit one && | |
e959a18e DL |
753 | git rev-parse --verify HEAD >head && |
754 | obj=$(sed "s#^..#&/#" head) && | |
3506dc94 JK |
755 | rm -f .git/objects/$obj && |
756 | test_must_fail git pull --rebase | |
757 | ) | |
758 | ' | |
759 | ||
3cee9236 | 760 | test_expect_success 'setup for detecting upstreamed changes' ' |
47c88d16 ÆAB |
761 | test_create_repo src && |
762 | test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" && | |
3cee9236 | 763 | git clone src dst && |
e8d1eaf9 DL |
764 | ( |
765 | cd src && | |
766 | modify s/5/43/ stuff && | |
767 | git commit -a -m "5->43" && | |
768 | modify s/6/42/ stuff && | |
769 | git commit -a -m "Make it bigger" | |
3cee9236 | 770 | ) && |
e8d1eaf9 DL |
771 | ( |
772 | cd dst && | |
773 | modify s/5/43/ stuff && | |
774 | git commit -a -m "Independent discovery of 5->43" | |
3cee9236 EN |
775 | ) |
776 | ' | |
777 | ||
cf65426d | 778 | test_expect_success 'git pull --rebase detects upstreamed changes' ' |
e8d1eaf9 DL |
779 | ( |
780 | cd dst && | |
781 | git pull --rebase && | |
979f8891 DL |
782 | git ls-files -u >untracked && |
783 | test_must_be_empty untracked | |
3cee9236 EN |
784 | ) |
785 | ' | |
786 | ||
787 | test_expect_success 'setup for avoiding reapplying old patches' ' | |
e8d1eaf9 DL |
788 | ( |
789 | cd dst && | |
790 | test_might_fail git rebase --abort && | |
3ac8f630 | 791 | git reset --hard origin/main |
3cee9236 EN |
792 | ) && |
793 | git clone --bare src src-replace.git && | |
794 | rm -rf src && | |
795 | mv src-replace.git src && | |
e8d1eaf9 DL |
796 | ( |
797 | cd dst && | |
798 | modify s/2/22/ stuff && | |
799 | git commit -a -m "Change 2" && | |
800 | modify s/3/33/ stuff && | |
801 | git commit -a -m "Change 3" && | |
802 | modify s/4/44/ stuff && | |
803 | git commit -a -m "Change 4" && | |
804 | git push && | |
805 | ||
806 | modify s/44/55/ stuff && | |
807 | git commit --amend -a -m "Modified Change 4" | |
3cee9236 EN |
808 | ) |
809 | ' | |
810 | ||
cf65426d | 811 | test_expect_success 'git pull --rebase does not reapply old patches' ' |
e8d1eaf9 DL |
812 | ( |
813 | cd dst && | |
814 | test_must_fail git pull --rebase && | |
2ac0d627 EN |
815 | cat .git/rebase-merge/done .git/rebase-merge/git-rebase-todo >work && |
816 | grep -v -e \# -e ^$ work >patches && | |
817 | test_line_count = 1 patches && | |
818 | rm -f work | |
3cee9236 EN |
819 | ) |
820 | ' | |
821 | ||
fe249b42 MZ |
822 | test_expect_success 'git pull --rebase against local branch' ' |
823 | git checkout -b copy2 to-rebase-orig && | |
824 | git pull --rebase . to-rebase && | |
a1a64fdd DL |
825 | echo "conflicting modification" >expect && |
826 | test_cmp expect file && | |
827 | echo file >expect && | |
828 | test_cmp expect file2 | |
fe249b42 MZ |
829 | ' |
830 | ||
d09e79cb | 831 | test_done |