872d765b5c396713909d81e289d5554ee48cd99f
1#!/bin/sh
2
3test_description='pulling into void'
4
5. ./test-lib.sh
6
7modify () {
8 sed -e "$1" <"$2" >"$2.x" &&
9 mv "$2.x" "$2"
10}
11
12test_expect_success setup '
13 echo file >file &&
14 git add file &&
15 git commit -a -m original
16'
17
18test_expect_success 'pulling into void' '
19 git init cloned &&
20 (
21 cd cloned &&
22 git pull ..
23 ) &&
24 test -f file &&
25 test -f cloned/file &&
26 test_cmp file cloned/file
27'
28
29test_expect_success 'pulling into void using master:master' '
30 git init cloned-uho &&
31 (
32 cd cloned-uho &&
33 git pull .. master:master
34 ) &&
35 test -f file &&
36 test -f cloned-uho/file &&
37 test_cmp file cloned-uho/file
38'
39
40test_expect_success 'pulling into void does not overwrite untracked files' '
41 git init cloned-untracked &&
42 (
43 cd cloned-untracked &&
44 echo untracked >file &&
45 test_must_fail git pull .. master &&
46 echo untracked >expect &&
47 test_cmp expect file
48 )
49'
50
51test_expect_success 'pulling into void does not overwrite staged files' '
52 git init cloned-staged-colliding &&
53 (
54 cd cloned-staged-colliding &&
55 echo "alternate content" >file &&
56 git add 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
62 )
63'
64
65test_expect_success 'pulling into void does not remove new staged files' '
66 git init cloned-staged-new &&
67 (
68 cd cloned-staged-new &&
69 echo "new tracked file" >newfile &&
70 git add newfile &&
71 git pull .. master &&
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
76 )
77'
78
79test_expect_success 'pulling into void must not create an octopus' '
80 git init cloned-octopus &&
81 (
82 cd cloned-octopus &&
83 test_must_fail git pull .. master master &&
84 ! test -f file
85 )
86'
87
88test_expect_success 'test . as a remote' '
89
90 git branch copy master &&
91 git config branch.copy.remote . &&
92 git config branch.copy.merge refs/heads/master &&
93 echo updated >file &&
94 git commit -a -m updated &&
95 git checkout copy &&
96 test "$(cat file)" = file &&
97 git pull &&
98 test "$(cat file)" = updated
99'
100
101test_expect_success 'the default remote . should not break explicit pull' '
102 git checkout -b second master^ &&
103 echo modified >file &&
104 git commit -a -m modified &&
105 git checkout copy &&
106 git reset --hard HEAD^ &&
107 test "$(cat file)" = file &&
108 git pull . second &&
109 test "$(cat file)" = modified
110'
111
112test_expect_success 'fail if wildcard spec does not match any refs' '
113 git checkout -b test copy^ &&
114 test_when_finished "git checkout -f copy && git branch -D test" &&
115 test "$(cat file)" = file &&
116 test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
117 test_i18ngrep "no candidates for merging" err &&
118 test "$(cat file)" = file
119'
120
121test_expect_success 'fail if no branches specified with non-default remote' '
122 git remote add test_remote . &&
123 test_when_finished "git remote remove test_remote" &&
124 git checkout -b test copy^ &&
125 test_when_finished "git checkout -f copy && git branch -D test" &&
126 test "$(cat file)" = file &&
127 test_config branch.test.remote origin &&
128 test_must_fail git pull test_remote 2>err &&
129 test_i18ngrep "specify a branch on the command line" err &&
130 test "$(cat file)" = file
131'
132
133test_expect_success 'fail if not on a branch' '
134 git remote add origin . &&
135 test_when_finished "git remote remove origin" &&
136 git checkout HEAD^ &&
137 test_when_finished "git checkout -f copy" &&
138 test "$(cat file)" = file &&
139 test_must_fail git pull 2>err &&
140 test_i18ngrep "not currently on a branch" err &&
141 test "$(cat file)" = file
142'
143
144test_expect_success 'fail if no configuration for current branch' '
145 git remote add test_remote . &&
146 test_when_finished "git remote remove test_remote" &&
147 git checkout -b test copy^ &&
148 test_when_finished "git checkout -f copy && git branch -D test" &&
149 test_config branch.test.remote test_remote &&
150 test "$(cat file)" = file &&
151 test_must_fail git pull 2>err &&
152 test_i18ngrep "no tracking information" err &&
153 test "$(cat file)" = file
154'
155
156test_expect_success 'fail if upstream branch does not exist' '
157 git checkout -b test copy^ &&
158 test_when_finished "git checkout -f copy && git branch -D test" &&
159 test_config branch.test.remote . &&
160 test_config branch.test.merge refs/heads/nonexisting &&
161 test "$(cat file)" = file &&
162 test_must_fail git pull 2>err &&
163 test_i18ngrep "no such ref was fetched" err &&
164 test "$(cat file)" = file
165'
166
167test_expect_success 'fail if the index has unresolved entries' '
168 git checkout -b third second^ &&
169 test_when_finished "git checkout -f copy && git branch -D third" &&
170 test "$(cat file)" = file &&
171 test_commit modified2 file &&
172 test -z "$(git ls-files -u)" &&
173 test_must_fail git pull . second &&
174 test -n "$(git ls-files -u)" &&
175 cp file expected &&
176 test_must_fail git pull . second 2>err &&
177 test_i18ngrep "Pull is not possible because you have unmerged files" err &&
178 test_cmp expected file &&
179 git add file &&
180 test -z "$(git ls-files -u)" &&
181 test_must_fail git pull . second 2>err &&
182 test_i18ngrep "You have not concluded your merge" err &&
183 test_cmp expected file
184'
185
186test_expect_success 'fast-forwards working tree if branch head is updated' '
187 git checkout -b third second^ &&
188 test_when_finished "git checkout -f copy && git branch -D third" &&
189 test "$(cat file)" = file &&
190 git pull . second:third 2>err &&
191 test_i18ngrep "fetch updated the current branch head" err &&
192 test "$(cat file)" = modified &&
193 test "$(git rev-parse third)" = "$(git rev-parse second)"
194'
195
196test_expect_success 'fast-forward fails with conflicting work tree' '
197 git checkout -b third second^ &&
198 test_when_finished "git checkout -f copy && git branch -D third" &&
199 test "$(cat file)" = file &&
200 echo conflict >file &&
201 test_must_fail git pull . second:third 2>err &&
202 test_i18ngrep "Cannot fast-forward your working tree" err &&
203 test "$(cat file)" = conflict &&
204 test "$(git rev-parse third)" = "$(git rev-parse second)"
205'
206
207test_expect_success '--rebase' '
208 git branch to-rebase &&
209 echo modified again > file &&
210 git commit -m file file &&
211 git checkout to-rebase &&
212 echo new > file2 &&
213 git add file2 &&
214 git commit -m "new file" &&
215 git tag before-rebase &&
216 git pull --rebase . copy &&
217 test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
218 test new = "$(git show HEAD:file2)"
219'
220test_expect_success 'pull.rebase' '
221 git reset --hard before-rebase &&
222 test_config pull.rebase true &&
223 git pull . copy &&
224 test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
225 test new = "$(git show HEAD:file2)"
226'
227
228test_expect_success 'branch.to-rebase.rebase' '
229 git reset --hard before-rebase &&
230 test_config branch.to-rebase.rebase true &&
231 git pull . copy &&
232 test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
233 test new = "$(git show HEAD:file2)"
234'
235
236test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
237 git reset --hard before-rebase &&
238 test_config pull.rebase true &&
239 test_config branch.to-rebase.rebase false &&
240 git pull . copy &&
241 test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
242 test new = "$(git show HEAD:file2)"
243'
244
245# add a feature branch, keep-merge, that is merged into master, so the
246# test can try preserving the merge commit (or not) with various
247# --rebase flags/pull.rebase settings.
248test_expect_success 'preserve merge setup' '
249 git reset --hard before-rebase &&
250 git checkout -b keep-merge second^ &&
251 test_commit file3 &&
252 git checkout to-rebase &&
253 git merge keep-merge &&
254 git tag before-preserve-rebase
255'
256
257test_expect_success 'pull.rebase=false create a new merge commit' '
258 git reset --hard before-preserve-rebase &&
259 test_config pull.rebase false &&
260 git pull . copy &&
261 test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
262 test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
263 test file3 = "$(git show HEAD:file3.t)"
264'
265
266test_expect_success 'pull.rebase=true flattens keep-merge' '
267 git reset --hard before-preserve-rebase &&
268 test_config pull.rebase true &&
269 git pull . copy &&
270 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
271 test file3 = "$(git show HEAD:file3.t)"
272'
273
274test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
275 git reset --hard before-preserve-rebase &&
276 test_config pull.rebase 1 &&
277 git pull . copy &&
278 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
279 test file3 = "$(git show HEAD:file3.t)"
280'
281
282test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
283 git reset --hard before-preserve-rebase &&
284 test_config pull.rebase preserve &&
285 git pull . copy &&
286 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
287 test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
288'
289
290test_expect_success 'pull.rebase=invalid fails' '
291 git reset --hard before-preserve-rebase &&
292 test_config pull.rebase invalid &&
293 ! git pull . copy
294'
295
296test_expect_success '--rebase=false create a new merge commit' '
297 git reset --hard before-preserve-rebase &&
298 test_config pull.rebase true &&
299 git pull --rebase=false . copy &&
300 test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
301 test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
302 test file3 = "$(git show HEAD:file3.t)"
303'
304
305test_expect_success '--rebase=true rebases and flattens keep-merge' '
306 git reset --hard before-preserve-rebase &&
307 test_config pull.rebase preserve &&
308 git pull --rebase=true . copy &&
309 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
310 test file3 = "$(git show HEAD:file3.t)"
311'
312
313test_expect_success '--rebase=preserve rebases and merges keep-merge' '
314 git reset --hard before-preserve-rebase &&
315 test_config pull.rebase true &&
316 git pull --rebase=preserve . copy &&
317 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
318 test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
319'
320
321test_expect_success '--rebase=invalid fails' '
322 git reset --hard before-preserve-rebase &&
323 ! git pull --rebase=invalid . copy
324'
325
326test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
327 git reset --hard before-preserve-rebase &&
328 test_config pull.rebase preserve &&
329 git pull --rebase . copy &&
330 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
331 test file3 = "$(git show HEAD:file3.t)"
332'
333
334test_expect_success '--rebase with rebased upstream' '
335
336 git remote add -f me . &&
337 git checkout copy &&
338 git tag copy-orig &&
339 git reset --hard HEAD^ &&
340 echo conflicting modification > file &&
341 git commit -m conflict file &&
342 git checkout to-rebase &&
343 echo file > file2 &&
344 git commit -m to-rebase file2 &&
345 git tag to-rebase-orig &&
346 git pull --rebase me copy &&
347 test "conflicting modification" = "$(cat file)" &&
348 test file = "$(cat file2)"
349
350'
351
352test_expect_success '--rebase with rebased default upstream' '
353
354 git update-ref refs/remotes/me/copy copy-orig &&
355 git checkout --track -b to-rebase2 me/copy &&
356 git reset --hard to-rebase-orig &&
357 git pull --rebase &&
358 test "conflicting modification" = "$(cat file)" &&
359 test file = "$(cat file2)"
360
361'
362
363test_expect_success 'rebased upstream + fetch + pull --rebase' '
364
365 git update-ref refs/remotes/me/copy copy-orig &&
366 git reset --hard to-rebase-orig &&
367 git checkout --track -b to-rebase3 me/copy &&
368 git reset --hard to-rebase-orig &&
369 git fetch &&
370 git pull --rebase &&
371 test "conflicting modification" = "$(cat file)" &&
372 test file = "$(cat file2)"
373
374'
375
376test_expect_success 'pull --rebase dies early with dirty working directory' '
377
378 git checkout to-rebase &&
379 git update-ref refs/remotes/me/copy copy^ &&
380 COPY="$(git rev-parse --verify me/copy)" &&
381 git rebase --onto $COPY copy &&
382 test_config branch.to-rebase.remote me &&
383 test_config branch.to-rebase.merge refs/heads/copy &&
384 test_config branch.to-rebase.rebase true &&
385 echo dirty >> file &&
386 git add file &&
387 test_must_fail git pull &&
388 test "$COPY" = "$(git rev-parse --verify me/copy)" &&
389 git checkout HEAD -- file &&
390 git pull &&
391 test "$COPY" != "$(git rev-parse --verify me/copy)"
392
393'
394
395test_expect_success 'pull --rebase works on branch yet to be born' '
396 git rev-parse master >expect &&
397 mkdir empty_repo &&
398 (cd empty_repo &&
399 git init &&
400 git pull --rebase .. master &&
401 git rev-parse HEAD >../actual
402 ) &&
403 test_cmp expect actual
404'
405
406test_expect_success 'setup for detecting upstreamed changes' '
407 mkdir src &&
408 (cd src &&
409 git init &&
410 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
411 git add stuff &&
412 git commit -m "Initial revision"
413 ) &&
414 git clone src dst &&
415 (cd src &&
416 modify s/5/43/ stuff &&
417 git commit -a -m "5->43" &&
418 modify s/6/42/ stuff &&
419 git commit -a -m "Make it bigger"
420 ) &&
421 (cd dst &&
422 modify s/5/43/ stuff &&
423 git commit -a -m "Independent discovery of 5->43"
424 )
425'
426
427test_expect_success 'git pull --rebase detects upstreamed changes' '
428 (cd dst &&
429 git pull --rebase &&
430 test -z "$(git ls-files -u)"
431 )
432'
433
434test_expect_success 'setup for avoiding reapplying old patches' '
435 (cd dst &&
436 test_might_fail git rebase --abort &&
437 git reset --hard origin/master
438 ) &&
439 git clone --bare src src-replace.git &&
440 rm -rf src &&
441 mv src-replace.git src &&
442 (cd dst &&
443 modify s/2/22/ stuff &&
444 git commit -a -m "Change 2" &&
445 modify s/3/33/ stuff &&
446 git commit -a -m "Change 3" &&
447 modify s/4/44/ stuff &&
448 git commit -a -m "Change 4" &&
449 git push &&
450
451 modify s/44/55/ stuff &&
452 git commit --amend -a -m "Modified Change 4"
453 )
454'
455
456test_expect_success 'git pull --rebase does not reapply old patches' '
457 (cd dst &&
458 test_must_fail git pull --rebase &&
459 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
460 )
461'
462
463test_expect_success 'git pull --rebase against local branch' '
464 git checkout -b copy2 to-rebase-orig &&
465 git pull --rebase . to-rebase &&
466 test "conflicting modification" = "$(cat file)" &&
467 test file = "$(cat file2)"
468'
469
470test_done