1#!/usr/bin/env bash
2
3. lib
4
5rm -rf temp1 temp2
6
7darcs init temp1
8cd temp1
9
10cd ..
11darcs init temp2
12cd temp2
13
14mkdir one
15cd one
16mkdir two
17cd two
18# darcs pull should work relative to the current directory
19darcs pull -a ../../../temp1 | grep -i 'No remote patches to pull in'
20
21# darcs pull should pull into repo specified with --repo
22cd ../..  # now in temp2
23darcs add one;
24darcs record --name uno --all
25cd ..     # now outside of any repo
26darcs pull --set-default --repodir temp1 --all temp2 | grep -i 'Finished pulling.' # temp2 is not relative to temp1
27
28# set up server repo
29date > temp2/one/date.t
30darcs add --repodir ./temp2 one/date.t
31darcs record --repodir ./temp2 -a -m foo
32
33# set up client repo for failure
34if echo $OS | grep -i windows; then
35    echo this test does not work on windows because it
36    echo is not possible to chmod -r
37elif whoami | grep root; then
38    echo root never gets permission denied
39else
40    chmod a-rwx ./temp1/one # remove all permissions
41    not darcs pull --repodir ./temp1 -a 2> err
42    chmod u+rwx temp1/one # restore permission
43    grep 'permission denied' err
44    rm -rf temp1/one
45fi
46
47cd temp1
48
49echo Before trying to pull from self, defaultrepo is something else
50not grep temp1 _darcs/prefs/defaultrepo
51
52#return special message when you try to pull from yourself
53DIR="`pwd`"
54not darcs pull --debug -a "$DIR" 2> out
55grep 'Can.t pull from current repository' out
56
57not darcs pull --debug -a . 2> out
58grep 'Can.t pull from current repository' out
59
60# and do not update the default repo to be the current di
61not grep temp1 _darcs/prefs/defaultrepo
62
63rm -f _darcs/prefs/defaultrepo
64not darcs pull 2> err
65grep 'please specify one' err
66echo . > _darcs/prefs/defaultrepo
67not darcs pull --debug 2> err
68grep 'Can.t pull from current repository' err
69
70not darcs pull --debug ../* 2> out
71not grep 'Can.t pull from current repository' out
72cd .. # now outside of any repo
73
74cd temp1
75echo a > foo
76darcs record -lam AA
77echo b > foo
78darcs record -lam BB
79echo c > foo
80darcs record -lam CC
81darcs rollback -p CC -a
82darcs record -am unC
83cd ..
84rm -rf temp2
85darcs get --to-patch B temp1 temp2
86cd temp2
87sleep 1 # So that rollback won't have same timestamp as get.
88darcs rollback -p BB -a
89darcs record -am unB
90darcs pull -a ../temp1 2> err2
91not grep 'Error applying patch' err2
92cd ..
93
94cd temp1
95echo -n foo > baz
96darcs add baz
97darcs record  -am newbaz
98cd ../temp2
99darcs pull -a | grep Finished
100echo -n bar > baz
101darcs record  -am bazbar
102cd ../temp1
103darcs pull ../temp2 -a
104echo -n bar > correct_baz
105diff baz correct_baz
106cd ..
107
108#   my $test_name = "when a patch creating a directory is attempted to be applied
109#       while a directory with that name already exists, a warning is raised, but
110#       the pull succeeds.";
111mkdir temp1/newdir
112cd temp1
113darcs add newdir
114darcs record -am newdir
115cd ../temp2
116mkdir newdir
117darcs pull -a --set-default ../temp1 &> out2
118grep Backing out2
119grep 'Finished pulling' out2
120grep newdir out2
121cd ..
122
123rm -rf temp1 temp2
124
125
126# issue662, which triggered:
127#  darcs failed:  Error applying hunk to file ./t.t
128#  Error applying patch to the working tree.
129
130darcs init temp1
131cd temp1
132
133touch t.t
134echo 'content'> t.t
135darcs record -lam 'initial add'
136echo 'content: remote change'> t.t
137darcs record -am 'remote change' --ignore
138cd ..
139darcs clone temp1 temp2
140cd temp2
141darcs obliterate --last 1 --all
142echo 'content: local change'> t.t
143# this is now recognized as a conflict with working:
144echo y | darcs pull -a ../temp1
145darcs w -s
146darcs revert -a
147cd ..
148rm -rf temp1 temp2
149
150# pull with conflicts
151
152darcs initialize temp1
153cd temp1
154echo foo > bar
155darcs record -lam addbar
156
157cd ..
158darcs clone temp1 temp2
159cd temp1
160date > bar
161darcs record -a -m datebar
162cd ../temp2
163echo aack >> bar
164darcs record -a -m aackbar
165darcs pull -a
166darcs check
167
168cd ..
169rm -rf temp1 temp2
170
171# pull --union
172
173rm -rf temp1 temp2 temp3
174
175darcs init temp1
176cd temp1
177echo A > A
178darcs record -lam A
179echo B > B
180darcs record -lam B
181
182cd ..
183darcs clone temp1 temp2
184
185cd temp2
186darcs obliterate --last 1 -a
187echo C > C
188darcs record -lam C
189cd ..
190
191darcs init temp3
192cd temp3
193darcs pull -a ../temp1 ../temp2
194
195darcs log > out
196grep A out
197grep B out
198grep C out
199
200cd ..
201rm -rf temp1 temp2 temp3
202
203# pull --intersection
204
205darcs init temp1
206cd temp1
207echo A > A
208darcs record -lam Aismyname
209echo B > B
210darcs record -lam Bismyname
211
212cd ..
213darcs clone temp1 temp2
214cd temp2
215darcs obliterate --last 1 -a
216echo C > C
217darcs record -lam Cismyname
218
219cd ..
220darcs init temp3
221cd temp3
222darcs pull -a --intersection ../temp1 ../temp2
223darcs log > out
224grep Aismyname out
225not grep Bismyname out
226not grep Cismyname out
227
228cd ..
229rm -rf temp1 temp2 temp3
230
231
232# pull --skip-conflicts
233rm -rf R S
234darcs init R
235cd R
236echo 'foo' > foo
237echo 'bar' > bar
238darcs rec -lam 'Add foo and bar'
239cd ..
240
241darcs clone R S
242
243cd R
244echo 'foo2' > foo
245darcs rec -lam 'Change foo (2)'
246echo 'bar2' > bar
247darcs rec -lam 'Change bar (2)'
248cd ..
249
250cd S
251echo 'foo3' > foo
252darcs rec -lam 'Change foo (3)'
253darcs pull --skip-conflicts -a ../R
254test `darcs log --count` -eq 3
255cd ..
256
257cd S
258darcs pull -a ../R
259test `darcs log --count` -eq 4
260cd ..
261rm -rf R S
262
263# bad pending after pull
264
265rm -fr temp1 temp2
266
267darcs init temp1
268cd temp1
269echo abc > A
270echo def > B1
271darcs record -lam patch1
272darcs mv B1 B2
273darcs record -am patch2
274cd ..
275
276darcs init temp2
277cd temp2
278darcs pull -a ../temp1
279not darcs whatsnew
280cd ..
281
282rm -fr temp1 temp2
283
284# issue494: note that in this test, we deliberately select filenames
285# with a backwards sorting order
286darcs init temp1
287cd temp1
288echo abc > b
289darcs record -lam patch1
290darcs mv b a
291echo def > a
292darcs record -am patch2
293cd ..
294
295darcs init temp2
296cd temp2
297darcs pull --all ../temp1
298not darcs whatsnew
299cd ..
300
301rm -fr temp1 temp2
302
303# pull binary
304
305rm -rf temp1 temp2
306
307darcs init temp1
308cd temp1
309printf "%01048576d" 0 > foo
310darcs record -l -a -m xx
311rm foo
312darcs record -a -m yy
313cd ..
314
315darcs init temp2
316cd temp2
317echo yny | darcs pull --set-default ../temp1
318rm foo
319# for darcs-1 and darcs-3 this pull conflicts with unrecorded changes
320# (which is correct, whereas darcs-2 is buggy)
321if test "$format" != "darcs-2"; then
322  echo y | darcs pull -a
323else
324  darcs pull -a
325fi
326cd ..
327
328rm -rf temp1 temp2
329
330# pull --matches
331darcs init temp1
332cd temp1
333echo first > a
334darcs record -lam 'first'
335firsthash=`darcs log --xml | grep 'hash=' | sed -e "s/.*hash='//" -e "s/'>//"`
336echo second > b
337darcs record -lam 'second'
338cd ..
339
340darcs init temp2
341darcs pull --repodir temp2 -a --match "hash $firsthash" temp1
342test $(darcs log --count --repodir temp2) -eq 1
343
344darcs init temp3
345darcs pull --repodir temp3 -a --hash $firsthash temp1
346test $(darcs log --count --repodir temp3) -eq 1
347
348rm -rf temp1 temp2 temp3
349