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