3 test_description
='pulling into void'
8 sed -e "$1" <"$2" >"$2.x" &&
12 test_expect_success setup
'
15 git commit -a -m original
18 test_expect_success
'pulling into void' '
25 test -f cloned/file &&
26 test_cmp file cloned/file
29 test_expect_success
'pulling into void using master:master' '
30 git init cloned-uho &&
33 git pull .. master:master
36 test -f cloned-uho/file &&
37 test_cmp file cloned-uho/file
40 test_expect_success
'pulling into void does not overwrite untracked files' '
41 git init cloned-untracked &&
43 cd cloned-untracked &&
44 echo untracked >file &&
45 test_must_fail git pull .. master &&
46 echo untracked >expect &&
51 test_expect_success
'pulling into void does not overwrite staged files' '
52 git init cloned-staged-colliding &&
54 cd cloned-staged-colliding &&
55 echo "alternate content" >file &&
57 test_must_fail git pull .. master &&
58 echo "alternate content" >expect &&
59 test_cmp expect file &&
60 git cat-file blob :file >file.index &&
61 test_cmp expect file.index
65 test_expect_success
'pulling into void does not remove new staged files' '
66 git init cloned-staged-new &&
68 cd cloned-staged-new &&
69 echo "new tracked file" >newfile &&
72 echo "new tracked file" >expect &&
73 test_cmp expect newfile &&
74 git cat-file blob :newfile >newfile.index &&
75 test_cmp expect newfile.index
79 test_expect_success
'pulling into void must not create an octopus' '
80 git init cloned-octopus &&
83 test_must_fail git pull .. master master &&
88 test_expect_success
'test . as a remote' '
89 git branch copy master &&
90 git config branch.copy.remote . &&
91 git config branch.copy.merge refs/heads/master &&
93 git commit -a -m updated &&
95 test "$(cat file)" = file &&
97 test "$(cat file)" = updated &&
98 git reflog -1 >reflog.actual &&
99 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
100 echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
101 test_cmp reflog.expected reflog.fuzzy
104 test_expect_success
'the default remote . should not break explicit pull' '
105 git checkout -b second master^ &&
106 echo modified >file &&
107 git commit -a -m modified &&
109 git reset --hard HEAD^ &&
110 test "$(cat file)" = file &&
112 test "$(cat file)" = modified &&
113 git reflog -1 >reflog.actual &&
114 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
115 echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
116 test_cmp reflog.expected reflog.fuzzy
119 test_expect_success
'fail if wildcard spec does not match any refs' '
120 git checkout -b test copy^ &&
121 test_when_finished "git checkout -f copy && git branch -D test" &&
122 test "$(cat file)" = file &&
123 test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
124 test_i18ngrep "no candidates for merging" err &&
125 test "$(cat file)" = file
128 test_expect_success
'fail if no branches specified with non-default remote' '
129 git remote add test_remote . &&
130 test_when_finished "git remote remove test_remote" &&
131 git checkout -b test copy^ &&
132 test_when_finished "git checkout -f copy && git branch -D test" &&
133 test "$(cat file)" = file &&
134 test_config branch.test.remote origin &&
135 test_must_fail git pull test_remote 2>err &&
136 test_i18ngrep "specify a branch on the command line" err &&
137 test "$(cat file)" = file
140 test_expect_success
'fail if not on a branch' '
141 git remote add origin . &&
142 test_when_finished "git remote remove origin" &&
143 git checkout HEAD^ &&
144 test_when_finished "git checkout -f copy" &&
145 test "$(cat file)" = file &&
146 test_must_fail git pull 2>err &&
147 test_i18ngrep "not currently on a branch" err &&
148 test "$(cat file)" = file
151 test_expect_success
'fail if no configuration for current branch' '
152 git remote add test_remote . &&
153 test_when_finished "git remote remove test_remote" &&
154 git checkout -b test copy^ &&
155 test_when_finished "git checkout -f copy && git branch -D test" &&
156 test_config branch.test.remote test_remote &&
157 test "$(cat file)" = file &&
158 test_must_fail git pull 2>err &&
159 test_i18ngrep "no tracking information" err &&
160 test "$(cat file)" = file
163 test_expect_success
'pull --all: fail if no configuration for current branch' '
164 git remote add test_remote . &&
165 test_when_finished "git remote remove test_remote" &&
166 git checkout -b test copy^ &&
167 test_when_finished "git checkout -f copy && git branch -D test" &&
168 test_config branch.test.remote test_remote &&
169 test "$(cat file)" = file &&
170 test_must_fail git pull --all 2>err &&
171 test_i18ngrep "There is no tracking information" err &&
172 test "$(cat file)" = file
175 test_expect_success
'fail if upstream branch does not exist' '
176 git checkout -b test copy^ &&
177 test_when_finished "git checkout -f copy && git branch -D test" &&
178 test_config branch.test.remote . &&
179 test_config branch.test.merge refs/heads/nonexisting &&
180 test "$(cat file)" = file &&
181 test_must_fail git pull 2>err &&
182 test_i18ngrep "no such ref was fetched" err &&
183 test "$(cat file)" = file
186 test_expect_success
'fail if the index has unresolved entries' '
187 git checkout -b third second^ &&
188 test_when_finished "git checkout -f copy && git branch -D third" &&
189 test "$(cat file)" = file &&
190 test_commit modified2 file &&
191 test -z "$(git ls-files -u)" &&
192 test_must_fail git pull . second &&
193 test -n "$(git ls-files -u)" &&
195 test_must_fail git pull . second 2>err &&
196 test_i18ngrep "Pull is not possible because you have unmerged files" err &&
197 test_cmp expected file &&
199 test -z "$(git ls-files -u)" &&
200 test_must_fail git pull . second 2>err &&
201 test_i18ngrep "You have not concluded your merge" err &&
202 test_cmp expected file
205 test_expect_success
'fast-forwards working tree if branch head is updated' '
206 git checkout -b third second^ &&
207 test_when_finished "git checkout -f copy && git branch -D third" &&
208 test "$(cat file)" = file &&
209 git pull . second:third 2>err &&
210 test_i18ngrep "fetch updated the current branch head" err &&
211 test "$(cat file)" = modified &&
212 test "$(git rev-parse third)" = "$(git rev-parse second)"
215 test_expect_success
'fast-forward fails with conflicting work tree' '
216 git checkout -b third second^ &&
217 test_when_finished "git checkout -f copy && git branch -D third" &&
218 test "$(cat file)" = file &&
219 echo conflict >file &&
220 test_must_fail git pull . second:third 2>err &&
221 test_i18ngrep "Cannot fast-forward your working tree" err &&
222 test "$(cat file)" = conflict &&
223 test "$(git rev-parse third)" = "$(git rev-parse second)"
226 test_expect_success
'--rebase' '
227 git branch to-rebase &&
228 echo modified again > file &&
229 git commit -m file file &&
230 git checkout to-rebase &&
233 git commit -m "new file" &&
234 git tag before-rebase &&
235 git pull --rebase . copy &&
236 test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
237 test new = "$(git show HEAD:file2)"
240 test_expect_success
'--rebase fails with multiple branches' '
241 git reset --hard before-rebase &&
242 test_must_fail git pull --rebase . copy master 2>err &&
243 test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
244 test_i18ngrep "Cannot rebase onto multiple branches" err &&
245 test modified = "$(git show HEAD:file)"
248 test_expect_success
'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
249 test_config rebase.autostash true &&
250 git reset --hard before-rebase &&
251 echo dirty >new_file &&
253 git pull --rebase . copy &&
254 test_cmp_rev HEAD^ copy &&
255 test "$(cat new_file)" = dirty &&
256 test "$(cat file)" = "modified again"
259 test_expect_success
'pull --rebase --autostash & rebase.autostash=true' '
260 test_config rebase.autostash true &&
261 git reset --hard before-rebase &&
262 echo dirty >new_file &&
264 git pull --rebase --autostash . copy &&
265 test_cmp_rev HEAD^ copy &&
266 test "$(cat new_file)" = dirty &&
267 test "$(cat file)" = "modified again"
270 test_expect_success
'pull --rebase --autostash & rebase.autostash=false' '
271 test_config rebase.autostash false &&
272 git reset --hard before-rebase &&
273 echo dirty >new_file &&
275 git pull --rebase --autostash . copy &&
276 test_cmp_rev HEAD^ copy &&
277 test "$(cat new_file)" = dirty &&
278 test "$(cat file)" = "modified again"
281 test_expect_success
'pull --rebase: --autostash & rebase.autostash unset' '
282 test_unconfig rebase.autostash &&
283 git reset --hard before-rebase &&
284 echo dirty >new_file &&
286 git pull --rebase --autostash . copy &&
287 test_cmp_rev HEAD^ copy &&
288 test "$(cat new_file)" = dirty &&
289 test "$(cat file)" = "modified again"
292 test_expect_success
'pull --rebase --no-autostash & rebase.autostash=true' '
293 test_config rebase.autostash true &&
294 git reset --hard before-rebase &&
295 echo dirty >new_file &&
297 test_must_fail git pull --rebase --no-autostash . copy 2>err &&
298 test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err
301 test_expect_success
'pull --rebase --no-autostash & rebase.autostash=false' '
302 test_config rebase.autostash false &&
303 git reset --hard before-rebase &&
304 echo dirty >new_file &&
306 test_must_fail git pull --rebase --no-autostash . copy 2>err &&
307 test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err
310 test_expect_success
'pull --rebase --no-autostash & rebase.autostash unset' '
311 test_unconfig rebase.autostash &&
312 git reset --hard before-rebase &&
313 echo dirty >new_file &&
315 test_must_fail git pull --rebase --no-autostash . copy 2>err &&
316 test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err
319 test_expect_success
'pull --autostash (without --rebase) should error out' '
320 test_must_fail git pull --autostash . copy 2>actual &&
321 echo "fatal: --[no-]autostash option is only valid with --rebase." >expect &&
322 test_i18ncmp actual expect
325 test_expect_success
'pull --no-autostash (without --rebase) should error out' '
326 test_must_fail git pull --no-autostash . copy 2>actual &&
327 echo "fatal: --[no-]autostash option is only valid with --rebase." >expect &&
328 test_i18ncmp actual expect
331 test_expect_success
'pull.rebase' '
332 git reset --hard before-rebase &&
333 test_config pull.rebase true &&
335 test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
336 test new = "$(git show HEAD:file2)"
339 test_expect_success
'branch.to-rebase.rebase' '
340 git reset --hard before-rebase &&
341 test_config branch.to-rebase.rebase true &&
343 test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
344 test new = "$(git show HEAD:file2)"
347 test_expect_success
'branch.to-rebase.rebase should override pull.rebase' '
348 git reset --hard before-rebase &&
349 test_config pull.rebase true &&
350 test_config branch.to-rebase.rebase false &&
352 test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
353 test new = "$(git show HEAD:file2)"
356 # add a feature branch, keep-merge, that is merged into master, so the
357 # test can try preserving the merge commit (or not) with various
358 # --rebase flags/pull.rebase settings.
359 test_expect_success
'preserve merge setup' '
360 git reset --hard before-rebase &&
361 git checkout -b keep-merge second^ &&
363 git checkout to-rebase &&
364 git merge keep-merge &&
365 git tag before-preserve-rebase
368 test_expect_success
'pull.rebase=false create a new merge commit' '
369 git reset --hard before-preserve-rebase &&
370 test_config pull.rebase false &&
372 test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
373 test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
374 test file3 = "$(git show HEAD:file3.t)"
377 test_expect_success
'pull.rebase=true flattens keep-merge' '
378 git reset --hard before-preserve-rebase &&
379 test_config pull.rebase true &&
381 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
382 test file3 = "$(git show HEAD:file3.t)"
385 test_expect_success
'pull.rebase=1 is treated as true and flattens keep-merge' '
386 git reset --hard before-preserve-rebase &&
387 test_config pull.rebase 1 &&
389 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
390 test file3 = "$(git show HEAD:file3.t)"
393 test_expect_success
'pull.rebase=preserve rebases and merges keep-merge' '
394 git reset --hard before-preserve-rebase &&
395 test_config pull.rebase preserve &&
397 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
398 test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
401 test_expect_success
'pull.rebase=interactive' '
402 write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
403 echo I was here >fake.out &&
406 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
407 test_must_fail git pull --rebase=interactive . copy &&
408 test "I was here" = "$(cat fake.out)"
411 test_expect_success
'pull.rebase=invalid fails' '
412 git reset --hard before-preserve-rebase &&
413 test_config pull.rebase invalid &&
417 test_expect_success
'--rebase=false create a new merge commit' '
418 git reset --hard before-preserve-rebase &&
419 test_config pull.rebase true &&
420 git pull --rebase=false . copy &&
421 test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
422 test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
423 test file3 = "$(git show HEAD:file3.t)"
426 test_expect_success
'--rebase=true rebases and flattens keep-merge' '
427 git reset --hard before-preserve-rebase &&
428 test_config pull.rebase preserve &&
429 git pull --rebase=true . copy &&
430 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
431 test file3 = "$(git show HEAD:file3.t)"
434 test_expect_success
'--rebase=preserve rebases and merges keep-merge' '
435 git reset --hard before-preserve-rebase &&
436 test_config pull.rebase true &&
437 git pull --rebase=preserve . copy &&
438 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
439 test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
442 test_expect_success
'--rebase=invalid fails' '
443 git reset --hard before-preserve-rebase &&
444 ! git pull --rebase=invalid . copy
447 test_expect_success
'--rebase overrides pull.rebase=preserve and flattens keep-merge' '
448 git reset --hard before-preserve-rebase &&
449 test_config pull.rebase preserve &&
450 git pull --rebase . copy &&
451 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
452 test file3 = "$(git show HEAD:file3.t)"
455 test_expect_success
'--rebase with rebased upstream' '
457 git remote add -f me . &&
460 git reset --hard HEAD^ &&
461 echo conflicting modification > file &&
462 git commit -m conflict file &&
463 git checkout to-rebase &&
465 git commit -m to-rebase file2 &&
466 git tag to-rebase-orig &&
467 git pull --rebase me copy &&
468 test "conflicting modification" = "$(cat file)" &&
469 test file = "$(cat file2)"
473 test_expect_success
'--rebase -f with rebased upstream' '
474 test_when_finished "test_might_fail git rebase --abort" &&
475 git reset --hard to-rebase-orig &&
476 git pull --rebase -f me copy &&
477 test "conflicting modification" = "$(cat file)" &&
478 test file = "$(cat file2)"
481 test_expect_success
'--rebase with rebased default upstream' '
483 git update-ref refs/remotes/me/copy copy-orig &&
484 git checkout --track -b to-rebase2 me/copy &&
485 git reset --hard to-rebase-orig &&
487 test "conflicting modification" = "$(cat file)" &&
488 test file = "$(cat file2)"
492 test_expect_success
'rebased upstream + fetch + pull --rebase' '
494 git update-ref refs/remotes/me/copy copy-orig &&
495 git reset --hard to-rebase-orig &&
496 git checkout --track -b to-rebase3 me/copy &&
497 git reset --hard to-rebase-orig &&
500 test "conflicting modification" = "$(cat file)" &&
501 test file = "$(cat file2)"
505 test_expect_success
'pull --rebase dies early with dirty working directory' '
507 git checkout to-rebase &&
508 git update-ref refs/remotes/me/copy copy^ &&
509 COPY="$(git rev-parse --verify me/copy)" &&
510 git rebase --onto $COPY copy &&
511 test_config branch.to-rebase.remote me &&
512 test_config branch.to-rebase.merge refs/heads/copy &&
513 test_config branch.to-rebase.rebase true &&
514 echo dirty >> file &&
516 test_must_fail git pull &&
517 test "$COPY" = "$(git rev-parse --verify me/copy)" &&
518 git checkout HEAD -- file &&
520 test "$COPY" != "$(git rev-parse --verify me/copy)"
524 test_expect_success
'pull --rebase works on branch yet to be born' '
525 git rev-parse master >expect &&
529 git pull --rebase .. master &&
530 git rev-parse HEAD >../actual
532 test_cmp expect actual
535 test_expect_success
'pull --rebase fails on unborn branch with staged changes' '
536 test_when_finished "rm -rf empty_repo2" &&
537 git init empty_repo2 &&
540 echo staged-file >staged-file &&
541 git add staged-file &&
542 test "$(git ls-files)" = staged-file &&
543 test_must_fail git pull --rebase .. master 2>err &&
544 test "$(git ls-files)" = staged-file &&
545 test "$(git show :staged-file)" = staged-file &&
546 test_i18ngrep "unborn branch with changes added to the index" err
550 test_expect_success
'setup for detecting upstreamed changes' '
554 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
556 git commit -m "Initial revision"
560 modify s/5/43/ stuff &&
561 git commit -a -m "5->43" &&
562 modify s/6/42/ stuff &&
563 git commit -a -m "Make it bigger"
566 modify s/5/43/ stuff &&
567 git commit -a -m "Independent discovery of 5->43"
571 test_expect_success
'git pull --rebase detects upstreamed changes' '
574 test -z "$(git ls-files -u)"
578 test_expect_success
'setup for avoiding reapplying old patches' '
580 test_might_fail git rebase --abort &&
581 git reset --hard origin/master
583 git clone --bare src src-replace.git &&
585 mv src-replace.git src &&
587 modify s/2/22/ stuff &&
588 git commit -a -m "Change 2" &&
589 modify s/3/33/ stuff &&
590 git commit -a -m "Change 3" &&
591 modify s/4/44/ stuff &&
592 git commit -a -m "Change 4" &&
595 modify s/44/55/ stuff &&
596 git commit --amend -a -m "Modified Change 4"
600 test_expect_success
'git pull --rebase does not reapply old patches' '
602 test_must_fail git pull --rebase &&
603 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
607 test_expect_success
'git pull --rebase against local branch' '
608 git checkout -b copy2 to-rebase-orig &&
609 git pull --rebase . to-rebase &&
610 test "conflicting modification" = "$(cat file)" &&
611 test file = "$(cat file2)"