3 test_description='pulling into void'
8 sed -e "$1" <"$2" >"$2.x" &&
14 test_expect_success setup '
18 git commit -a -m original
22 test_expect_success 'pulling into void' '
31 test_expect_success 'checking the results' '
33 test -f cloned/file &&
34 test_cmp file cloned/file
37 test_expect_success 'pulling into void using master:master' '
42 git pull .. master:master
45 test -f cloned-uho/file &&
46 test_cmp file cloned-uho/file
49 test_expect_success 'pulling into void does not overwrite untracked files' '
50 git init cloned-untracked &&
52 cd cloned-untracked &&
53 echo untracked >file &&
54 test_must_fail git pull .. master &&
55 echo untracked >expect &&
60 test_expect_success 'pulling into void does not overwrite staged files' '
61 git init cloned-staged-colliding &&
63 cd cloned-staged-colliding &&
64 echo "alternate content" >file &&
66 test_must_fail git pull .. master &&
67 echo "alternate content" >expect &&
68 test_cmp expect file &&
69 git cat-file blob :file >file.index &&
70 test_cmp expect file.index
75 test_expect_success 'pulling into void does not remove new staged files' '
76 git init cloned-staged-new &&
78 cd cloned-staged-new &&
79 echo "new tracked file" >newfile &&
82 echo "new tracked file" >expect &&
83 test_cmp expect newfile &&
84 git cat-file blob :newfile >newfile.index &&
85 test_cmp expect newfile.index
89 test_expect_success 'test . as a remote' '
91 git branch copy master &&
92 git config branch.copy.remote . &&
93 git config branch.copy.merge refs/heads/master &&
95 git commit -a -m updated &&
97 test `cat file` = file &&
99 test `cat file` = updated
102 test_expect_success 'the default remote . should not break explicit pull' '
103 git checkout -b second master^ &&
104 echo modified >file &&
105 git commit -a -m modified &&
107 git reset --hard HEAD^ &&
108 test `cat file` = file &&
110 test `cat file` = modified
113 test_expect_success '--rebase' '
114 git branch to-rebase &&
115 echo modified again > file &&
116 git commit -m file file &&
117 git checkout to-rebase &&
120 git commit -m "new file" &&
121 git tag before-rebase &&
122 git pull --rebase . copy &&
123 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
124 test new = $(git show HEAD:file2)
126 test_expect_success 'pull.mode=rebase' '
127 git reset --hard before-rebase &&
128 test_config pull.mode rebase &&
130 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
131 test new = $(git show HEAD:file2)
134 test_expect_success 'branch.to-rebase.pullmode=rebase' '
135 git reset --hard before-rebase &&
136 test_config branch.to-rebase.pullmode rebase &&
138 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
139 test new = $(git show HEAD:file2)
142 test_expect_success 'branch.to-rebase.pullmode should override pull.mode' '
143 git reset --hard before-rebase &&
144 test_config pull.mode merge &&
145 test_config branch.to-rebase.pullmode merge &&
147 test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
148 test new = $(git show HEAD:file2)
151 # add a feature branch, keep-merge, that is merged into master, so the
152 # test can try preserving the merge commit (or not) with various
153 # --rebase flags/pull.mode settings.
154 test_expect_success 'preserve merge setup' '
155 git reset --hard before-rebase &&
156 git checkout -b keep-merge second^ &&
158 git checkout to-rebase &&
159 git merge keep-merge &&
160 git tag before-preserve-rebase
163 test_expect_success 'pull.mode=merge create a new merge commit' '
164 git reset --hard before-preserve-rebase &&
165 test_config pull.mode merge &&
167 test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
168 test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
169 test file3 = $(git show HEAD:file3.t)
172 test_expect_success 'pull.mode=rebase flattens keep-merge' '
173 git reset --hard before-preserve-rebase &&
174 test_config pull.mode rebase &&
176 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
177 test file3 = $(git show HEAD:file3.t)
180 test_expect_success 'pull.mode=rebase-preserve rebases and merges keep-merge' '
181 git reset --hard before-preserve-rebase &&
182 test_config pull.mode rebase-preserve &&
184 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
185 test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
188 test_expect_success 'pull.mode=invalid fails' '
189 git reset --hard before-preserve-rebase &&
190 test_config pull.mode invalid &&
194 test_expect_success '--rebase=false create a new merge commit' '
195 git reset --hard before-preserve-rebase &&
196 test_config pull.mode rebase &&
197 git pull --rebase=false . copy &&
198 test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
199 test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
200 test file3 = $(git show HEAD:file3.t)
203 test_expect_success '--rebase=true rebases and flattens keep-merge' '
204 git reset --hard before-preserve-rebase &&
205 test_config pull.mode rebase-preserve &&
206 git pull --rebase=true . copy &&
207 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
208 test file3 = $(git show HEAD:file3.t)
211 test_expect_success '--rebase=preserve rebases and merges keep-merge' '
212 git reset --hard before-preserve-rebase &&
213 test_config pull.mode rebase &&
214 git pull --rebase=preserve . copy &&
215 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
216 test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
219 test_expect_success '--rebase=invalid fails' '
220 git reset --hard before-preserve-rebase &&
221 ! git pull --rebase=invalid . copy
224 test_expect_success '--rebase overrides pull.mode=rebase-preserve and flattens keep-merge' '
225 git reset --hard before-preserve-rebase &&
226 test_config pull.mode rebase-preserve &&
227 git pull --rebase . copy &&
228 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
229 test file3 = $(git show HEAD:file3.t)
232 test_expect_success '--rebase with rebased upstream' '
234 git remote add -f me . &&
237 git reset --hard HEAD^ &&
238 echo conflicting modification > file &&
239 git commit -m conflict file &&
240 git checkout to-rebase &&
242 git commit -m to-rebase file2 &&
243 git tag to-rebase-orig &&
244 git pull --rebase me copy &&
245 test "conflicting modification" = "$(cat file)" &&
246 test file = $(cat file2)
250 test_expect_success '--rebase with rebased default upstream' '
252 git update-ref refs/remotes/me/copy copy-orig &&
253 git checkout --track -b to-rebase2 me/copy &&
254 git reset --hard to-rebase-orig &&
256 test "conflicting modification" = "$(cat file)" &&
257 test file = $(cat file2)
261 test_expect_success 'rebased upstream + fetch + pull --rebase' '
263 git update-ref refs/remotes/me/copy copy-orig &&
264 git reset --hard to-rebase-orig &&
265 git checkout --track -b to-rebase3 me/copy &&
266 git reset --hard to-rebase-orig &&
269 test "conflicting modification" = "$(cat file)" &&
270 test file = "$(cat file2)"
274 test_expect_success 'pull --rebase dies early with dirty working directory' '
276 git checkout to-rebase &&
277 git update-ref refs/remotes/me/copy copy^ &&
278 COPY=$(git rev-parse --verify me/copy) &&
279 git rebase --onto $COPY copy &&
280 test_config branch.to-rebase.remote me &&
281 test_config branch.to-rebase.merge refs/heads/copy &&
282 test_config branch.to-rebase.rebase true &&
283 echo dirty >> file &&
285 test_must_fail git pull &&
286 test $COPY = $(git rev-parse --verify me/copy) &&
287 git checkout HEAD -- file &&
289 test $COPY != $(git rev-parse --verify me/copy)
293 test_expect_success 'pull --rebase works on branch yet to be born' '
294 git rev-parse master >expect &&
298 git pull --rebase .. master &&
299 git rev-parse HEAD >../actual
301 test_cmp expect actual
304 test_expect_success 'setup for detecting upstreamed changes' '
308 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
310 git commit -m "Initial revision"
314 modify s/5/43/ stuff &&
315 git commit -a -m "5->43" &&
316 modify s/6/42/ stuff &&
317 git commit -a -m "Make it bigger"
320 modify s/5/43/ stuff &&
321 git commit -a -m "Independent discovery of 5->43"
325 test_expect_success 'git pull --rebase detects upstreamed changes' '
328 test -z "$(git ls-files -u)"
332 test_expect_success 'setup for avoiding reapplying old patches' '
334 test_might_fail git rebase --abort &&
335 git reset --hard origin/master
337 git clone --bare src src-replace.git &&
339 mv src-replace.git src &&
341 modify s/2/22/ stuff &&
342 git commit -a -m "Change 2" &&
343 modify s/3/33/ stuff &&
344 git commit -a -m "Change 3" &&
345 modify s/4/44/ stuff &&
346 git commit -a -m "Change 4" &&
349 modify s/44/55/ stuff &&
350 git commit --amend -a -m "Modified Change 4"
354 test_expect_success 'git pull --rebase does not reapply old patches' '
356 test_must_fail git pull --rebase &&
357 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
361 test_expect_success 'git pull --rebase against local branch' '
362 git checkout -b copy2 to-rebase-orig &&
363 git pull --rebase . to-rebase &&
364 test "conflicting modification" = "$(cat file)" &&
365 test file = "$(cat file2)"
368 test_expect_success 'pull.mode' '
369 git checkout to-rebase &&
370 git reset --hard before-rebase &&
371 test_config pull.mode rebase &&
373 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
374 test new = $(git show HEAD:file2)
377 test_expect_success 'branch.to-rebase.pullmode' '
378 git reset --hard before-rebase &&
379 test_config branch.to-rebase.pullmode rebase &&
381 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
382 test new = $(git show HEAD:file2)
385 test_expect_success 'branch.to-rebase.pullmode should override pull.mode' '
386 git reset --hard before-rebase &&
387 test_config pull.mode rebase &&
388 test_config branch.to-rebase.pullmode merge &&
390 test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
391 test new = $(git show HEAD:file2)
394 test_expect_success 'git pull fast-forward' '
395 test_when_finished "git checkout master && git branch -D other test" &&
396 test_config pull.mode merge-ff-only &&
397 git checkout -b other master &&
401 git checkout -b test -t other &&
402 git reset --hard master &&
406 test_expect_success 'git pull non-fast-forward' '
407 test_when_finished "git checkout master && git branch -D other test" &&
408 test_config pull.mode merge-ff-only &&
409 git checkout -b other master^ &&
413 git checkout -b test -t other &&
414 git reset --hard master &&
415 test_must_fail git pull
418 test_expect_success 'git pull non-fast-forward (merge)' '
419 test_when_finished "git checkout master && git branch -D other test" &&
420 test_config pull.mode merge-ff-only &&
421 git checkout -b other master^ &&
425 git checkout -b test -t other &&
426 git reset --hard master &&