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 git config --bool pull.rebase true &&
129 test_when_finished "git config --unset pull.rebase" &&
130 git pull . copy &&
131 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
132 test new = $(git show HEAD:file2)
133'
134
135test_expect_success 'branch.to-rebase.rebase' '
136 git reset --hard before-rebase &&
137 git config --bool branch.to-rebase.rebase true &&
138 test_when_finished "git config --unset branch.to-rebase.rebase" &&
139 git pull . copy &&
140 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
141 test new = $(git show HEAD:file2)
142'
143
144test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
145 git reset --hard before-rebase &&
146 git config --bool pull.rebase true &&
147 test_when_finished "git config --unset pull.rebase" &&
148 git config --bool branch.to-rebase.rebase false &&
149 test_when_finished "git config --unset branch.to-rebase.rebase" &&
150 git pull . copy &&
151 test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
152 test new = $(git show HEAD:file2)
153'
154
155test_expect_success '--rebase with rebased upstream' '
156
157 git remote add -f me . &&
158 git checkout copy &&
159 git tag copy-orig &&
160 git reset --hard HEAD^ &&
161 echo conflicting modification > file &&
162 git commit -m conflict file &&
163 git checkout to-rebase &&
164 echo file > file2 &&
165 git commit -m to-rebase file2 &&
166 git tag to-rebase-orig &&
167 git pull --rebase me copy &&
168 test "conflicting modification" = "$(cat file)" &&
169 test file = $(cat file2)
170
171'
172
173test_expect_success '--rebase with rebased default upstream' '
174
175 git update-ref refs/remotes/me/copy copy-orig &&
176 git checkout --track -b to-rebase2 me/copy &&
177 git reset --hard to-rebase-orig &&
178 git pull --rebase &&
179 test "conflicting modification" = "$(cat file)" &&
180 test file = $(cat file2)
181
182'
183
184test_expect_success 'rebased upstream + fetch + pull --rebase' '
185
186 git update-ref refs/remotes/me/copy copy-orig &&
187 git reset --hard to-rebase-orig &&
188 git checkout --track -b to-rebase3 me/copy &&
189 git reset --hard to-rebase-orig &&
190 git fetch &&
191 git pull --rebase &&
192 test "conflicting modification" = "$(cat file)" &&
193 test file = "$(cat file2)"
194
195'
196
197test_expect_success 'pull --rebase dies early with dirty working directory' '
198
199 git checkout to-rebase &&
200 git update-ref refs/remotes/me/copy copy^ &&
201 COPY=$(git rev-parse --verify me/copy) &&
202 git rebase --onto $COPY copy &&
203 git config branch.to-rebase.remote me &&
204 git config branch.to-rebase.merge refs/heads/copy &&
205 git config branch.to-rebase.rebase true &&
206 echo dirty >> file &&
207 git add file &&
208 test_must_fail git pull &&
209 test $COPY = $(git rev-parse --verify me/copy) &&
210 git checkout HEAD -- file &&
211 git pull &&
212 test $COPY != $(git rev-parse --verify me/copy)
213
214'
215
216test_expect_success 'pull --rebase works on branch yet to be born' '
217 git rev-parse master >expect &&
218 mkdir empty_repo &&
219 (cd empty_repo &&
220 git init &&
221 git pull --rebase .. master &&
222 git rev-parse HEAD >../actual
223 ) &&
224 test_cmp expect actual
225'
226
227test_expect_success 'setup for detecting upstreamed changes' '
228 mkdir src &&
229 (cd src &&
230 git init &&
231 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
232 git add stuff &&
233 git commit -m "Initial revision"
234 ) &&
235 git clone src dst &&
236 (cd src &&
237 modify s/5/43/ stuff &&
238 git commit -a -m "5->43" &&
239 modify s/6/42/ stuff &&
240 git commit -a -m "Make it bigger"
241 ) &&
242 (cd dst &&
243 modify s/5/43/ stuff &&
244 git commit -a -m "Independent discovery of 5->43"
245 )
246'
247
248test_expect_success 'git pull --rebase detects upstreamed changes' '
249 (cd dst &&
250 git pull --rebase &&
251 test -z "$(git ls-files -u)"
252 )
253'
254
255test_expect_success 'setup for avoiding reapplying old patches' '
256 (cd dst &&
257 test_might_fail git rebase --abort &&
258 git reset --hard origin/master
259 ) &&
260 git clone --bare src src-replace.git &&
261 rm -rf src &&
262 mv src-replace.git src &&
263 (cd dst &&
264 modify s/2/22/ stuff &&
265 git commit -a -m "Change 2" &&
266 modify s/3/33/ stuff &&
267 git commit -a -m "Change 3" &&
268 modify s/4/44/ stuff &&
269 git commit -a -m "Change 4" &&
270 git push &&
271
272 modify s/44/55/ stuff &&
273 git commit --amend -a -m "Modified Change 4"
274 )
275'
276
277test_expect_success 'git pull --rebase does not reapply old patches' '
278 (cd dst &&
279 test_must_fail git pull --rebase &&
280 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
281 )
282'
283
284test_expect_success 'git pull --rebase against local branch' '
285 git checkout -b copy2 to-rebase-orig &&
286 git pull --rebase . to-rebase &&
287 test "conflicting modification" = "$(cat file)" &&
288 test file = "$(cat file2)"
289'
290
291test_done