3 test_description='pulling into void'
8 sed -e "$1" <"$2" >"$2.x" &&
12 test_expect_success setup '
15 git commit -a -m original
18 test_expect_success 'pulling into void' '
25 test -f cloned/file &&
26 test_cmp file cloned/file
29 test_expect_success 'pulling into void using master:master' '
30 git init cloned-uho &&
33 git pull .. master:master
36 test -f cloned-uho/file &&
37 test_cmp file cloned-uho/file
40 test_expect_success 'pulling into void does not overwrite untracked files' '
41 git init cloned-untracked &&
43 cd cloned-untracked &&
44 echo untracked >file &&
45 test_must_fail git pull .. master &&
46 echo untracked >expect &&
51 test_expect_success 'pulling into void does not overwrite staged files' '
52 git init cloned-staged-colliding &&
54 cd cloned-staged-colliding &&
55 echo "alternate content" >file &&
57 test_must_fail git pull .. master &&
58 echo "alternate content" >expect &&
59 test_cmp expect file &&
60 git cat-file blob :file >file.index &&
61 test_cmp expect file.index
65 test_expect_success 'pulling into void does not remove new staged files' '
66 git init cloned-staged-new &&
68 cd cloned-staged-new &&
69 echo "new tracked file" >newfile &&
72 echo "new tracked file" >expect &&
73 test_cmp expect newfile &&
74 git cat-file blob :newfile >newfile.index &&
75 test_cmp expect newfile.index
79 test_expect_success 'pulling into void must not create an octopus' '
80 git init cloned-octopus &&
83 test_must_fail git pull .. master master &&
88 test_expect_success 'test . as a remote' '
89 git branch copy master &&
90 git config branch.copy.remote . &&
91 git config branch.copy.merge refs/heads/master &&
93 git commit -a -m updated &&
95 test "$(cat file)" = file &&
97 test "$(cat file)" = updated &&
98 git reflog -1 >reflog.actual &&
99 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
100 echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
101 test_cmp reflog.expected reflog.fuzzy
104 test_expect_success 'the default remote . should not break explicit pull' '
105 git checkout -b second master^ &&
106 echo modified >file &&
107 git commit -a -m modified &&
109 git reset --hard HEAD^ &&
110 test "$(cat file)" = file &&
112 test "$(cat file)" = modified &&
113 git reflog -1 >reflog.actual &&
114 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
115 echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
116 test_cmp reflog.expected reflog.fuzzy
119 test_expect_success 'fail if wildcard spec does not match any refs' '
120 git checkout -b test copy^ &&
121 test_when_finished "git checkout -f copy && git branch -D test" &&
122 test "$(cat file)" = file &&
123 test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
124 test_i18ngrep "no candidates for merging" err &&
125 test "$(cat file)" = file
128 test_expect_success 'fail if no branches specified with non-default remote' '
129 git remote add test_remote . &&
130 test_when_finished "git remote remove test_remote" &&
131 git checkout -b test copy^ &&
132 test_when_finished "git checkout -f copy && git branch -D test" &&
133 test "$(cat file)" = file &&
134 test_config branch.test.remote origin &&
135 test_must_fail git pull test_remote 2>err &&
136 test_i18ngrep "specify a branch on the command line" err &&
137 test "$(cat file)" = file
140 test_expect_success 'fail if not on a branch' '
141 git remote add origin . &&
142 test_when_finished "git remote remove origin" &&
143 git checkout HEAD^ &&
144 test_when_finished "git checkout -f copy" &&
145 test "$(cat file)" = file &&
146 test_must_fail git pull 2>err &&
147 test_i18ngrep "not currently on a branch" err &&
148 test "$(cat file)" = file
151 test_expect_success 'fail if no configuration for current branch' '
152 git remote add test_remote . &&
153 test_when_finished "git remote remove test_remote" &&
154 git checkout -b test copy^ &&
155 test_when_finished "git checkout -f copy && git branch -D test" &&
156 test_config branch.test.remote test_remote &&
157 test "$(cat file)" = file &&
158 test_must_fail git pull 2>err &&
159 test_i18ngrep "no tracking information" err &&
160 test "$(cat file)" = file
163 test_expect_success 'fail if upstream branch does not exist' '
164 git checkout -b test copy^ &&
165 test_when_finished "git checkout -f copy && git branch -D test" &&
166 test_config branch.test.remote . &&
167 test_config branch.test.merge refs/heads/nonexisting &&
168 test "$(cat file)" = file &&
169 test_must_fail git pull 2>err &&
170 test_i18ngrep "no such ref was fetched" err &&
171 test "$(cat file)" = file
174 test_expect_success 'fail if the index has unresolved entries' '
175 git checkout -b third second^ &&
176 test_when_finished "git checkout -f copy && git branch -D third" &&
177 test "$(cat file)" = file &&
178 test_commit modified2 file &&
179 test -z "$(git ls-files -u)" &&
180 test_must_fail git pull . second &&
181 test -n "$(git ls-files -u)" &&
183 test_must_fail git pull . second 2>err &&
184 test_i18ngrep "Pull is not possible because you have unmerged files" err &&
185 test_cmp expected file &&
187 test -z "$(git ls-files -u)" &&
188 test_must_fail git pull . second 2>err &&
189 test_i18ngrep "You have not concluded your merge" err &&
190 test_cmp expected file
193 test_expect_success 'fast-forwards working tree if branch head is updated' '
194 git checkout -b third second^ &&
195 test_when_finished "git checkout -f copy && git branch -D third" &&
196 test "$(cat file)" = file &&
197 git pull . second:third 2>err &&
198 test_i18ngrep "fetch updated the current branch head" err &&
199 test "$(cat file)" = modified &&
200 test "$(git rev-parse third)" = "$(git rev-parse second)"
203 test_expect_success 'fast-forward fails with conflicting work tree' '
204 git checkout -b third second^ &&
205 test_when_finished "git checkout -f copy && git branch -D third" &&
206 test "$(cat file)" = file &&
207 echo conflict >file &&
208 test_must_fail git pull . second:third 2>err &&
209 test_i18ngrep "Cannot fast-forward your working tree" err &&
210 test "$(cat file)" = conflict &&
211 test "$(git rev-parse third)" = "$(git rev-parse second)"
214 test_expect_success '--rebase' '
215 git branch to-rebase &&
216 echo modified again > file &&
217 git commit -m file file &&
218 git checkout to-rebase &&
221 git commit -m "new file" &&
222 git tag before-rebase &&
223 git pull --rebase . copy &&
224 test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
225 test new = "$(git show HEAD:file2)"
228 test_expect_success '--rebase fails with multiple branches' '
229 git reset --hard before-rebase &&
230 test_must_fail git pull --rebase . copy master 2>err &&
231 test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
232 test_i18ngrep "Cannot rebase onto multiple branches" err &&
233 test modified = "$(git show HEAD:file)"
236 test_expect_success 'pull.rebase' '
237 git reset --hard before-rebase &&
238 test_config pull.rebase true &&
240 test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
241 test new = "$(git show HEAD:file2)"
244 test_expect_success 'branch.to-rebase.rebase' '
245 git reset --hard before-rebase &&
246 test_config branch.to-rebase.rebase true &&
248 test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
249 test new = "$(git show HEAD:file2)"
252 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
253 git reset --hard before-rebase &&
254 test_config pull.rebase true &&
255 test_config branch.to-rebase.rebase false &&
257 test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
258 test new = "$(git show HEAD:file2)"
261 # add a feature branch, keep-merge, that is merged into master, so the
262 # test can try preserving the merge commit (or not) with various
263 # --rebase flags/pull.rebase settings.
264 test_expect_success 'preserve merge setup' '
265 git reset --hard before-rebase &&
266 git checkout -b keep-merge second^ &&
268 git checkout to-rebase &&
269 git merge keep-merge &&
270 git tag before-preserve-rebase
273 test_expect_success 'pull.rebase=false create a new merge commit' '
274 git reset --hard before-preserve-rebase &&
275 test_config pull.rebase false &&
277 test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
278 test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
279 test file3 = "$(git show HEAD:file3.t)"
282 test_expect_success 'pull.rebase=true flattens keep-merge' '
283 git reset --hard before-preserve-rebase &&
284 test_config pull.rebase true &&
286 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
287 test file3 = "$(git show HEAD:file3.t)"
290 test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
291 git reset --hard before-preserve-rebase &&
292 test_config pull.rebase 1 &&
294 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
295 test file3 = "$(git show HEAD:file3.t)"
298 test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
299 git reset --hard before-preserve-rebase &&
300 test_config pull.rebase preserve &&
302 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
303 test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
306 test_expect_success 'pull.rebase=invalid fails' '
307 git reset --hard before-preserve-rebase &&
308 test_config pull.rebase invalid &&
312 test_expect_success '--rebase=false create a new merge commit' '
313 git reset --hard before-preserve-rebase &&
314 test_config pull.rebase true &&
315 git pull --rebase=false . copy &&
316 test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
317 test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
318 test file3 = "$(git show HEAD:file3.t)"
321 test_expect_success '--rebase=true rebases and flattens keep-merge' '
322 git reset --hard before-preserve-rebase &&
323 test_config pull.rebase preserve &&
324 git pull --rebase=true . copy &&
325 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
326 test file3 = "$(git show HEAD:file3.t)"
329 test_expect_success '--rebase=preserve rebases and merges keep-merge' '
330 git reset --hard before-preserve-rebase &&
331 test_config pull.rebase true &&
332 git pull --rebase=preserve . copy &&
333 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
334 test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
337 test_expect_success '--rebase=invalid fails' '
338 git reset --hard before-preserve-rebase &&
339 ! git pull --rebase=invalid . copy
342 test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
343 git reset --hard before-preserve-rebase &&
344 test_config pull.rebase preserve &&
345 git pull --rebase . copy &&
346 test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
347 test file3 = "$(git show HEAD:file3.t)"
350 test_expect_success '--rebase with rebased upstream' '
352 git remote add -f me . &&
355 git reset --hard HEAD^ &&
356 echo conflicting modification > file &&
357 git commit -m conflict file &&
358 git checkout to-rebase &&
360 git commit -m to-rebase file2 &&
361 git tag to-rebase-orig &&
362 git pull --rebase me copy &&
363 test "conflicting modification" = "$(cat file)" &&
364 test file = "$(cat file2)"
368 test_expect_success '--rebase with rebased default upstream' '
370 git update-ref refs/remotes/me/copy copy-orig &&
371 git checkout --track -b to-rebase2 me/copy &&
372 git reset --hard to-rebase-orig &&
374 test "conflicting modification" = "$(cat file)" &&
375 test file = "$(cat file2)"
379 test_expect_success 'rebased upstream + fetch + pull --rebase' '
381 git update-ref refs/remotes/me/copy copy-orig &&
382 git reset --hard to-rebase-orig &&
383 git checkout --track -b to-rebase3 me/copy &&
384 git reset --hard to-rebase-orig &&
387 test "conflicting modification" = "$(cat file)" &&
388 test file = "$(cat file2)"
392 test_expect_success 'pull --rebase dies early with dirty working directory' '
394 git checkout to-rebase &&
395 git update-ref refs/remotes/me/copy copy^ &&
396 COPY="$(git rev-parse --verify me/copy)" &&
397 git rebase --onto $COPY copy &&
398 test_config branch.to-rebase.remote me &&
399 test_config branch.to-rebase.merge refs/heads/copy &&
400 test_config branch.to-rebase.rebase true &&
401 echo dirty >> file &&
403 test_must_fail git pull &&
404 test "$COPY" = "$(git rev-parse --verify me/copy)" &&
405 git checkout HEAD -- file &&
407 test "$COPY" != "$(git rev-parse --verify me/copy)"
411 test_expect_success 'pull --rebase works on branch yet to be born' '
412 git rev-parse master >expect &&
416 git pull --rebase .. master &&
417 git rev-parse HEAD >../actual
419 test_cmp expect actual
422 test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
423 test_when_finished "rm -rf empty_repo2" &&
424 git init empty_repo2 &&
427 echo staged-file >staged-file &&
428 git add staged-file &&
429 test "$(git ls-files)" = staged-file &&
430 test_must_fail git pull --rebase .. master 2>err &&
431 test "$(git ls-files)" = staged-file &&
432 test "$(git show :staged-file)" = staged-file &&
433 test_i18ngrep "unborn branch with changes added to the index" err
437 test_expect_success 'setup for detecting upstreamed changes' '
441 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
443 git commit -m "Initial revision"
447 modify s/5/43/ stuff &&
448 git commit -a -m "5->43" &&
449 modify s/6/42/ stuff &&
450 git commit -a -m "Make it bigger"
453 modify s/5/43/ stuff &&
454 git commit -a -m "Independent discovery of 5->43"
458 test_expect_success 'git pull --rebase detects upstreamed changes' '
461 test -z "$(git ls-files -u)"
465 test_expect_success 'setup for avoiding reapplying old patches' '
467 test_might_fail git rebase --abort &&
468 git reset --hard origin/master
470 git clone --bare src src-replace.git &&
472 mv src-replace.git src &&
474 modify s/2/22/ stuff &&
475 git commit -a -m "Change 2" &&
476 modify s/3/33/ stuff &&
477 git commit -a -m "Change 3" &&
478 modify s/4/44/ stuff &&
479 git commit -a -m "Change 4" &&
482 modify s/44/55/ stuff &&
483 git commit --amend -a -m "Modified Change 4"
487 test_expect_success 'git pull --rebase does not reapply old patches' '
489 test_must_fail git pull --rebase &&
490 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
494 test_expect_success 'git pull --rebase against local branch' '
495 git checkout -b copy2 to-rebase-orig &&
496 git pull --rebase . to-rebase &&
497 test "conflicting modification" = "$(cat file)" &&
498 test file = "$(cat file2)"