3 test_description='pulling into void'
8 sed -e "$1" "$2" >"$2.x" &&
12 test_pull_autostash () {
13 git reset --hard before-rebase &&
14 echo dirty >new_file &&
16 git pull "$@" . copy &&
17 test_cmp_rev HEAD^ copy &&
19 test_cmp expect new_file &&
20 echo "modified again" >expect &&
24 test_pull_autostash_fail () {
25 git reset --hard before-rebase &&
26 echo dirty >new_file &&
28 test_must_fail git pull "$@" . copy 2>err &&
29 test_i18ngrep "uncommitted changes." err
32 test_expect_success setup '
35 git commit -a -m original
38 test_expect_success 'pulling into void' '
44 test_path_is_file file &&
45 test_path_is_file cloned/file &&
46 test_cmp file cloned/file
49 test_expect_success 'pulling into void using master:master' '
50 git init cloned-uho &&
53 git pull .. master:master
55 test_path_is_file file &&
56 test_path_is_file cloned-uho/file &&
57 test_cmp file cloned-uho/file
60 test_expect_success 'pulling into void does not overwrite untracked files' '
61 git init cloned-untracked &&
63 cd cloned-untracked &&
64 echo untracked >file &&
65 test_must_fail git pull .. master &&
66 echo untracked >expect &&
71 test_expect_success 'pulling into void does not overwrite staged files' '
72 git init cloned-staged-colliding &&
74 cd cloned-staged-colliding &&
75 echo "alternate content" >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
85 test_expect_success 'pulling into void does not remove new staged files' '
86 git init cloned-staged-new &&
88 cd cloned-staged-new &&
89 echo "new tracked file" >newfile &&
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
99 test_expect_success 'pulling into void must not create an octopus' '
100 git init cloned-octopus &&
103 test_must_fail git pull .. master master &&
104 test_path_is_missing file
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 &&
116 test_cmp expect file &&
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
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 &&
131 git reset --hard HEAD^ &&
133 test_cmp expect file &&
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
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" &&
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 &&
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" &&
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 &&
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" &&
172 test_cmp expect file &&
173 test_must_fail git pull 2>err &&
174 test_i18ngrep "not currently on a branch" err &&
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 &&
185 test_cmp expect file &&
186 test_must_fail git pull 2>err &&
187 test_i18ngrep "no tracking information" err &&
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 &&
198 test_cmp expect file &&
199 test_must_fail git pull --all 2>err &&
200 test_i18ngrep "There is no tracking information" err &&
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 &&
210 test_cmp expect file &&
211 test_must_fail git pull 2>err &&
212 test_i18ngrep "no such ref was fetched" err &&
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" &&
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 &&
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 &&
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
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" &&
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
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" &&
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
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 &&
271 git commit -m "new file" &&
272 git tag before-rebase &&
273 git pull --rebase . copy &&
274 test_cmp_rev HEAD^ copy &&
276 git show HEAD:file2 >actual &&
277 test_cmp expect actual
280 test_expect_success '--rebase (merge) fast forward' '
281 git reset --hard before-rebase &&
282 git checkout -b ff &&
283 echo another modification >file &&
284 git commit -m third file &&
286 git checkout to-rebase &&
287 git -c rebase.backend=merge pull --rebase . ff &&
288 test_cmp_rev HEAD ff &&
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
297 test_expect_success '--rebase (am) fast forward' '
298 git reset --hard before-rebase &&
300 git -c rebase.backend=apply pull --rebase . ff &&
301 test_cmp_rev HEAD ff &&
303 # The above only validates the result. Did we actually bypass rebase?
304 git reflog -1 >reflog.actual &&
305 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
306 echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected &&
307 test_cmp reflog.expected reflog.fuzzy
310 test_expect_success '--rebase --autostash fast forward' '
313 git checkout to-rebase
314 git branch -D to-rebase-ff
315 git branch -D behind" &&
317 git checkout -b to-rebase-ff &&
318 echo another modification >>file &&
322 git checkout behind &&
324 git pull --rebase --autostash . to-rebase-ff &&
325 test_cmp_rev HEAD to-rebase-ff
328 test_expect_success '--rebase with conflicts shows advice' '
329 test_when_finished "git rebase --abort; git checkout -f to-rebase" &&
330 git checkout -b seq &&
331 test_seq 5 >seq.txt &&
334 git commit -m "Add seq.txt" &&
337 git commit -m "Append to seq.txt" seq.txt &&
338 git checkout -b with-conflicts HEAD^ &&
339 echo conflicting >>seq.txt &&
341 git commit -m "Create conflict" seq.txt &&
342 test_must_fail git pull --rebase . seq 2>err >out &&
343 test_i18ngrep "Resolve all conflicts manually" err
346 test_expect_success 'failed --rebase shows advice' '
347 test_when_finished "git rebase --abort; git checkout -f to-rebase" &&
348 git checkout -b diverging &&
349 test_commit attributes .gitattributes "* text=auto" attrs &&
350 sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" &&
351 git update-index --cacheinfo 0644 $sha1 file &&
352 git commit -m v1-with-cr &&
353 # force checkout because `git reset --hard` will not leave clean `file`
354 git checkout -f -b fails-to-rebase HEAD^ &&
355 test_commit v2-without-cr file "2" file2-lf &&
356 test_must_fail git pull --rebase . diverging 2>err >out &&
357 test_i18ngrep "Resolve all conflicts manually" err
360 test_expect_success '--rebase fails with multiple branches' '
361 git reset --hard before-rebase &&
362 test_must_fail git pull --rebase . copy master 2>err &&
363 test_cmp_rev HEAD before-rebase &&
364 test_i18ngrep "Cannot rebase onto multiple branches" err &&
365 echo modified >expect &&
366 git show HEAD:file >actual &&
367 test_cmp expect actual
370 test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
371 test_config rebase.autostash true &&
372 test_pull_autostash --rebase
375 test_expect_success 'pull --rebase --autostash & rebase.autostash=true' '
376 test_config rebase.autostash true &&
377 test_pull_autostash --rebase --autostash
380 test_expect_success 'pull --rebase --autostash & rebase.autostash=false' '
381 test_config rebase.autostash false &&
382 test_pull_autostash --rebase --autostash
385 test_expect_success 'pull --rebase --autostash & rebase.autostash unset' '
386 test_unconfig rebase.autostash &&
387 test_pull_autostash --rebase --autostash
390 test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' '
391 test_config rebase.autostash true &&
392 test_pull_autostash_fail --rebase --no-autostash
395 test_expect_success 'pull --rebase --no-autostash & rebase.autostash=false' '
396 test_config rebase.autostash false &&
397 test_pull_autostash_fail --rebase --no-autostash
400 test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' '
401 test_unconfig rebase.autostash &&
402 test_pull_autostash_fail --rebase --no-autostash
405 for i in --autostash --no-autostash
407 test_expect_success "pull $i (without --rebase) is illegal" '
408 test_must_fail git pull $i . copy 2>err &&
409 test_i18ngrep "only valid with --rebase" err
413 test_expect_success 'pull.rebase' '
414 git reset --hard before-rebase &&
415 test_config pull.rebase true &&
417 test_cmp_rev HEAD^ copy &&
419 git show HEAD:file2 >actual &&
420 test_cmp expect actual
423 test_expect_success 'pull --autostash & pull.rebase=true' '
424 test_config pull.rebase true &&
425 test_pull_autostash --autostash
428 test_expect_success 'pull --no-autostash & pull.rebase=true' '
429 test_config pull.rebase true &&
430 test_pull_autostash_fail --no-autostash
433 test_expect_success 'branch.to-rebase.rebase' '
434 git reset --hard before-rebase &&
435 test_config branch.to-rebase.rebase true &&
437 test_cmp_rev HEAD^ copy &&
439 git show HEAD:file2 >actual &&
440 test_cmp expect actual
443 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
444 git reset --hard before-rebase &&
445 test_config pull.rebase true &&
446 test_config branch.to-rebase.rebase false &&
448 test_cmp_rev ! HEAD^ copy &&
450 git show HEAD:file2 >actual &&
451 test_cmp expect actual
454 test_expect_success 'pull --rebase warns on --verify-signatures' '
455 git reset --hard before-rebase &&
456 git pull --rebase --verify-signatures . copy 2>err &&
457 test_cmp_rev HEAD^ copy &&
459 git show HEAD:file2 >actual &&
460 test_cmp expect actual &&
461 test_i18ngrep "ignoring --verify-signatures for rebase" err
464 test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
465 git reset --hard before-rebase &&
466 git pull --rebase --no-verify-signatures . copy 2>err &&
467 test_cmp_rev HEAD^ copy &&
469 git show HEAD:file2 >actual &&
470 test_cmp expect actual &&
471 test_i18ngrep ! "verify-signatures" err
474 # add a feature branch, keep-merge, that is merged into master, so the
475 # test can try preserving the merge commit (or not) with various
476 # --rebase flags/pull.rebase settings.
477 test_expect_success 'preserve merge setup' '
478 git reset --hard before-rebase &&
479 git checkout -b keep-merge second^ &&
481 git checkout to-rebase &&
482 git merge keep-merge &&
483 git tag before-preserve-rebase
486 test_expect_success 'pull.rebase=false create a new merge commit' '
487 git reset --hard before-preserve-rebase &&
488 test_config pull.rebase false &&
490 test_cmp_rev HEAD^1 before-preserve-rebase &&
491 test_cmp_rev HEAD^2 copy &&
492 echo file3 >expect &&
493 git show HEAD:file3.t >actual &&
494 test_cmp expect actual
497 test_expect_success 'pull.rebase=true flattens keep-merge' '
498 git reset --hard before-preserve-rebase &&
499 test_config pull.rebase true &&
501 test_cmp_rev HEAD^^ copy &&
502 echo file3 >expect &&
503 git show HEAD:file3.t >actual &&
504 test_cmp expect actual
507 test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
508 git reset --hard before-preserve-rebase &&
509 test_config pull.rebase 1 &&
511 test_cmp_rev HEAD^^ copy &&
512 echo file3 >expect &&
513 git show HEAD:file3.t >actual &&
514 test_cmp expect actual
517 test_expect_success REBASE_P \
518 'pull.rebase=preserve rebases and merges keep-merge' '
519 git reset --hard before-preserve-rebase &&
520 test_config pull.rebase preserve &&
522 test_cmp_rev HEAD^^ copy &&
523 test_cmp_rev HEAD^2 keep-merge
526 test_expect_success 'pull.rebase=interactive' '
527 write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
528 echo I was here >fake.out &&
531 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
532 test_when_finished "test_might_fail git rebase --abort" &&
533 test_must_fail git pull --rebase=interactive . copy &&
534 echo "I was here" >expect &&
535 test_cmp expect fake.out
538 test_expect_success 'pull --rebase=i' '
539 write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
540 echo I was here, too >fake.out &&
543 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
544 test_when_finished "test_might_fail git rebase --abort" &&
545 test_must_fail git pull --rebase=i . copy &&
546 echo "I was here, too" >expect &&
547 test_cmp expect fake.out
550 test_expect_success 'pull.rebase=invalid fails' '
551 git reset --hard before-preserve-rebase &&
552 test_config pull.rebase invalid &&
553 test_must_fail git pull . copy
556 test_expect_success '--rebase=false create a new merge commit' '
557 git reset --hard before-preserve-rebase &&
558 test_config pull.rebase true &&
559 git pull --rebase=false . copy &&
560 test_cmp_rev HEAD^1 before-preserve-rebase &&
561 test_cmp_rev HEAD^2 copy &&
562 echo file3 >expect &&
563 git show HEAD:file3.t >actual &&
564 test_cmp expect actual
567 test_expect_success '--rebase=true rebases and flattens keep-merge' '
568 git reset --hard before-preserve-rebase &&
569 test_config pull.rebase preserve &&
570 git pull --rebase=true . copy &&
571 test_cmp_rev HEAD^^ copy &&
572 echo file3 >expect &&
573 git show HEAD:file3.t >actual &&
574 test_cmp expect actual
577 test_expect_success REBASE_P \
578 '--rebase=preserve rebases and merges keep-merge' '
579 git reset --hard before-preserve-rebase &&
580 test_config pull.rebase true &&
581 git pull --rebase=preserve . copy &&
582 test_cmp_rev HEAD^^ copy &&
583 test_cmp_rev HEAD^2 keep-merge
586 test_expect_success '--rebase=invalid fails' '
587 git reset --hard before-preserve-rebase &&
588 test_must_fail git pull --rebase=invalid . copy
591 test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
592 git reset --hard before-preserve-rebase &&
593 test_config pull.rebase preserve &&
594 git pull --rebase . copy &&
595 test_cmp_rev HEAD^^ copy &&
596 echo file3 >expect &&
597 git show HEAD:file3.t >actual &&
598 test_cmp expect actual
601 test_expect_success '--rebase with rebased upstream' '
602 git remote add -f me . &&
605 git reset --hard HEAD^ &&
606 echo conflicting modification >file &&
607 git commit -m conflict file &&
608 git checkout to-rebase &&
610 git commit -m to-rebase file2 &&
611 git tag to-rebase-orig &&
612 git pull --rebase me copy &&
613 echo "conflicting modification" >expect &&
614 test_cmp expect file &&
616 test_cmp expect file2
619 test_expect_success '--rebase -f with rebased upstream' '
620 test_when_finished "test_might_fail git rebase --abort" &&
621 git reset --hard to-rebase-orig &&
622 git pull --rebase -f me copy &&
623 echo "conflicting modification" >expect &&
624 test_cmp expect file &&
626 test_cmp expect file2
629 test_expect_success '--rebase with rebased default upstream' '
630 git update-ref refs/remotes/me/copy copy-orig &&
631 git checkout --track -b to-rebase2 me/copy &&
632 git reset --hard to-rebase-orig &&
634 echo "conflicting modification" >expect &&
635 test_cmp expect file &&
637 test_cmp expect file2
640 test_expect_success 'rebased upstream + fetch + pull --rebase' '
642 git update-ref refs/remotes/me/copy copy-orig &&
643 git reset --hard to-rebase-orig &&
644 git checkout --track -b to-rebase3 me/copy &&
645 git reset --hard to-rebase-orig &&
648 echo "conflicting modification" >expect &&
649 test_cmp expect file &&
651 test_cmp expect file2
655 test_expect_success 'pull --rebase dies early with dirty working directory' '
656 git checkout to-rebase &&
657 git update-ref refs/remotes/me/copy copy^ &&
658 COPY="$(git rev-parse --verify me/copy)" &&
659 git rebase --onto $COPY copy &&
660 test_config branch.to-rebase.remote me &&
661 test_config branch.to-rebase.merge refs/heads/copy &&
662 test_config branch.to-rebase.rebase true &&
665 test_must_fail git pull &&
666 test_cmp_rev "$COPY" me/copy &&
667 git checkout HEAD -- file &&
669 test_cmp_rev ! "$COPY" me/copy
672 test_expect_success 'pull --rebase works on branch yet to be born' '
673 git rev-parse master >expect &&
678 git pull --rebase .. master &&
679 git rev-parse HEAD >../actual
681 test_cmp expect actual
684 test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
685 test_when_finished "rm -rf empty_repo2" &&
686 git init empty_repo2 &&
689 echo staged-file >staged-file &&
690 git add staged-file &&
691 echo staged-file >expect &&
692 git ls-files >actual &&
693 test_cmp expect actual &&
694 test_must_fail git pull --rebase .. master 2>err &&
695 git ls-files >actual &&
696 test_cmp expect actual &&
697 git show :staged-file >actual &&
698 test_cmp expect actual &&
699 test_i18ngrep "unborn branch with changes added to the index" err
703 test_expect_success 'pull --rebase fails on corrupt HEAD' '
704 test_when_finished "rm -rf corrupt" &&
709 git rev-parse --verify HEAD >head &&
710 obj=$(sed "s#^..#&/#" head) &&
711 rm -f .git/objects/$obj &&
712 test_must_fail git pull --rebase
716 test_expect_success 'setup for detecting upstreamed changes' '
721 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
723 git commit -m "Initial revision"
728 modify s/5/43/ stuff &&
729 git commit -a -m "5->43" &&
730 modify s/6/42/ stuff &&
731 git commit -a -m "Make it bigger"
735 modify s/5/43/ stuff &&
736 git commit -a -m "Independent discovery of 5->43"
740 test_expect_success 'git pull --rebase detects upstreamed changes' '
744 git ls-files -u >untracked &&
745 test_must_be_empty untracked
749 test_expect_success 'setup for avoiding reapplying old patches' '
752 test_might_fail git rebase --abort &&
753 git reset --hard origin/master
755 git clone --bare src src-replace.git &&
757 mv src-replace.git src &&
760 modify s/2/22/ stuff &&
761 git commit -a -m "Change 2" &&
762 modify s/3/33/ stuff &&
763 git commit -a -m "Change 3" &&
764 modify s/4/44/ stuff &&
765 git commit -a -m "Change 4" &&
768 modify s/44/55/ stuff &&
769 git commit --amend -a -m "Modified Change 4"
773 test_expect_success 'git pull --rebase does not reapply old patches' '
776 test_must_fail git pull --rebase &&
777 cat .git/rebase-merge/done .git/rebase-merge/git-rebase-todo >work &&
778 grep -v -e \# -e ^$ work >patches &&
779 test_line_count = 1 patches &&
784 test_expect_success 'git pull --rebase against local branch' '
785 git checkout -b copy2 to-rebase-orig &&
786 git pull --rebase . to-rebase &&
787 echo "conflicting modification" >expect &&
788 test_cmp expect file &&
790 test_cmp expect file2