builtin: patch-id: add --verbatim as a command mode
[git/debian.git] / t / t5520-pull.sh
blob081808009b2e74aa4cb81a768a15701dd4eca9d5
1 #!/bin/sh
3 test_description='pulling into void'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 modify () {
11 sed -e "$1" "$2" >"$2.x" &&
12 mv "$2.x" "$2"
15 test_pull_autostash () {
16 expect_parent_num="$1" &&
17 shift &&
18 git reset --hard before-rebase &&
19 echo dirty >new_file &&
20 git add new_file &&
21 git pull "$@" . copy &&
22 test_cmp_rev HEAD^"$expect_parent_num" copy &&
23 echo dirty >expect &&
24 test_cmp expect new_file &&
25 echo "modified again" >expect &&
26 test_cmp expect file
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 &&
34 test_i18ngrep -E "uncommitted changes.|overwritten by merge:" err
37 test_expect_success setup '
38 echo file >file &&
39 git add file &&
40 git commit -a -m original
43 test_expect_success 'pulling into void' '
44 git init cloned &&
46 cd cloned &&
47 git pull ..
48 ) &&
49 test_path_is_file file &&
50 test_path_is_file cloned/file &&
51 test_cmp file cloned/file
54 test_expect_success 'pulling into void using main:main' '
55 git init cloned-uho &&
57 cd cloned-uho &&
58 git pull .. main:main
59 ) &&
60 test_path_is_file file &&
61 test_path_is_file cloned-uho/file &&
62 test_cmp file cloned-uho/file
65 test_expect_success 'pulling into void does not overwrite untracked files' '
66 git init cloned-untracked &&
68 cd cloned-untracked &&
69 echo untracked >file &&
70 test_must_fail git pull .. main &&
71 echo untracked >expect &&
72 test_cmp expect file
76 test_expect_success 'pulling into void does not overwrite staged files' '
77 git init cloned-staged-colliding &&
79 cd cloned-staged-colliding &&
80 echo "alternate content" >file &&
81 git add file &&
82 test_must_fail git pull .. main &&
83 echo "alternate content" >expect &&
84 test_cmp expect file &&
85 git cat-file blob :file >file.index &&
86 test_cmp expect file.index
90 test_expect_success 'pulling into void does not remove new staged files' '
91 git init cloned-staged-new &&
93 cd cloned-staged-new &&
94 echo "new tracked file" >newfile &&
95 git add newfile &&
96 git pull .. main &&
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
104 test_expect_success 'pulling into void must not create an octopus' '
105 git init cloned-octopus &&
107 cd cloned-octopus &&
108 test_must_fail git pull .. main main &&
109 test_path_is_missing file
113 test_expect_success 'test . as a remote' '
114 git branch copy main &&
115 git config branch.copy.remote . &&
116 git config branch.copy.merge refs/heads/main &&
117 echo updated >file &&
118 git commit -a -m updated &&
119 git checkout copy &&
120 echo file >expect &&
121 test_cmp expect file &&
122 git pull &&
123 echo updated >expect &&
124 test_cmp expect file &&
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
131 test_expect_success 'the default remote . should not break explicit pull' '
132 git checkout -b second main^ &&
133 echo modified >file &&
134 git commit -a -m modified &&
135 git checkout copy &&
136 git reset --hard HEAD^ &&
137 echo file >expect &&
138 test_cmp expect file &&
139 git pull --no-rebase . second &&
140 echo modified >expect &&
141 test_cmp expect file &&
142 git reflog -1 >reflog.actual &&
143 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
144 echo "OBJID HEAD@{0}: pull --no-rebase . second: Fast-forward" >reflog.expected &&
145 test_cmp reflog.expected reflog.fuzzy
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" &&
151 echo file >expect &&
152 test_cmp expect file &&
153 test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
154 test_i18ngrep "no candidates for merging" err &&
155 test_cmp expect file
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" &&
163 echo file >expect &&
164 test_cmp expect file &&
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 &&
168 test_cmp expect file
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" &&
176 echo file >expect &&
177 test_cmp expect file &&
178 test_must_fail git pull 2>err &&
179 test_i18ngrep "not currently on a branch" err &&
180 test_cmp expect file
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 &&
189 echo file >expect &&
190 test_cmp expect file &&
191 test_must_fail git pull 2>err &&
192 test_i18ngrep "no tracking information" err &&
193 test_cmp expect file
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 &&
202 echo file >expect &&
203 test_cmp expect file &&
204 test_must_fail git pull --all 2>err &&
205 test_i18ngrep "There is no tracking information" err &&
206 test_cmp expect file
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 &&
214 echo file >expect &&
215 test_cmp expect file &&
216 test_must_fail git pull 2>err &&
217 test_i18ngrep "no such ref was fetched" err &&
218 test_cmp expect file
221 test_expect_success 'fail if the index has unresolved entries' '
222 git checkout -b third second^ &&
223 test_when_finished "git checkout -f copy && git branch -D third" &&
224 echo file >expect &&
225 test_cmp expect file &&
226 test_commit modified2 file &&
227 git ls-files -u >unmerged &&
228 test_must_be_empty unmerged &&
229 test_must_fail git pull --no-rebase . second &&
230 git ls-files -u >unmerged &&
231 test_file_not_empty unmerged &&
232 cp file expected &&
233 test_must_fail git pull . second 2>err &&
234 test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
235 test_cmp expected file &&
236 git add file &&
237 git ls-files -u >unmerged &&
238 test_must_be_empty unmerged &&
239 test_must_fail git pull . second 2>err &&
240 test_i18ngrep "You have not concluded your merge" err &&
241 test_cmp expected file
244 test_expect_success 'fast-forwards working tree if branch head is updated' '
245 git checkout -b third second^ &&
246 test_when_finished "git checkout -f copy && git branch -D third" &&
247 echo file >expect &&
248 test_cmp expect file &&
249 git pull . second:third 2>err &&
250 test_i18ngrep "fetch updated the current branch head" err &&
251 echo modified >expect &&
252 test_cmp expect file &&
253 test_cmp_rev third second
256 test_expect_success 'fast-forward fails with conflicting work tree' '
257 git checkout -b third second^ &&
258 test_when_finished "git checkout -f copy && git branch -D third" &&
259 echo file >expect &&
260 test_cmp expect file &&
261 echo conflict >file &&
262 test_must_fail git pull . second:third 2>err &&
263 test_i18ngrep "Cannot fast-forward your working tree" err &&
264 echo conflict >expect &&
265 test_cmp expect file &&
266 test_cmp_rev third second
269 test_expect_success '--rebase' '
270 git branch to-rebase &&
271 echo modified again >file &&
272 git commit -m file file &&
273 git checkout to-rebase &&
274 echo new >file2 &&
275 git add file2 &&
276 git commit -m "new file" &&
277 git tag before-rebase &&
278 git pull --rebase . copy &&
279 test_cmp_rev HEAD^ copy &&
280 echo new >expect &&
281 git show HEAD:file2 >actual &&
282 test_cmp expect actual
285 test_expect_success '--rebase (merge) fast forward' '
286 git reset --hard before-rebase &&
287 git checkout -b ff &&
288 echo another modification >file &&
289 git commit -m third file &&
291 git checkout to-rebase &&
292 git -c rebase.backend=merge pull --rebase . ff &&
293 test_cmp_rev HEAD ff &&
295 # The above only validates the result. Did we actually bypass rebase?
296 git reflog -1 >reflog.actual &&
297 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
298 echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected &&
299 test_cmp reflog.expected reflog.fuzzy
302 test_expect_success '--rebase (am) fast forward' '
303 git reset --hard before-rebase &&
305 git -c rebase.backend=apply pull --rebase . ff &&
306 test_cmp_rev HEAD ff &&
308 # The above only validates the result. Did we actually bypass rebase?
309 git reflog -1 >reflog.actual &&
310 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
311 echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected &&
312 test_cmp reflog.expected reflog.fuzzy
315 test_expect_success '--rebase --autostash fast forward' '
316 test_when_finished "
317 git reset --hard
318 git checkout to-rebase
319 git branch -D to-rebase-ff
320 git branch -D behind" &&
321 git branch behind &&
322 git checkout -b to-rebase-ff &&
323 echo another modification >>file &&
324 git add file &&
325 git commit -m mod &&
327 git checkout behind &&
328 echo dirty >file &&
329 git pull --rebase --autostash . to-rebase-ff &&
330 test_cmp_rev HEAD to-rebase-ff
333 test_expect_success '--rebase with rebase.autostash succeeds on ff' '
334 test_when_finished "rm -fr src dst actual" &&
335 git init src &&
336 test_commit -C src "initial" file "content" &&
337 git clone src dst &&
338 test_commit -C src --printf "more_content" file "more content\ncontent\n" &&
339 echo "dirty" >>dst/file &&
340 test_config -C dst rebase.autostash true &&
341 git -C dst pull --rebase >actual 2>&1 &&
342 grep -q "Fast-forward" actual &&
343 grep -q "Applied autostash." actual
346 test_expect_success '--rebase with conflicts shows advice' '
347 test_when_finished "git rebase --abort; git checkout -f to-rebase" &&
348 git checkout -b seq &&
349 test_seq 5 >seq.txt &&
350 git add seq.txt &&
351 test_tick &&
352 git commit -m "Add seq.txt" &&
353 echo 6 >>seq.txt &&
354 test_tick &&
355 git commit -m "Append to seq.txt" seq.txt &&
356 git checkout -b with-conflicts HEAD^ &&
357 echo conflicting >>seq.txt &&
358 test_tick &&
359 git commit -m "Create conflict" seq.txt &&
360 test_must_fail git pull --rebase . seq 2>err >out &&
361 test_i18ngrep "Resolve all conflicts manually" err
364 test_expect_success 'failed --rebase shows advice' '
365 test_when_finished "git rebase --abort; git checkout -f to-rebase" &&
366 git checkout -b diverging &&
367 test_commit attributes .gitattributes "* text=auto" attrs &&
368 sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" &&
369 git update-index --cacheinfo 0644 $sha1 file &&
370 git commit -m v1-with-cr &&
371 # force checkout because `git reset --hard` will not leave clean `file`
372 git checkout -f -b fails-to-rebase HEAD^ &&
373 test_commit v2-without-cr file "2" file2-lf &&
374 test_must_fail git pull --rebase . diverging 2>err >out &&
375 test_i18ngrep "Resolve all conflicts manually" err
378 test_expect_success '--rebase fails with multiple branches' '
379 git reset --hard before-rebase &&
380 test_must_fail git pull --rebase . copy main 2>err &&
381 test_cmp_rev HEAD before-rebase &&
382 test_i18ngrep "Cannot rebase onto multiple branches" err &&
383 echo modified >expect &&
384 git show HEAD:file >actual &&
385 test_cmp expect actual
388 test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
389 test_config rebase.autostash true &&
390 test_pull_autostash 1 --rebase
393 test_expect_success 'pull --rebase --autostash & rebase.autostash=true' '
394 test_config rebase.autostash true &&
395 test_pull_autostash 1 --rebase --autostash
398 test_expect_success 'pull --rebase --autostash & rebase.autostash=false' '
399 test_config rebase.autostash false &&
400 test_pull_autostash 1 --rebase --autostash
403 test_expect_success 'pull --rebase --autostash & rebase.autostash unset' '
404 test_unconfig rebase.autostash &&
405 test_pull_autostash 1 --rebase --autostash
408 test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' '
409 test_config rebase.autostash true &&
410 test_pull_autostash_fail --rebase --no-autostash
413 test_expect_success 'pull --rebase --no-autostash & rebase.autostash=false' '
414 test_config rebase.autostash false &&
415 test_pull_autostash_fail --rebase --no-autostash
418 test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' '
419 test_unconfig rebase.autostash &&
420 test_pull_autostash_fail --rebase --no-autostash
423 test_expect_success 'pull succeeds with dirty working directory and merge.autostash set' '
424 test_config merge.autostash true &&
425 test_pull_autostash 2 --no-rebase
428 test_expect_success 'pull --autostash & merge.autostash=true' '
429 test_config merge.autostash true &&
430 test_pull_autostash 2 --autostash --no-rebase
433 test_expect_success 'pull --autostash & merge.autostash=false' '
434 test_config merge.autostash false &&
435 test_pull_autostash 2 --autostash --no-rebase
438 test_expect_success 'pull --autostash & merge.autostash unset' '
439 test_unconfig merge.autostash &&
440 test_pull_autostash 2 --autostash --no-rebase
443 test_expect_success 'pull --no-autostash & merge.autostash=true' '
444 test_config merge.autostash true &&
445 test_pull_autostash_fail --no-autostash --no-rebase
448 test_expect_success 'pull --no-autostash & merge.autostash=false' '
449 test_config merge.autostash false &&
450 test_pull_autostash_fail --no-autostash --no-rebase
453 test_expect_success 'pull --no-autostash & merge.autostash unset' '
454 test_unconfig merge.autostash &&
455 test_pull_autostash_fail --no-autostash --no-rebase
458 test_expect_success 'pull.rebase' '
459 git reset --hard before-rebase &&
460 test_config pull.rebase true &&
461 git pull . copy &&
462 test_cmp_rev HEAD^ copy &&
463 echo new >expect &&
464 git show HEAD:file2 >actual &&
465 test_cmp expect actual
468 test_expect_success 'pull --autostash & pull.rebase=true' '
469 test_config pull.rebase true &&
470 test_pull_autostash 1 --autostash
473 test_expect_success 'pull --no-autostash & pull.rebase=true' '
474 test_config pull.rebase true &&
475 test_pull_autostash_fail --no-autostash
478 test_expect_success 'branch.to-rebase.rebase' '
479 git reset --hard before-rebase &&
480 test_config branch.to-rebase.rebase true &&
481 git pull . copy &&
482 test_cmp_rev HEAD^ copy &&
483 echo new >expect &&
484 git show HEAD:file2 >actual &&
485 test_cmp expect actual
488 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
489 git reset --hard before-rebase &&
490 test_config pull.rebase true &&
491 test_config branch.to-rebase.rebase false &&
492 git pull . copy &&
493 test_cmp_rev ! HEAD^ copy &&
494 echo new >expect &&
495 git show HEAD:file2 >actual &&
496 test_cmp expect actual
499 test_expect_success 'pull --rebase warns on --verify-signatures' '
500 git reset --hard before-rebase &&
501 git pull --rebase --verify-signatures . copy 2>err &&
502 test_cmp_rev HEAD^ copy &&
503 echo new >expect &&
504 git show HEAD:file2 >actual &&
505 test_cmp expect actual &&
506 test_i18ngrep "ignoring --verify-signatures for rebase" err
509 test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
510 git reset --hard before-rebase &&
511 git pull --rebase --no-verify-signatures . copy 2>err &&
512 test_cmp_rev HEAD^ copy &&
513 echo new >expect &&
514 git show HEAD:file2 >actual &&
515 test_cmp expect actual &&
516 test_i18ngrep ! "verify-signatures" err
519 # add a feature branch, keep-merge, that is merged into main, so the
520 # test can try preserving the merge commit (or not) with various
521 # --rebase flags/pull.rebase settings.
522 test_expect_success 'preserve merge setup' '
523 git reset --hard before-rebase &&
524 git checkout -b keep-merge second^ &&
525 test_commit file3 &&
526 git checkout to-rebase &&
527 git merge keep-merge &&
528 git tag before-preserve-rebase
531 test_expect_success 'pull.rebase=false create a new merge commit' '
532 git reset --hard before-preserve-rebase &&
533 test_config pull.rebase false &&
534 git pull . copy &&
535 test_cmp_rev HEAD^1 before-preserve-rebase &&
536 test_cmp_rev HEAD^2 copy &&
537 echo file3 >expect &&
538 git show HEAD:file3.t >actual &&
539 test_cmp expect actual
542 test_expect_success 'pull.rebase=true flattens keep-merge' '
543 git reset --hard before-preserve-rebase &&
544 test_config pull.rebase true &&
545 git pull . copy &&
546 test_cmp_rev HEAD^^ copy &&
547 echo file3 >expect &&
548 git show HEAD:file3.t >actual &&
549 test_cmp expect actual
552 test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
553 git reset --hard before-preserve-rebase &&
554 test_config pull.rebase 1 &&
555 git pull . copy &&
556 test_cmp_rev HEAD^^ copy &&
557 echo file3 >expect &&
558 git show HEAD:file3.t >actual &&
559 test_cmp expect actual
562 test_expect_success 'pull.rebase=interactive' '
563 write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
564 echo I was here >fake.out &&
565 false
567 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
568 test_when_finished "test_might_fail git rebase --abort" &&
569 test_must_fail git pull --rebase=interactive . copy &&
570 echo "I was here" >expect &&
571 test_cmp expect fake.out
574 test_expect_success 'pull --rebase=i' '
575 write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
576 echo I was here, too >fake.out &&
577 false
579 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
580 test_when_finished "test_might_fail git rebase --abort" &&
581 test_must_fail git pull --rebase=i . copy &&
582 echo "I was here, too" >expect &&
583 test_cmp expect fake.out
586 test_expect_success 'pull.rebase=invalid fails' '
587 git reset --hard before-preserve-rebase &&
588 test_config pull.rebase invalid &&
589 test_must_fail git pull . copy
592 test_expect_success '--rebase=false create a new merge commit' '
593 git reset --hard before-preserve-rebase &&
594 test_config pull.rebase true &&
595 git pull --rebase=false . copy &&
596 test_cmp_rev HEAD^1 before-preserve-rebase &&
597 test_cmp_rev HEAD^2 copy &&
598 echo file3 >expect &&
599 git show HEAD:file3.t >actual &&
600 test_cmp expect actual
603 test_expect_success '--rebase=true rebases and flattens keep-merge' '
604 git reset --hard before-preserve-rebase &&
605 test_config pull.rebase merges &&
606 git pull --rebase=true . copy &&
607 test_cmp_rev HEAD^^ copy &&
608 echo file3 >expect &&
609 git show HEAD:file3.t >actual &&
610 test_cmp expect actual
613 test_expect_success '--rebase=invalid fails' '
614 git reset --hard before-preserve-rebase &&
615 test_must_fail git pull --rebase=invalid . copy
618 test_expect_success '--rebase overrides pull.rebase=merges and flattens keep-merge' '
619 git reset --hard before-preserve-rebase &&
620 test_config pull.rebase merges &&
621 git pull --rebase . copy &&
622 test_cmp_rev HEAD^^ copy &&
623 echo file3 >expect &&
624 git show HEAD:file3.t >actual &&
625 test_cmp expect actual
628 test_expect_success '--rebase with rebased upstream' '
629 git remote add -f me . &&
630 git checkout copy &&
631 git tag copy-orig &&
632 git reset --hard HEAD^ &&
633 echo conflicting modification >file &&
634 git commit -m conflict file &&
635 git checkout to-rebase &&
636 echo file >file2 &&
637 git commit -m to-rebase file2 &&
638 git tag to-rebase-orig &&
639 git pull --rebase me copy &&
640 echo "conflicting modification" >expect &&
641 test_cmp expect file &&
642 echo file >expect &&
643 test_cmp expect file2
646 test_expect_success '--rebase -f with rebased upstream' '
647 test_when_finished "test_might_fail git rebase --abort" &&
648 git reset --hard to-rebase-orig &&
649 git pull --rebase -f me copy &&
650 echo "conflicting modification" >expect &&
651 test_cmp expect file &&
652 echo file >expect &&
653 test_cmp expect file2
656 test_expect_success '--rebase with rebased default upstream' '
657 git update-ref refs/remotes/me/copy copy-orig &&
658 git checkout --track -b to-rebase2 me/copy &&
659 git reset --hard to-rebase-orig &&
660 git pull --rebase &&
661 echo "conflicting modification" >expect &&
662 test_cmp expect file &&
663 echo file >expect &&
664 test_cmp expect file2
667 test_expect_success 'rebased upstream + fetch + pull --rebase' '
669 git update-ref refs/remotes/me/copy copy-orig &&
670 git reset --hard to-rebase-orig &&
671 git checkout --track -b to-rebase3 me/copy &&
672 git reset --hard to-rebase-orig &&
673 git fetch &&
674 git pull --rebase &&
675 echo "conflicting modification" >expect &&
676 test_cmp expect file &&
677 echo file >expect &&
678 test_cmp expect file2
682 test_expect_success 'pull --rebase dies early with dirty working directory' '
683 git checkout to-rebase &&
684 git update-ref refs/remotes/me/copy copy^ &&
685 COPY="$(git rev-parse --verify me/copy)" &&
686 git rebase --onto $COPY copy &&
687 test_config branch.to-rebase.remote me &&
688 test_config branch.to-rebase.merge refs/heads/copy &&
689 test_config branch.to-rebase.rebase true &&
690 echo dirty >>file &&
691 git add file &&
692 test_must_fail git pull &&
693 test_cmp_rev "$COPY" me/copy &&
694 git checkout HEAD -- file &&
695 git pull &&
696 test_cmp_rev ! "$COPY" me/copy
699 test_expect_success 'pull --rebase works on branch yet to be born' '
700 git rev-parse main >expect &&
701 mkdir empty_repo &&
703 cd empty_repo &&
704 git init &&
705 git pull --rebase .. main &&
706 git rev-parse HEAD >../actual
707 ) &&
708 test_cmp expect actual
711 test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
712 test_when_finished "rm -rf empty_repo2" &&
713 git init empty_repo2 &&
715 cd empty_repo2 &&
716 echo staged-file >staged-file &&
717 git add staged-file &&
718 echo staged-file >expect &&
719 git ls-files >actual &&
720 test_cmp expect actual &&
721 test_must_fail git pull --rebase .. main 2>err &&
722 git ls-files >actual &&
723 test_cmp expect actual &&
724 git show :staged-file >actual &&
725 test_cmp expect actual &&
726 test_i18ngrep "unborn branch with changes added to the index" err
730 test_expect_success 'pull --rebase fails on corrupt HEAD' '
731 test_when_finished "rm -rf corrupt" &&
732 git init corrupt &&
734 cd corrupt &&
735 test_commit one &&
736 git rev-parse --verify HEAD >head &&
737 obj=$(sed "s#^..#&/#" head) &&
738 rm -f .git/objects/$obj &&
739 test_must_fail git pull --rebase
743 test_expect_success 'setup for detecting upstreamed changes' '
744 test_create_repo src &&
745 test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
746 git clone src dst &&
748 cd src &&
749 modify s/5/43/ stuff &&
750 git commit -a -m "5->43" &&
751 modify s/6/42/ stuff &&
752 git commit -a -m "Make it bigger"
753 ) &&
755 cd dst &&
756 modify s/5/43/ stuff &&
757 git commit -a -m "Independent discovery of 5->43"
761 test_expect_success 'git pull --rebase detects upstreamed changes' '
763 cd dst &&
764 git pull --rebase &&
765 git ls-files -u >untracked &&
766 test_must_be_empty untracked
770 test_expect_success 'setup for avoiding reapplying old patches' '
772 cd dst &&
773 test_might_fail git rebase --abort &&
774 git reset --hard origin/main
775 ) &&
776 git clone --bare src src-replace.git &&
777 rm -rf src &&
778 mv src-replace.git src &&
780 cd dst &&
781 modify s/2/22/ stuff &&
782 git commit -a -m "Change 2" &&
783 modify s/3/33/ stuff &&
784 git commit -a -m "Change 3" &&
785 modify s/4/44/ stuff &&
786 git commit -a -m "Change 4" &&
787 git push &&
789 modify s/44/55/ stuff &&
790 git commit --amend -a -m "Modified Change 4"
794 test_expect_success 'git pull --rebase does not reapply old patches' '
796 cd dst &&
797 test_must_fail git pull --rebase &&
798 cat .git/rebase-merge/done .git/rebase-merge/git-rebase-todo >work &&
799 grep -v -e \# -e ^$ work >patches &&
800 test_line_count = 1 patches &&
801 rm -f work
805 test_expect_success 'git pull --rebase against local branch' '
806 git checkout -b copy2 to-rebase-orig &&
807 git pull --rebase . to-rebase &&
808 echo "conflicting modification" >expect &&
809 test_cmp expect file &&
810 echo file >expect &&
811 test_cmp expect file2
814 test_done