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 &&
154 test_expect_success
'fail if no branches specified with non-default remote' '
155 git remote add test_remote . &&
156 test_when_finished "git remote remove test_remote" &&
157 git checkout -b test copy^ &&
158 test_when_finished "git checkout -f copy && git branch -D test" &&
160 test_cmp expect file &&
161 test_config branch.test.remote origin &&
162 test_must_fail git pull test_remote 2>err &&
163 test_i18ngrep "specify a branch on the command line" err &&
168 test_expect_success
'fail if not on a branch' '
169 git remote add origin . &&
170 test_when_finished "git remote remove origin" &&
171 git checkout HEAD^ &&
172 test_when_finished "git checkout -f copy" &&
174 test_cmp expect file &&
175 test_must_fail git pull 2>err &&
176 test_i18ngrep "not currently on a branch" err &&
181 test_expect_success
'fail if no configuration for current branch' '
182 git remote add test_remote . &&
183 test_when_finished "git remote remove test_remote" &&
184 git checkout -b test copy^ &&
185 test_when_finished "git checkout -f copy && git branch -D test" &&
186 test_config branch.test.remote test_remote &&
188 test_cmp expect file &&
189 test_must_fail git pull 2>err &&
190 test_i18ngrep "no tracking information" err &&
195 test_expect_success
'pull --all: fail if no configuration for current branch' '
196 git remote add test_remote . &&
197 test_when_finished "git remote remove test_remote" &&
198 git checkout -b test copy^ &&
199 test_when_finished "git checkout -f copy && git branch -D test" &&
200 test_config branch.test.remote test_remote &&
202 test_cmp expect file &&
203 test_must_fail git pull --all 2>err &&
204 test_i18ngrep "There is no tracking information" err &&
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 &&
215 test_cmp expect file &&
216 test_must_fail git pull 2>err &&
217 test_i18ngrep "no such ref was fetched" err &&
222 test_expect_success
'fail if the index has unresolved entries' '
223 git checkout -b third second^ &&
224 test_when_finished "git checkout -f copy && git branch -D third" &&
226 test_cmp expect file &&
227 test_commit modified2 file &&
228 git ls-files -u >unmerged &&
229 test_must_be_empty unmerged &&
230 test_must_fail git pull . second &&
231 git ls-files -u >unmerged &&
232 test_file_not_empty unmerged &&
234 test_must_fail git pull . second 2>err &&
235 test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
236 test_cmp expected file &&
238 git ls-files -u >unmerged &&
239 test_must_be_empty unmerged &&
240 test_must_fail git pull . second 2>err &&
241 test_i18ngrep "You have not concluded your merge" err &&
242 test_cmp expected file
245 test_expect_success
'fast-forwards working tree if branch head is updated' '
246 git checkout -b third second^ &&
247 test_when_finished "git checkout -f copy && git branch -D third" &&
249 test_cmp expect file &&
250 git pull . second:third 2>err &&
251 test_i18ngrep "fetch updated the current branch head" err &&
252 echo modified >expect &&
253 test_cmp expect file &&
254 test_cmp_rev third second
257 test_expect_success
'fast-forward fails with conflicting work tree' '
258 git checkout -b third second^ &&
259 test_when_finished "git checkout -f copy && git branch -D third" &&
261 test_cmp expect file &&
262 echo conflict >file &&
263 test_must_fail git pull . second:third 2>err &&
264 test_i18ngrep "Cannot fast-forward your working tree" err &&
265 echo conflict >expect &&
266 test_cmp expect file &&
267 test_cmp_rev third second
270 test_expect_success
'--rebase' '
271 git branch to-rebase &&
272 echo modified again >file &&
273 git commit -m file file &&
274 git checkout to-rebase &&
277 git commit -m "new file" &&
278 git tag before-rebase &&
279 git pull --rebase . copy &&
280 test_cmp_rev HEAD^ copy &&
282 git show HEAD:file2 >actual &&
283 test_cmp expect actual
286 test_expect_success
'--rebase fast forward' '
287 git reset --hard before-rebase &&
288 git checkout -b ff &&
289 echo another modification >file &&
290 git commit -m third file &&
292 git checkout to-rebase &&
293 git pull --rebase . ff &&
294 test_cmp_rev HEAD ff &&
296 # The above only validates the result. Did we actually bypass rebase?
297 git reflog -1 >reflog.actual &&
298 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
299 echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected &&
300 test_cmp reflog.expected reflog.fuzzy
303 test_expect_success
'--rebase --autostash fast forward' '
306 git checkout to-rebase
307 git branch -D to-rebase-ff
308 git branch -D behind" &&
310 git checkout -b to-rebase-ff &&
311 echo another modification >>file &&
315 git checkout behind &&
317 git pull --rebase --autostash . to-rebase-ff &&
318 test_cmp_rev HEAD to-rebase-ff
321 test_expect_success
'--rebase with conflicts shows advice' '
322 test_when_finished "git rebase --abort; git checkout -f to-rebase" &&
323 git checkout -b seq &&
324 test_seq 5 >seq.txt &&
327 git commit -m "Add seq.txt" &&
330 git commit -m "Append to seq.txt" seq.txt &&
331 git checkout -b with-conflicts HEAD^ &&
332 echo conflicting >>seq.txt &&
334 git commit -m "Create conflict" seq.txt &&
335 test_must_fail git pull --rebase . seq 2>err >out &&
336 test_i18ngrep "Resolve all conflicts manually" out
339 test_expect_success
'failed --rebase shows advice' '
340 test_when_finished "git rebase --abort; git checkout -f to-rebase" &&
341 git checkout -b diverging &&
342 test_commit attributes .gitattributes "* text=auto" attrs &&
343 sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" &&
344 git update-index --cacheinfo 0644 $sha1 file &&
345 git commit -m v1-with-cr &&
346 # force checkout because `git reset --hard` will not leave clean `file`
347 git checkout -f -b fails-to-rebase HEAD^ &&
348 test_commit v2-without-cr file "2" file2-lf &&
349 test_must_fail git pull --rebase . diverging 2>err >out &&
350 test_i18ngrep "Resolve all conflicts manually" out
353 test_expect_success
'--rebase fails with multiple branches' '
354 git reset --hard before-rebase &&
355 test_must_fail git pull --rebase . copy master 2>err &&
356 test_cmp_rev HEAD before-rebase &&
357 test_i18ngrep "Cannot rebase onto multiple branches" err &&
358 echo modified >expect &&
359 git show HEAD:file >actual &&
360 test_cmp expect actual
363 test_expect_success
'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
364 test_config rebase.autostash true &&
365 test_pull_autostash --rebase
368 test_expect_success
'pull --rebase --autostash & rebase.autostash=true' '
369 test_config rebase.autostash true &&
370 test_pull_autostash --rebase --autostash
373 test_expect_success
'pull --rebase --autostash & rebase.autostash=false' '
374 test_config rebase.autostash false &&
375 test_pull_autostash --rebase --autostash
378 test_expect_success
'pull --rebase --autostash & rebase.autostash unset' '
379 test_unconfig rebase.autostash &&
380 test_pull_autostash --rebase --autostash
383 test_expect_success
'pull --rebase --no-autostash & rebase.autostash=true' '
384 test_config rebase.autostash true &&
385 test_pull_autostash_fail --rebase --no-autostash
388 test_expect_success
'pull --rebase --no-autostash & rebase.autostash=false' '
389 test_config rebase.autostash false &&
390 test_pull_autostash_fail --rebase --no-autostash
393 test_expect_success
'pull --rebase --no-autostash & rebase.autostash unset' '
394 test_unconfig rebase.autostash &&
395 test_pull_autostash_fail --rebase --no-autostash
398 for i
in --autostash --no-autostash
400 test_expect_success
"pull $i (without --rebase) is illegal" '
401 test_must_fail git pull $i . copy 2>err &&
402 test_i18ngrep "only valid with --rebase" err
406 test_expect_success
'pull.rebase' '
407 git reset --hard before-rebase &&
408 test_config pull.rebase true &&
410 test_cmp_rev HEAD^ copy &&
412 git show HEAD:file2 >actual &&
413 test_cmp expect actual
416 test_expect_success
'pull --autostash & pull.rebase=true' '
417 test_config pull.rebase true &&
418 test_pull_autostash --autostash
421 test_expect_success
'pull --no-autostash & pull.rebase=true' '
422 test_config pull.rebase true &&
423 test_pull_autostash_fail --no-autostash
426 test_expect_success
'branch.to-rebase.rebase' '
427 git reset --hard before-rebase &&
428 test_config branch.to-rebase.rebase true &&
430 test_cmp_rev HEAD^ copy &&
432 git show HEAD:file2 >actual &&
433 test_cmp expect actual
436 test_expect_success
'branch.to-rebase.rebase should override pull.rebase' '
437 git reset --hard before-rebase &&
438 test_config pull.rebase true &&
439 test_config branch.to-rebase.rebase false &&
441 test_cmp_rev ! HEAD^ copy &&
443 git show HEAD:file2 >actual &&
444 test_cmp expect actual
447 test_expect_success
'pull --rebase warns on --verify-signatures' '
448 git reset --hard before-rebase &&
449 git pull --rebase --verify-signatures . copy 2>err &&
450 test_cmp_rev HEAD^ copy &&
452 git show HEAD:file2 >actual &&
453 test_cmp expect actual &&
454 test_i18ngrep "ignoring --verify-signatures for rebase" err
457 test_expect_success
'pull --rebase does not warn on --no-verify-signatures' '
458 git reset --hard before-rebase &&
459 git pull --rebase --no-verify-signatures . copy 2>err &&
460 test_cmp_rev HEAD^ copy &&
462 git show HEAD:file2 >actual &&
463 test_cmp expect actual &&
464 test_i18ngrep ! "verify-signatures" err
467 # add a feature branch, keep-merge, that is merged into master, so the
468 # test can try preserving the merge commit (or not) with various
469 # --rebase flags/pull.rebase settings.
470 test_expect_success
'preserve merge setup' '
471 git reset --hard before-rebase &&
472 git checkout -b keep-merge second^ &&
474 git checkout to-rebase &&
475 git merge keep-merge &&
476 git tag before-preserve-rebase
479 test_expect_success
'pull.rebase=false create a new merge commit' '
480 git reset --hard before-preserve-rebase &&
481 test_config pull.rebase false &&
483 test_cmp_rev HEAD^1 before-preserve-rebase &&
484 test_cmp_rev HEAD^2 copy &&
485 echo file3 >expect &&
486 git show HEAD:file3.t >actual &&
487 test_cmp expect actual
490 test_expect_success
'pull.rebase=true flattens keep-merge' '
491 git reset --hard before-preserve-rebase &&
492 test_config pull.rebase true &&
494 test_cmp_rev HEAD^^ copy &&
495 echo file3 >expect &&
496 git show HEAD:file3.t >actual &&
497 test_cmp expect actual
500 test_expect_success
'pull.rebase=1 is treated as true and flattens keep-merge' '
501 git reset --hard before-preserve-rebase &&
502 test_config pull.rebase 1 &&
504 test_cmp_rev HEAD^^ copy &&
505 echo file3 >expect &&
506 git show HEAD:file3.t >actual &&
507 test_cmp expect actual
510 test_expect_success REBASE_P \
511 'pull.rebase=preserve rebases and merges keep-merge' '
512 git reset --hard before-preserve-rebase &&
513 test_config pull.rebase preserve &&
515 test_cmp_rev HEAD^^ copy &&
516 test_cmp_rev HEAD^2 keep-merge
519 test_expect_success
'pull.rebase=interactive' '
520 write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
521 echo I was here >fake.out &&
524 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
525 test_when_finished "test_might_fail git rebase --abort" &&
526 test_must_fail git pull --rebase=interactive . copy &&
527 echo "I was here" >expect &&
528 test_cmp expect fake.out
531 test_expect_success
'pull --rebase=i' '
532 write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
533 echo I was here, too >fake.out &&
536 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
537 test_when_finished "test_might_fail git rebase --abort" &&
538 test_must_fail git pull --rebase=i . copy &&
539 echo "I was here, too" >expect &&
540 test_cmp expect fake.out
543 test_expect_success
'pull.rebase=invalid fails' '
544 git reset --hard before-preserve-rebase &&
545 test_config pull.rebase invalid &&
549 test_expect_success
'--rebase=false create a new merge commit' '
550 git reset --hard before-preserve-rebase &&
551 test_config pull.rebase true &&
552 git pull --rebase=false . copy &&
553 test_cmp_rev HEAD^1 before-preserve-rebase &&
554 test_cmp_rev HEAD^2 copy &&
555 echo file3 >expect &&
556 git show HEAD:file3.t >actual &&
557 test_cmp expect actual
560 test_expect_success
'--rebase=true rebases and flattens keep-merge' '
561 git reset --hard before-preserve-rebase &&
562 test_config pull.rebase preserve &&
563 git pull --rebase=true . copy &&
564 test_cmp_rev HEAD^^ copy &&
565 echo file3 >expect &&
566 git show HEAD:file3.t >actual &&
567 test_cmp expect actual
570 test_expect_success REBASE_P \
571 '--rebase=preserve rebases and merges keep-merge' '
572 git reset --hard before-preserve-rebase &&
573 test_config pull.rebase true &&
574 git pull --rebase=preserve . copy &&
575 test_cmp_rev HEAD^^ copy &&
576 test_cmp_rev HEAD^2 keep-merge
579 test_expect_success
'--rebase=invalid fails' '
580 git reset --hard before-preserve-rebase &&
581 ! git pull --rebase=invalid . copy
584 test_expect_success
'--rebase overrides pull.rebase=preserve and flattens keep-merge' '
585 git reset --hard before-preserve-rebase &&
586 test_config pull.rebase preserve &&
587 git pull --rebase . copy &&
588 test_cmp_rev HEAD^^ copy &&
589 echo file3 >expect &&
590 git show HEAD:file3.t >actual &&
591 test_cmp expect actual
594 test_expect_success
'--rebase with rebased upstream' '
595 git remote add -f me . &&
598 git reset --hard HEAD^ &&
599 echo conflicting modification >file &&
600 git commit -m conflict file &&
601 git checkout to-rebase &&
603 git commit -m to-rebase file2 &&
604 git tag to-rebase-orig &&
605 git pull --rebase me copy &&
606 echo "conflicting modification" >expect &&
607 test_cmp expect file &&
609 test_cmp expect file2
612 test_expect_success
'--rebase -f with rebased upstream' '
613 test_when_finished "test_might_fail git rebase --abort" &&
614 git reset --hard to-rebase-orig &&
615 git pull --rebase -f me copy &&
616 echo "conflicting modification" >expect &&
617 test_cmp expect file &&
619 test_cmp expect file2
622 test_expect_success
'--rebase with rebased default upstream' '
623 git update-ref refs/remotes/me/copy copy-orig &&
624 git checkout --track -b to-rebase2 me/copy &&
625 git reset --hard to-rebase-orig &&
627 echo "conflicting modification" >expect &&
628 test_cmp expect file &&
630 test_cmp expect file2
633 test_expect_success
'rebased upstream + fetch + pull --rebase' '
635 git update-ref refs/remotes/me/copy copy-orig &&
636 git reset --hard to-rebase-orig &&
637 git checkout --track -b to-rebase3 me/copy &&
638 git reset --hard to-rebase-orig &&
641 echo "conflicting modification" >expect &&
642 test_cmp expect file &&
644 test_cmp expect file2
648 test_expect_success
'pull --rebase dies early with dirty working directory' '
649 git checkout to-rebase &&
650 git update-ref refs/remotes/me/copy copy^ &&
651 COPY="$(git rev-parse --verify me/copy)" &&
652 git rebase --onto $COPY copy &&
653 test_config branch.to-rebase.remote me &&
654 test_config branch.to-rebase.merge refs/heads/copy &&
655 test_config branch.to-rebase.rebase true &&
658 test_must_fail git pull &&
659 test_cmp_rev "$COPY" me/copy &&
660 git checkout HEAD -- file &&
662 test_cmp_rev ! "$COPY" me/copy
665 test_expect_success
'pull --rebase works on branch yet to be born' '
666 git rev-parse master >expect &&
671 git pull --rebase .. master &&
672 git rev-parse HEAD >../actual
674 test_cmp expect actual
677 test_expect_success
'pull --rebase fails on unborn branch with staged changes' '
678 test_when_finished "rm -rf empty_repo2" &&
679 git init empty_repo2 &&
682 echo staged-file >staged-file &&
683 git add staged-file &&
684 echo staged-file >expect &&
685 git ls-files >actual &&
686 test_cmp expect actual &&
687 test_must_fail git pull --rebase .. master 2>err &&
688 echo staged-file >expect &&
689 git ls-files >actual &&
690 test_cmp expect actual &&
691 echo staged-file >expect &&
692 git show :staged-file >actual &&
693 test_cmp expect actual &&
694 test_i18ngrep "unborn branch with changes added to the index" err
698 test_expect_success
'pull --rebase fails on corrupt HEAD' '
699 test_when_finished "rm -rf corrupt" &&
704 git rev-parse --verify HEAD >head &&
705 obj=$(sed "s#^..#&/#" head) &&
706 rm -f .git/objects/$obj &&
707 test_must_fail git pull --rebase
711 test_expect_success
'setup for detecting upstreamed changes' '
716 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
718 git commit -m "Initial revision"
723 modify s/5/43/ stuff &&
724 git commit -a -m "5->43" &&
725 modify s/6/42/ stuff &&
726 git commit -a -m "Make it bigger"
730 modify s/5/43/ stuff &&
731 git commit -a -m "Independent discovery of 5->43"
735 test_expect_success
'git pull --rebase detects upstreamed changes' '
739 git ls-files -u >untracked &&
740 test_must_be_empty untracked
744 test_expect_success
'setup for avoiding reapplying old patches' '
747 test_might_fail git rebase --abort &&
748 git reset --hard origin/master
750 git clone --bare src src-replace.git &&
752 mv src-replace.git src &&
755 modify s/2/22/ stuff &&
756 git commit -a -m "Change 2" &&
757 modify s/3/33/ stuff &&
758 git commit -a -m "Change 3" &&
759 modify s/4/44/ stuff &&
760 git commit -a -m "Change 4" &&
763 modify s/44/55/ stuff &&
764 git commit --amend -a -m "Modified Change 4"
768 test_expect_success
'git pull --rebase does not reapply old patches' '
771 test_must_fail git pull --rebase &&
772 find .git/rebase-apply -name "000*" >patches &&
773 test_line_count = 1 patches
777 test_expect_success
'git pull --rebase against local branch' '
778 git checkout -b copy2 to-rebase-orig &&
779 git pull --rebase . to-rebase &&
780 echo "conflicting modification" >expect &&
781 test_cmp expect file &&
783 test_cmp expect file2