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