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
12D=`pwd`
13
14test_expect_success setup '
15
16 echo file >file &&
17 git add file &&
18 git commit -a -m original
19
20'
21
22test_expect_success 'pulling into void' '
23 mkdir cloned &&
24 cd cloned &&
25 git init &&
26 git pull ..
27'
28
29cd "$D"
30
31test_expect_success 'checking the results' '
32 test -f file &&
33 test -f cloned/file &&
34 test_cmp file cloned/file
35'
36
37test_expect_success 'pulling into void using master:master' '
38 mkdir cloned-uho &&
39 (
40 cd cloned-uho &&
41 git init &&
42 git pull .. master:master
43 ) &&
44 test -f file &&
45 test -f cloned-uho/file &&
46 test_cmp file cloned-uho/file
47'
48
49test_expect_success 'pulling into void does not overwrite untracked files' '
50 git init cloned-untracked &&
51 (
52 cd cloned-untracked &&
53 echo untracked >file &&
54 test_must_fail git pull .. master &&
55 echo untracked >expect &&
56 test_cmp expect file
57 )
58'
59
60test_expect_success 'pulling into void does not overwrite staged files' '
61 git init cloned-staged-colliding &&
62 (
63 cd cloned-staged-colliding &&
64 echo "alternate content" >file &&
65 git add 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
71 )
72'
73
74
75test_expect_success 'pulling into void does not remove new staged files' '
76 git init cloned-staged-new &&
77 (
78 cd cloned-staged-new &&
79 echo "new tracked file" >newfile &&
80 git add newfile &&
81 git pull .. master &&
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
86 )
87'
88
89test_expect_success 'test . as a remote' '
90
91 git branch copy master &&
92 git config branch.copy.remote . &&
93 git config branch.copy.merge refs/heads/master &&
94 echo updated >file &&
95 git commit -a -m updated &&
96 git checkout copy &&
97 test `cat file` = file &&
98 git pull &&
99 test `cat file` = updated
100'
101
102test_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 &&
106 git checkout copy &&
107 git reset --hard HEAD^ &&
108 test `cat file` = file &&
109 git pull . second &&
110 test `cat file` = modified
111'
112
113test_expect_success '--rebase' '
114 git branch to-rebase &&
115 echo modified again > file &&
116 git commit -m file file &&
117 git checkout to-rebase &&
118 echo new > file2 &&
119 git add file2 &&
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)
125'
126test_expect_success 'pull.rebase' '
127 git reset --hard before-rebase &&
128 test_config pull.rebase true &&
129 git pull . copy &&
130 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
131 test new = $(git show HEAD:file2)
132'
133
134test_expect_success 'branch.to-rebase.rebase' '
135 git reset --hard before-rebase &&
136 test_config branch.to-rebase.rebase true &&
137 git pull . copy &&
138 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
139 test new = $(git show HEAD:file2)
140'
141
142test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
143 git reset --hard before-rebase &&
144 test_config pull.rebase true &&
145 test_config branch.to-rebase.rebase false &&
146 git pull . copy &&
147 test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
148 test new = $(git show HEAD:file2)
149'
150
151test_expect_success '--rebase with rebased upstream' '
152
153 git remote add -f me . &&
154 git checkout copy &&
155 git tag copy-orig &&
156 git reset --hard HEAD^ &&
157 echo conflicting modification > file &&
158 git commit -m conflict file &&
159 git checkout to-rebase &&
160 echo file > file2 &&
161 git commit -m to-rebase file2 &&
162 git tag to-rebase-orig &&
163 git pull --rebase me copy &&
164 test "conflicting modification" = "$(cat file)" &&
165 test file = $(cat file2)
166
167'
168
169test_expect_success '--rebase with rebased default upstream' '
170
171 git update-ref refs/remotes/me/copy copy-orig &&
172 git checkout --track -b to-rebase2 me/copy &&
173 git reset --hard to-rebase-orig &&
174 git pull --rebase &&
175 test "conflicting modification" = "$(cat file)" &&
176 test file = $(cat file2)
177
178'
179
180test_expect_success 'rebased upstream + fetch + pull --rebase' '
181
182 git update-ref refs/remotes/me/copy copy-orig &&
183 git reset --hard to-rebase-orig &&
184 git checkout --track -b to-rebase3 me/copy &&
185 git reset --hard to-rebase-orig &&
186 git fetch &&
187 git pull --rebase &&
188 test "conflicting modification" = "$(cat file)" &&
189 test file = "$(cat file2)"
190
191'
192
193test_expect_success 'pull --rebase dies early with dirty working directory' '
194
195 git checkout to-rebase &&
196 git update-ref refs/remotes/me/copy copy^ &&
197 COPY=$(git rev-parse --verify me/copy) &&
198 git rebase --onto $COPY copy &&
199 test_config branch.to-rebase.remote me &&
200 test_config branch.to-rebase.merge refs/heads/copy &&
201 test_config branch.to-rebase.rebase true &&
202 echo dirty >> file &&
203 git add file &&
204 test_must_fail git pull &&
205 test $COPY = $(git rev-parse --verify me/copy) &&
206 git checkout HEAD -- file &&
207 git pull &&
208 test $COPY != $(git rev-parse --verify me/copy)
209
210'
211
212test_expect_success 'pull --rebase works on branch yet to be born' '
213 git rev-parse master >expect &&
214 mkdir empty_repo &&
215 (cd empty_repo &&
216 git init &&
217 git pull --rebase .. master &&
218 git rev-parse HEAD >../actual
219 ) &&
220 test_cmp expect actual
221'
222
223test_expect_success 'setup for detecting upstreamed changes' '
224 mkdir src &&
225 (cd src &&
226 git init &&
227 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
228 git add stuff &&
229 git commit -m "Initial revision"
230 ) &&
231 git clone src dst &&
232 (cd src &&
233 modify s/5/43/ stuff &&
234 git commit -a -m "5->43" &&
235 modify s/6/42/ stuff &&
236 git commit -a -m "Make it bigger"
237 ) &&
238 (cd dst &&
239 modify s/5/43/ stuff &&
240 git commit -a -m "Independent discovery of 5->43"
241 )
242'
243
244test_expect_success 'git pull --rebase detects upstreamed changes' '
245 (cd dst &&
246 git pull --rebase &&
247 test -z "$(git ls-files -u)"
248 )
249'
250
251test_expect_success 'setup for avoiding reapplying old patches' '
252 (cd dst &&
253 test_might_fail git rebase --abort &&
254 git reset --hard origin/master
255 ) &&
256 git clone --bare src src-replace.git &&
257 rm -rf src &&
258 mv src-replace.git src &&
259 (cd dst &&
260 modify s/2/22/ stuff &&
261 git commit -a -m "Change 2" &&
262 modify s/3/33/ stuff &&
263 git commit -a -m "Change 3" &&
264 modify s/4/44/ stuff &&
265 git commit -a -m "Change 4" &&
266 git push &&
267
268 modify s/44/55/ stuff &&
269 git commit --amend -a -m "Modified Change 4"
270 )
271'
272
273test_expect_success 'git pull --rebase does not reapply old patches' '
274 (cd dst &&
275 test_must_fail git pull --rebase &&
276 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
277 )
278'
279
280test_expect_success 'git pull --rebase against local branch' '
281 git checkout -b copy2 to-rebase-orig &&
282 git pull --rebase . to-rebase &&
283 test "conflicting modification" = "$(cat file)" &&
284 test file = "$(cat file2)"
285'
286
287test_done