]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5520-pull.sh
Merge branch 'kk/complete-diff-color-moved'
[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
MJ
12test_pull_autostash () {
13 git reset --hard before-rebase &&
14 echo dirty >new_file &&
15 git add new_file &&
16 git pull "$@" . copy &&
17 test_cmp_rev HEAD^ copy &&
a1a64fdd
DL
18 echo dirty >expect &&
19 test_cmp expect new_file &&
20 echo "modified again" >expect &&
21 test_cmp expect file
5c82bcdd
MJ
22}
23
44a59fff
MJ
24test_pull_autostash_fail () {
25 git reset --hard before-rebase &&
26 echo dirty >new_file &&
27 git add new_file &&
28 test_must_fail git pull "$@" . copy 2>err &&
29 test_i18ngrep "uncommitted changes." err
30}
31
d09e79cb 32test_expect_success setup '
d09e79cb
LT
33 echo file >file &&
34 git add file &&
35 git commit -a -m original
d09e79cb
LT
36'
37
38test_expect_success 'pulling into void' '
55691133
JH
39 git init cloned &&
40 (
41 cd cloned &&
42 git pull ..
43 ) &&
ceeef863
DL
44 test_path_is_file file &&
45 test_path_is_file cloned/file &&
4fdf71be 46 test_cmp file cloned/file
d09e79cb
LT
47'
48
b0ad11ea 49test_expect_success 'pulling into void using master:master' '
55691133 50 git init cloned-uho &&
b0ad11ea
JH
51 (
52 cd cloned-uho &&
b0ad11ea
JH
53 git pull .. master:master
54 ) &&
ceeef863
DL
55 test_path_is_file file &&
56 test_path_is_file cloned-uho/file &&
b0ad11ea
JH
57 test_cmp file cloned-uho/file
58'
59
4b3ffe51
JK
60test_expect_success 'pulling into void does not overwrite untracked files' '
61 git init cloned-untracked &&
62 (
63 cd cloned-untracked &&
64 echo untracked >file &&
65 test_must_fail git pull .. master &&
66 echo untracked >expect &&
67 test_cmp expect file
68 )
69'
70
b4dc085a
TR
71test_expect_success 'pulling into void does not overwrite staged files' '
72 git init cloned-staged-colliding &&
73 (
74 cd cloned-staged-colliding &&
75 echo "alternate content" >file &&
76 git add 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
82 )
83'
84
b4dc085a
TR
85test_expect_success 'pulling into void does not remove new staged files' '
86 git init cloned-staged-new &&
87 (
88 cd cloned-staged-new &&
89 echo "new tracked file" >newfile &&
90 git add newfile &&
91 git pull .. master &&
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
96 )
97'
98
7ad39a27
JH
99test_expect_success 'pulling into void must not create an octopus' '
100 git init cloned-octopus &&
101 (
102 cd cloned-octopus &&
103 test_must_fail git pull .. master master &&
ceeef863 104 test_path_is_missing file
7ad39a27
JH
105 )
106'
107
9debc324 108test_expect_success 'test . as a remote' '
9debc324
PB
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 &&
114 git checkout copy &&
a1a64fdd
DL
115 echo file >expect &&
116 test_cmp expect file &&
9debc324 117 git pull &&
a1a64fdd
DL
118 echo updated >expect &&
119 test_cmp expect file &&
80ea984d
PT
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
9debc324
PB
124'
125
126test_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 &&
130 git checkout copy &&
131 git reset --hard HEAD^ &&
a1a64fdd
DL
132 echo file >expect &&
133 test_cmp expect file &&
9debc324 134 git pull . second &&
a1a64fdd
DL
135 echo modified >expect &&
136 test_cmp expect file &&
80ea984d
PT
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
9debc324
PB
141'
142
d12f455e
PT
143test_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" &&
a1a64fdd
DL
146 echo file >expect &&
147 test_cmp expect file &&
d12f455e
PT
148 test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
149 test_i18ngrep "no candidates for merging" err &&
a1a64fdd 150 test_cmp expect file
d12f455e
PT
151'
152
153test_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" &&
a1a64fdd
DL
158 echo file >expect &&
159 test_cmp expect file &&
d12f455e
PT
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 &&
a1a64fdd 163 test_cmp expect file
d12f455e
PT
164'
165
166test_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" &&
a1a64fdd
DL
171 echo file >expect &&
172 test_cmp expect file &&
d12f455e
PT
173 test_must_fail git pull 2>err &&
174 test_i18ngrep "not currently on a branch" err &&
a1a64fdd 175 test_cmp expect file
d12f455e
PT
176'
177
178test_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 &&
a1a64fdd
DL
184 echo file >expect &&
185 test_cmp expect file &&
d12f455e
PT
186 test_must_fail git pull 2>err &&
187 test_i18ngrep "no tracking information" err &&
a1a64fdd 188 test_cmp expect file
d12f455e
PT
189'
190
eb2a8d9e
PT
191test_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 &&
a1a64fdd
DL
197 echo file >expect &&
198 test_cmp expect file &&
eb2a8d9e
PT
199 test_must_fail git pull --all 2>err &&
200 test_i18ngrep "There is no tracking information" err &&
a1a64fdd 201 test_cmp expect file
eb2a8d9e
PT
202'
203
d12f455e
PT
204test_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 &&
a1a64fdd
DL
209 echo file >expect &&
210 test_cmp expect file &&
d12f455e
PT
211 test_must_fail git pull 2>err &&
212 test_i18ngrep "no such ref was fetched" err &&
a1a64fdd 213 test_cmp expect file
d12f455e
PT
214'
215
05438afc
PT
216test_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" &&
a1a64fdd
DL
219 echo file >expect &&
220 test_cmp expect file &&
05438afc 221 test_commit modified2 file &&
979f8891
DL
222 git ls-files -u >unmerged &&
223 test_must_be_empty unmerged &&
05438afc 224 test_must_fail git pull . second &&
979f8891
DL
225 git ls-files -u >unmerged &&
226 test_file_not_empty unmerged &&
05438afc
PT
227 cp file expected &&
228 test_must_fail git pull . second 2>err &&
8785c425 229 test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
05438afc
PT
230 test_cmp expected file &&
231 git add file &&
979f8891
DL
232 git ls-files -u >unmerged &&
233 test_must_be_empty unmerged &&
05438afc
PT
234 test_must_fail git pull . second 2>err &&
235 test_i18ngrep "You have not concluded your merge" err &&
236 test_cmp expected file
237'
238
9f992262
PT
239test_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" &&
a1a64fdd
DL
242 echo file >expect &&
243 test_cmp expect file &&
9f992262
PT
244 git pull . second:third 2>err &&
245 test_i18ngrep "fetch updated the current branch head" err &&
a1a64fdd
DL
246 echo modified >expect &&
247 test_cmp expect file &&
dd0f1e76 248 test_cmp_rev third second
9f992262
PT
249'
250
251test_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" &&
a1a64fdd
DL
254 echo file >expect &&
255 test_cmp expect file &&
9f992262
PT
256 echo conflict >file &&
257 test_must_fail git pull . second:third 2>err &&
258 test_i18ngrep "Cannot fast-forward your working tree" err &&
a1a64fdd
DL
259 echo conflict >expect &&
260 test_cmp expect file &&
dd0f1e76 261 test_cmp_rev third second
9f992262
PT
262'
263
cd67e4d4
JS
264test_expect_success '--rebase' '
265 git branch to-rebase &&
93a9bf87 266 echo modified again >file &&
cd67e4d4
JS
267 git commit -m file file &&
268 git checkout to-rebase &&
93a9bf87 269 echo new >file2 &&
cd67e4d4
JS
270 git add file2 &&
271 git commit -m "new file" &&
272 git tag before-rebase &&
273 git pull --rebase . copy &&
dd0f1e76 274 test_cmp_rev HEAD^ copy &&
5540ed27
DL
275 echo new >expect &&
276 git show HEAD:file2 >actual &&
277 test_cmp expect actual
cd67e4d4 278'
9570d67c 279
76340c81 280test_expect_success '--rebase (merge) fast forward' '
33b842a1
JH
281 git reset --hard before-rebase &&
282 git checkout -b ff &&
283 echo another modification >file &&
284 git commit -m third file &&
285
286 git checkout to-rebase &&
76340c81
EN
287 git -c rebase.backend=merge pull --rebase . ff &&
288 test_cmp_rev HEAD ff &&
289
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
295'
296
297test_expect_success '--rebase (am) fast forward' '
298 git reset --hard before-rebase &&
299
10cdb9f3 300 git -c rebase.backend=apply pull --rebase . ff &&
dd0f1e76 301 test_cmp_rev HEAD ff &&
33b842a1
JH
302
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
308'
309
f15e7cf5
TB
310test_expect_success '--rebase --autostash fast forward' '
311 test_when_finished "
312 git reset --hard
313 git checkout to-rebase
314 git branch -D to-rebase-ff
315 git branch -D behind" &&
316 git branch behind &&
317 git checkout -b to-rebase-ff &&
318 echo another modification >>file &&
319 git add file &&
320 git commit -m mod &&
321
322 git checkout behind &&
323 echo dirty >file &&
324 git pull --rebase --autostash . to-rebase-ff &&
dd0f1e76 325 test_cmp_rev HEAD to-rebase-ff
f15e7cf5
TB
326'
327
3be18b47
JS
328test_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 &&
332 git add seq.txt &&
333 test_tick &&
334 git commit -m "Add seq.txt" &&
335 echo 6 >>seq.txt &&
336 test_tick &&
337 git commit -m "Append to seq.txt" seq.txt &&
338 git checkout -b with-conflicts HEAD^ &&
339 echo conflicting >>seq.txt &&
340 test_tick &&
341 git commit -m "Create conflict" seq.txt &&
342 test_must_fail git pull --rebase . seq 2>err >out &&
2ac0d627 343 test_i18ngrep "Resolve all conflicts manually" err
3be18b47
JS
344'
345
346test_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 &&
2ac0d627 357 test_i18ngrep "Resolve all conflicts manually" err
3be18b47
JS
358'
359
9570d67c
PT
360test_expect_success '--rebase fails with multiple branches' '
361 git reset --hard before-rebase &&
362 test_must_fail git pull --rebase . copy master 2>err &&
dd0f1e76 363 test_cmp_rev HEAD before-rebase &&
9570d67c 364 test_i18ngrep "Cannot rebase onto multiple branches" err &&
5540ed27
DL
365 echo modified >expect &&
366 git show HEAD:file >actual &&
367 test_cmp expect actual
9570d67c
PT
368'
369
53c76dc0
KD
370test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
371 test_config rebase.autostash true &&
5c82bcdd 372 test_pull_autostash --rebase
53c76dc0
KD
373'
374
f66398eb
MJ
375test_expect_success 'pull --rebase --autostash & rebase.autostash=true' '
376 test_config rebase.autostash true &&
5c82bcdd 377 test_pull_autostash --rebase --autostash
f66398eb
MJ
378'
379
efa195d5 380test_expect_success 'pull --rebase --autostash & rebase.autostash=false' '
f66398eb 381 test_config rebase.autostash false &&
5c82bcdd 382 test_pull_autostash --rebase --autostash
f66398eb
MJ
383'
384
5c82bcdd 385test_expect_success 'pull --rebase --autostash & rebase.autostash unset' '
eff960b3 386 test_unconfig rebase.autostash &&
5c82bcdd 387 test_pull_autostash --rebase --autostash
f66398eb
MJ
388'
389
390test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' '
391 test_config rebase.autostash true &&
44a59fff 392 test_pull_autostash_fail --rebase --no-autostash
f66398eb
MJ
393'
394
395test_expect_success 'pull --rebase --no-autostash & rebase.autostash=false' '
396 test_config rebase.autostash false &&
44a59fff 397 test_pull_autostash_fail --rebase --no-autostash
f66398eb
MJ
398'
399
400test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' '
eff960b3 401 test_unconfig rebase.autostash &&
44a59fff 402 test_pull_autostash_fail --rebase --no-autostash
f66398eb
MJ
403'
404
16622979
MJ
405for i in --autostash --no-autostash
406do
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
410 '
411done
f66398eb 412
6b37dff1
ÆAB
413test_expect_success 'pull.rebase' '
414 git reset --hard before-rebase &&
9d6aa64d 415 test_config pull.rebase true &&
6b37dff1 416 git pull . copy &&
dd0f1e76 417 test_cmp_rev HEAD^ copy &&
5540ed27
DL
418 echo new >expect &&
419 git show HEAD:file2 >actual &&
420 test_cmp expect actual
6b37dff1 421'
cd67e4d4 422
450dd1dc
MJ
423test_expect_success 'pull --autostash & pull.rebase=true' '
424 test_config pull.rebase true &&
425 test_pull_autostash --autostash
426'
427
428test_expect_success 'pull --no-autostash & pull.rebase=true' '
429 test_config pull.rebase true &&
430 test_pull_autostash_fail --no-autostash
431'
432
cd67e4d4
JS
433test_expect_success 'branch.to-rebase.rebase' '
434 git reset --hard before-rebase &&
9d6aa64d 435 test_config branch.to-rebase.rebase true &&
cd67e4d4 436 git pull . copy &&
dd0f1e76 437 test_cmp_rev HEAD^ copy &&
5540ed27
DL
438 echo new >expect &&
439 git show HEAD:file2 >actual &&
440 test_cmp expect actual
cd67e4d4
JS
441'
442
6b37dff1
ÆAB
443test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
444 git reset --hard before-rebase &&
9d6aa64d
YD
445 test_config pull.rebase true &&
446 test_config branch.to-rebase.rebase false &&
6b37dff1 447 git pull . copy &&
dd0f1e76 448 test_cmp_rev ! HEAD^ copy &&
5540ed27
DL
449 echo new >expect &&
450 git show HEAD:file2 >actual &&
451 test_cmp expect actual
6b37dff1
ÆAB
452'
453
53c62b98 454test_expect_success 'pull --rebase warns on --verify-signatures' '
c57e501c
AH
455 git reset --hard before-rebase &&
456 git pull --rebase --verify-signatures . copy 2>err &&
dd0f1e76 457 test_cmp_rev HEAD^ copy &&
5540ed27
DL
458 echo new >expect &&
459 git show HEAD:file2 >actual &&
460 test_cmp expect actual &&
c57e501c
AH
461 test_i18ngrep "ignoring --verify-signatures for rebase" err
462'
463
53c62b98 464test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
c57e501c
AH
465 git reset --hard before-rebase &&
466 git pull --rebase --no-verify-signatures . copy 2>err &&
dd0f1e76 467 test_cmp_rev HEAD^ copy &&
5540ed27
DL
468 echo new >expect &&
469 git show HEAD:file2 >actual &&
470 test_cmp expect actual &&
c57e501c
AH
471 test_i18ngrep ! "verify-signatures" err
472'
473
66713ef3
SH
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.
477test_expect_success 'preserve merge setup' '
478 git reset --hard before-rebase &&
479 git checkout -b keep-merge second^ &&
480 test_commit file3 &&
481 git checkout to-rebase &&
482 git merge keep-merge &&
483 git tag before-preserve-rebase
484'
485
486test_expect_success 'pull.rebase=false create a new merge commit' '
487 git reset --hard before-preserve-rebase &&
488 test_config pull.rebase false &&
489 git pull . copy &&
dd0f1e76
DL
490 test_cmp_rev HEAD^1 before-preserve-rebase &&
491 test_cmp_rev HEAD^2 copy &&
5540ed27
DL
492 echo file3 >expect &&
493 git show HEAD:file3.t >actual &&
494 test_cmp expect actual
66713ef3
SH
495'
496
497test_expect_success 'pull.rebase=true flattens keep-merge' '
498 git reset --hard before-preserve-rebase &&
499 test_config pull.rebase true &&
500 git pull . copy &&
dd0f1e76 501 test_cmp_rev HEAD^^ copy &&
5540ed27
DL
502 echo file3 >expect &&
503 git show HEAD:file3.t >actual &&
504 test_cmp expect actual
66713ef3
SH
505'
506
507test_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 &&
510 git pull . copy &&
dd0f1e76 511 test_cmp_rev HEAD^^ copy &&
5540ed27
DL
512 echo file3 >expect &&
513 git show HEAD:file3.t >actual &&
514 test_cmp expect actual
66713ef3
SH
515'
516
11aad464
JS
517test_expect_success REBASE_P \
518 'pull.rebase=preserve rebases and merges keep-merge' '
66713ef3
SH
519 git reset --hard before-preserve-rebase &&
520 test_config pull.rebase preserve &&
521 git pull . copy &&
dd0f1e76
DL
522 test_cmp_rev HEAD^^ copy &&
523 test_cmp_rev HEAD^2 keep-merge
66713ef3
SH
524'
525
f5eb87b9
JS
526test_expect_success 'pull.rebase=interactive' '
527 write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
528 echo I was here >fake.out &&
529 false
530 EOF
531 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
46af44b0 532 test_when_finished "test_might_fail git rebase --abort" &&
f5eb87b9 533 test_must_fail git pull --rebase=interactive . copy &&
a1a64fdd
DL
534 echo "I was here" >expect &&
535 test_cmp expect fake.out
f5eb87b9
JS
536'
537
46af44b0
JS
538test_expect_success 'pull --rebase=i' '
539 write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF &&
540 echo I was here, too >fake.out &&
541 false
542 EOF
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 &&
a1a64fdd
DL
546 echo "I was here, too" >expect &&
547 test_cmp expect fake.out
46af44b0
JS
548'
549
66713ef3
SH
550test_expect_success 'pull.rebase=invalid fails' '
551 git reset --hard before-preserve-rebase &&
552 test_config pull.rebase invalid &&
2a022620 553 test_must_fail git pull . copy
66713ef3
SH
554'
555
556test_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 &&
dd0f1e76
DL
560 test_cmp_rev HEAD^1 before-preserve-rebase &&
561 test_cmp_rev HEAD^2 copy &&
5540ed27
DL
562 echo file3 >expect &&
563 git show HEAD:file3.t >actual &&
564 test_cmp expect actual
66713ef3
SH
565'
566
567test_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 &&
dd0f1e76 571 test_cmp_rev HEAD^^ copy &&
5540ed27
DL
572 echo file3 >expect &&
573 git show HEAD:file3.t >actual &&
574 test_cmp expect actual
66713ef3
SH
575'
576
11aad464
JS
577test_expect_success REBASE_P \
578 '--rebase=preserve rebases and merges keep-merge' '
66713ef3
SH
579 git reset --hard before-preserve-rebase &&
580 test_config pull.rebase true &&
581 git pull --rebase=preserve . copy &&
dd0f1e76
DL
582 test_cmp_rev HEAD^^ copy &&
583 test_cmp_rev HEAD^2 keep-merge
66713ef3
SH
584'
585
586test_expect_success '--rebase=invalid fails' '
587 git reset --hard before-preserve-rebase &&
2a022620 588 test_must_fail git pull --rebase=invalid . copy
66713ef3
SH
589'
590
591test_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 &&
dd0f1e76 595 test_cmp_rev HEAD^^ copy &&
5540ed27
DL
596 echo file3 >expect &&
597 git show HEAD:file3.t >actual &&
598 test_cmp expect actual
66713ef3
SH
599'
600
c85c7927 601test_expect_success '--rebase with rebased upstream' '
c85c7927
JS
602 git remote add -f me . &&
603 git checkout copy &&
e9460a66 604 git tag copy-orig &&
c85c7927 605 git reset --hard HEAD^ &&
93a9bf87 606 echo conflicting modification >file &&
c85c7927
JS
607 git commit -m conflict file &&
608 git checkout to-rebase &&
93a9bf87 609 echo file >file2 &&
c85c7927 610 git commit -m to-rebase file2 &&
e9460a66 611 git tag to-rebase-orig &&
c85c7927 612 git pull --rebase me copy &&
a1a64fdd
DL
613 echo "conflicting modification" >expect &&
614 test_cmp expect file &&
615 echo file >expect &&
616 test_cmp expect file2
c85c7927
JS
617'
618
eb2a8d9e
PT
619test_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 &&
a1a64fdd
DL
623 echo "conflicting modification" >expect &&
624 test_cmp expect file &&
625 echo file >expect &&
626 test_cmp expect file2
eb2a8d9e
PT
627'
628
e9460a66 629test_expect_success '--rebase with rebased default upstream' '
e9460a66
SB
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 &&
633 git pull --rebase &&
a1a64fdd
DL
634 echo "conflicting modification" >expect &&
635 test_cmp expect file &&
636 echo file >expect &&
637 test_cmp expect file2
e9460a66
SB
638'
639
d44e7126 640test_expect_success 'rebased upstream + fetch + pull --rebase' '
a418441b
SB
641
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 &&
646 git fetch &&
d44e7126 647 git pull --rebase &&
a1a64fdd
DL
648 echo "conflicting modification" >expect &&
649 test_cmp expect file &&
650 echo file >expect &&
651 test_cmp expect file2
a418441b
SB
652
653'
654
f9189cf8 655test_expect_success 'pull --rebase dies early with dirty working directory' '
e9460a66 656 git checkout to-rebase &&
f9189cf8 657 git update-ref refs/remotes/me/copy copy^ &&
c998b381 658 COPY="$(git rev-parse --verify me/copy)" &&
f9189cf8 659 git rebase --onto $COPY copy &&
790f2827
RR
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 &&
93a9bf87 663 echo dirty >>file &&
f9189cf8
JS
664 git add file &&
665 test_must_fail git pull &&
dd0f1e76 666 test_cmp_rev "$COPY" me/copy &&
f9189cf8
JS
667 git checkout HEAD -- file &&
668 git pull &&
dd0f1e76 669 test_cmp_rev ! "$COPY" me/copy
f9189cf8
JS
670'
671
19a7fcbf
JK
672test_expect_success 'pull --rebase works on branch yet to be born' '
673 git rev-parse master >expect &&
674 mkdir empty_repo &&
e8d1eaf9
DL
675 (
676 cd empty_repo &&
677 git init &&
678 git pull --rebase .. master &&
679 git rev-parse HEAD >../actual
19a7fcbf
JK
680 ) &&
681 test_cmp expect actual
682'
683
fa14ee77
PT
684test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
685 test_when_finished "rm -rf empty_repo2" &&
686 git init empty_repo2 &&
687 (
688 cd empty_repo2 &&
689 echo staged-file >staged-file &&
690 git add staged-file &&
5540ed27
DL
691 echo staged-file >expect &&
692 git ls-files >actual &&
693 test_cmp expect actual &&
fa14ee77 694 test_must_fail git pull --rebase .. master 2>err &&
5540ed27
DL
695 git ls-files >actual &&
696 test_cmp expect actual &&
5540ed27
DL
697 git show :staged-file >actual &&
698 test_cmp expect actual &&
fa14ee77
PT
699 test_i18ngrep "unborn branch with changes added to the index" err
700 )
701'
702
3506dc94
JK
703test_expect_success 'pull --rebase fails on corrupt HEAD' '
704 test_when_finished "rm -rf corrupt" &&
705 git init corrupt &&
706 (
707 cd corrupt &&
708 test_commit one &&
e959a18e
DL
709 git rev-parse --verify HEAD >head &&
710 obj=$(sed "s#^..#&/#" head) &&
3506dc94
JK
711 rm -f .git/objects/$obj &&
712 test_must_fail git pull --rebase
713 )
714'
715
3cee9236
EN
716test_expect_success 'setup for detecting upstreamed changes' '
717 mkdir src &&
e8d1eaf9
DL
718 (
719 cd src &&
720 git init &&
721 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
722 git add stuff &&
723 git commit -m "Initial revision"
3cee9236
EN
724 ) &&
725 git clone src dst &&
e8d1eaf9
DL
726 (
727 cd src &&
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"
3cee9236 732 ) &&
e8d1eaf9
DL
733 (
734 cd dst &&
735 modify s/5/43/ stuff &&
736 git commit -a -m "Independent discovery of 5->43"
3cee9236
EN
737 )
738'
739
cf65426d 740test_expect_success 'git pull --rebase detects upstreamed changes' '
e8d1eaf9
DL
741 (
742 cd dst &&
743 git pull --rebase &&
979f8891
DL
744 git ls-files -u >untracked &&
745 test_must_be_empty untracked
3cee9236
EN
746 )
747'
748
749test_expect_success 'setup for avoiding reapplying old patches' '
e8d1eaf9
DL
750 (
751 cd dst &&
752 test_might_fail git rebase --abort &&
753 git reset --hard origin/master
3cee9236
EN
754 ) &&
755 git clone --bare src src-replace.git &&
756 rm -rf src &&
757 mv src-replace.git src &&
e8d1eaf9
DL
758 (
759 cd dst &&
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" &&
766 git push &&
767
768 modify s/44/55/ stuff &&
769 git commit --amend -a -m "Modified Change 4"
3cee9236
EN
770 )
771'
772
cf65426d 773test_expect_success 'git pull --rebase does not reapply old patches' '
e8d1eaf9
DL
774 (
775 cd dst &&
776 test_must_fail git pull --rebase &&
2ac0d627
EN
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 &&
780 rm -f work
3cee9236
EN
781 )
782'
783
fe249b42
MZ
784test_expect_success 'git pull --rebase against local branch' '
785 git checkout -b copy2 to-rebase-orig &&
786 git pull --rebase . to-rebase &&
a1a64fdd
DL
787 echo "conflicting modification" >expect &&
788 test_cmp expect file &&
789 echo file >expect &&
790 test_cmp expect file2
fe249b42
MZ
791'
792
d09e79cb 793test_done