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