5195a218a25f26f32978f80c3a3566c3529d8e8c
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 'test . as a remote' '
80
81 git branch copy master &&
82 git config branch.copy.remote . &&
83 git config branch.copy.merge refs/heads/master &&
84 echo updated >file &&
85 git commit -a -m updated &&
86 git checkout copy &&
87 test `cat file` = file &&
88 git pull &&
89 test `cat file` = updated
90'
91
92test_expect_success 'the default remote . should not break explicit pull' '
93 git checkout -b second master^ &&
94 echo modified >file &&
95 git commit -a -m modified &&
96 git checkout copy &&
97 git reset --hard HEAD^ &&
98 test `cat file` = file &&
99 git pull . second &&
100 test `cat file` = modified
101'
102
103test_expect_success '--rebase' '
104 git branch to-rebase &&
105 echo modified again > file &&
106 git commit -m file file &&
107 git checkout to-rebase &&
108 echo new > file2 &&
109 git add file2 &&
110 git commit -m "new file" &&
111 git tag before-rebase &&
112 git pull --rebase . copy &&
113 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
114 test new = $(git show HEAD:file2)
115'
116test_expect_success 'pull.rebase' '
117 git reset --hard before-rebase &&
118 test_config pull.rebase true &&
119 git pull . copy &&
120 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
121 test new = $(git show HEAD:file2)
122'
123
124test_expect_success 'branch.to-rebase.rebase' '
125 git reset --hard before-rebase &&
126 test_config branch.to-rebase.rebase true &&
127 git pull . copy &&
128 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
129 test new = $(git show HEAD:file2)
130'
131
132test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
133 git reset --hard before-rebase &&
134 test_config pull.rebase true &&
135 test_config branch.to-rebase.rebase false &&
136 git pull . copy &&
137 test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
138 test new = $(git show HEAD:file2)
139'
140
141# add a feature branch, keep-merge, that is merged into master, so the
142# test can try preserving the merge commit (or not) with various
143# --rebase flags/pull.rebase settings.
144test_expect_success 'preserve merge setup' '
145 git reset --hard before-rebase &&
146 git checkout -b keep-merge second^ &&
147 test_commit file3 &&
148 git checkout to-rebase &&
149 git merge keep-merge &&
150 git tag before-preserve-rebase
151'
152
153test_expect_success 'pull.rebase=false create a new merge commit' '
154 git reset --hard before-preserve-rebase &&
155 test_config pull.rebase false &&
156 git pull . copy &&
157 test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
158 test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
159 test file3 = $(git show HEAD:file3.t)
160'
161
162test_expect_success 'pull.rebase=true flattens keep-merge' '
163 git reset --hard before-preserve-rebase &&
164 test_config pull.rebase true &&
165 git pull . copy &&
166 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
167 test file3 = $(git show HEAD:file3.t)
168'
169
170test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
171 git reset --hard before-preserve-rebase &&
172 test_config pull.rebase 1 &&
173 git pull . copy &&
174 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
175 test file3 = $(git show HEAD:file3.t)
176'
177
178test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
179 git reset --hard before-preserve-rebase &&
180 test_config pull.rebase preserve &&
181 git pull . copy &&
182 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
183 test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
184'
185
186test_expect_success 'pull.rebase=invalid fails' '
187 git reset --hard before-preserve-rebase &&
188 test_config pull.rebase invalid &&
189 ! git pull . copy
190'
191
192test_expect_success '--rebase=false create a new merge commit' '
193 git reset --hard before-preserve-rebase &&
194 test_config pull.rebase true &&
195 git pull --rebase=false . copy &&
196 test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
197 test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
198 test file3 = $(git show HEAD:file3.t)
199'
200
201test_expect_success '--rebase=true rebases and flattens keep-merge' '
202 git reset --hard before-preserve-rebase &&
203 test_config pull.rebase preserve &&
204 git pull --rebase=true . copy &&
205 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
206 test file3 = $(git show HEAD:file3.t)
207'
208
209test_expect_success '--rebase=preserve rebases and merges keep-merge' '
210 git reset --hard before-preserve-rebase &&
211 test_config pull.rebase true &&
212 git pull --rebase=preserve . copy &&
213 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
214 test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
215'
216
217test_expect_success '--rebase=invalid fails' '
218 git reset --hard before-preserve-rebase &&
219 ! git pull --rebase=invalid . copy
220'
221
222test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
223 git reset --hard before-preserve-rebase &&
224 test_config pull.rebase preserve &&
225 git pull --rebase . copy &&
226 test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
227 test file3 = $(git show HEAD:file3.t)
228'
229
230test_expect_success '--rebase with rebased upstream' '
231
232 git remote add -f me . &&
233 git checkout copy &&
234 git tag copy-orig &&
235 git reset --hard HEAD^ &&
236 echo conflicting modification > file &&
237 git commit -m conflict file &&
238 git checkout to-rebase &&
239 echo file > file2 &&
240 git commit -m to-rebase file2 &&
241 git tag to-rebase-orig &&
242 git pull --rebase me copy &&
243 test "conflicting modification" = "$(cat file)" &&
244 test file = $(cat file2)
245
246'
247
248test_expect_success '--rebase with rebased default upstream' '
249
250 git update-ref refs/remotes/me/copy copy-orig &&
251 git checkout --track -b to-rebase2 me/copy &&
252 git reset --hard to-rebase-orig &&
253 git pull --rebase &&
254 test "conflicting modification" = "$(cat file)" &&
255 test file = $(cat file2)
256
257'
258
259test_expect_success 'rebased upstream + fetch + pull --rebase' '
260
261 git update-ref refs/remotes/me/copy copy-orig &&
262 git reset --hard to-rebase-orig &&
263 git checkout --track -b to-rebase3 me/copy &&
264 git reset --hard to-rebase-orig &&
265 git fetch &&
266 git pull --rebase &&
267 test "conflicting modification" = "$(cat file)" &&
268 test file = "$(cat file2)"
269
270'
271
272test_expect_success 'pull --rebase dies early with dirty working directory' '
273
274 git checkout to-rebase &&
275 git update-ref refs/remotes/me/copy copy^ &&
276 COPY=$(git rev-parse --verify me/copy) &&
277 git rebase --onto $COPY copy &&
278 test_config branch.to-rebase.remote me &&
279 test_config branch.to-rebase.merge refs/heads/copy &&
280 test_config branch.to-rebase.rebase true &&
281 echo dirty >> file &&
282 git add file &&
283 test_must_fail git pull &&
284 test $COPY = $(git rev-parse --verify me/copy) &&
285 git checkout HEAD -- file &&
286 git pull &&
287 test $COPY != $(git rev-parse --verify me/copy)
288
289'
290
291test_expect_success 'pull --rebase works on branch yet to be born' '
292 git rev-parse master >expect &&
293 mkdir empty_repo &&
294 (cd empty_repo &&
295 git init &&
296 git pull --rebase .. master &&
297 git rev-parse HEAD >../actual
298 ) &&
299 test_cmp expect actual
300'
301
302test_expect_success 'setup for detecting upstreamed changes' '
303 mkdir src &&
304 (cd src &&
305 git init &&
306 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
307 git add stuff &&
308 git commit -m "Initial revision"
309 ) &&
310 git clone src dst &&
311 (cd src &&
312 modify s/5/43/ stuff &&
313 git commit -a -m "5->43" &&
314 modify s/6/42/ stuff &&
315 git commit -a -m "Make it bigger"
316 ) &&
317 (cd dst &&
318 modify s/5/43/ stuff &&
319 git commit -a -m "Independent discovery of 5->43"
320 )
321'
322
323test_expect_success 'git pull --rebase detects upstreamed changes' '
324 (cd dst &&
325 git pull --rebase &&
326 test -z "$(git ls-files -u)"
327 )
328'
329
330test_expect_success 'setup for avoiding reapplying old patches' '
331 (cd dst &&
332 test_might_fail git rebase --abort &&
333 git reset --hard origin/master
334 ) &&
335 git clone --bare src src-replace.git &&
336 rm -rf src &&
337 mv src-replace.git src &&
338 (cd dst &&
339 modify s/2/22/ stuff &&
340 git commit -a -m "Change 2" &&
341 modify s/3/33/ stuff &&
342 git commit -a -m "Change 3" &&
343 modify s/4/44/ stuff &&
344 git commit -a -m "Change 4" &&
345 git push &&
346
347 modify s/44/55/ stuff &&
348 git commit --amend -a -m "Modified Change 4"
349 )
350'
351
352test_expect_success 'git pull --rebase does not reapply old patches' '
353 (cd dst &&
354 test_must_fail git pull --rebase &&
355 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
356 )
357'
358
359test_expect_success 'git pull --rebase against local branch' '
360 git checkout -b copy2 to-rebase-orig &&
361 git pull --rebase . to-rebase &&
362 test "conflicting modification" = "$(cat file)" &&
363 test file = "$(cat file2)"
364'
365
366test_done