~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/tests/clients/cmdline/externals_tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
#  module_tests.py:  testing modules / external sources.
 
4
#
 
5
#  Subversion is a tool for revision control. 
 
6
#  See http://subversion.tigris.org for more information.
 
7
#    
 
8
# ====================================================================
 
9
# Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
10
#
 
11
# This software is licensed as described in the file COPYING, which
 
12
# you should have received as part of this distribution.  The terms
 
13
# are also available at http://subversion.tigris.org/license-1.html.
 
14
# If newer versions of this license are posted there, you may use a
 
15
# newer version instead, at your option.
 
16
#
 
17
######################################################################
 
18
 
 
19
# General modules
 
20
import shutil, string, sys, re, os
 
21
import warnings
 
22
 
 
23
# Our testing module
 
24
import svntest
 
25
from svntest import SVNAnyOutput
 
26
 
 
27
 
 
28
# (abbreviation)
 
29
Skip = svntest.testcase.Skip
 
30
XFail = svntest.testcase.XFail
 
31
Item = svntest.wc.StateItem
 
32
 
 
33
 
 
34
######################################################################
 
35
# Tests
 
36
#
 
37
#   Each test must return on success or raise on failure.
 
38
 
 
39
 
 
40
#----------------------------------------------------------------------
 
41
 
 
42
### todo: it's inefficient to keep calling externals_test_setup() for
 
43
### every test.  It's slow.  But it's very safe -- we're guaranteed to
 
44
### have a clean repository, built from the latest Subversion, with
 
45
### the svn:externals properties preset in a known way.  Right now I
 
46
### can't think of any other way to achieve that guarantee, so the
 
47
### result is that each individual test is slow.
 
48
 
 
49
def externals_test_setup(sbox):
 
50
  """Set up a repository in which some directories have the externals property,
 
51
  and set up another repository, referred to by some of those externals.
 
52
  Both repositories contain greek trees with five revisions worth of
 
53
  random changes, then in the sixth revision the first repository --
 
54
  and only the first -- has some externals properties set.  ### Later,
 
55
  test putting externals on the second repository. ###
 
56
 
 
57
  The arrangement of the externals in the first repository is:
 
58
 
 
59
     /A/C/     ==>  exdir_G       <scheme>:///<other_repos>/A/D/G
 
60
                    exdir_H  -r 1 <scheme>:///<other_repos>/A/D/H
 
61
 
 
62
     /A/D/     ==>  exdir_A          <scheme>:///<other_repos>/A
 
63
                    exdir_A/G        <scheme>:///<other_repos>/A/D/G
 
64
                    exdir_A/H  -r 3  <scheme>:///<other_repos>/A/D/H
 
65
                    x/y/z/blah       <scheme>:///<other_repos>/A/B
 
66
 
 
67
  NOTE: Before calling this, use externals_test_cleanup(SBOX) to
 
68
  remove a previous incarnation of the other repository.
 
69
  """
 
70
 
 
71
  sbox.build()
 
72
 
 
73
  svntest.main.safe_rmtree(sbox.wc_dir) # The test itself will recreate this
 
74
 
 
75
  wc_init_dir    = sbox.add_wc_path('init')  # just for setting up props
 
76
  repo_dir       = sbox.repo_dir
 
77
  repo_url       = sbox.repo_url
 
78
  other_repo_dir, other_repo_url = sbox.add_repo_path('other')
 
79
 
 
80
  # These files will get changed in revisions 2 through 5.
 
81
  mu_path = os.path.join(wc_init_dir, "A/mu")
 
82
  pi_path = os.path.join(wc_init_dir, "A/D/G/pi")
 
83
  lambda_path = os.path.join(wc_init_dir, "A/B/lambda")
 
84
  omega_path = os.path.join(wc_init_dir, "A/D/H/omega")
 
85
 
 
86
  # These are the directories on which `svn:externals' will be set, in
 
87
  # revision 6 on the first repo.
 
88
  C_path = os.path.join(wc_init_dir, "A/C")
 
89
  D_path = os.path.join(wc_init_dir, "A/D")
 
90
 
 
91
  # Create a working copy.
 
92
  svntest.actions.run_and_verify_svn("", None, [],
 
93
                                     'checkout',
 
94
                                     '--username', svntest.main.wc_author,
 
95
                                     '--password', svntest.main.wc_passwd,
 
96
                                     repo_url, wc_init_dir)
 
97
 
 
98
  # Make revisions 2 through 5, but don't bother with pre- and
 
99
  # post-commit status checks.
 
100
 
 
101
  svntest.main.file_append(mu_path, "\nAdded to mu in revision 2.\n")
 
102
  svntest.actions.run_and_verify_svn("", None, [],
 
103
                                     'ci', '-m', 'log msg',
 
104
                                     '--quiet', wc_init_dir)
 
105
 
 
106
  svntest.main.file_append(pi_path, "\nAdded to pi in revision 3.\n")
 
107
  svntest.actions.run_and_verify_svn("", None, [],
 
108
                                     'ci', '-m', 'log msg',
 
109
                                     '--quiet', wc_init_dir)
 
110
 
 
111
  svntest.main.file_append(lambda_path, "\nAdded to lambda in revision 4.\n")
 
112
  svntest.actions.run_and_verify_svn("", None, [],
 
113
                                     'ci', '-m', 'log msg',
 
114
                                     '--quiet', wc_init_dir)
 
115
 
 
116
  svntest.main.file_append(omega_path, "\nAdded to omega in revision 5.\n")
 
117
  svntest.actions.run_and_verify_svn("", None, [],
 
118
                                     'ci', '-m', 'log msg',
 
119
                                     '--quiet', wc_init_dir)
 
120
 
 
121
  # Get the whole working copy to revision 5.
 
122
  svntest.actions.run_and_verify_svn("", None, [], 'up', wc_init_dir)
 
123
 
 
124
  # Now copy the initial repository to create the "other" repository,
 
125
  # the one to which the first repository's `svn:externals' properties
 
126
  # will refer.  After this, both repositories have five revisions
 
127
  # of random stuff, with no svn:externals props set yet.
 
128
  svntest.main.copy_repos(repo_dir, other_repo_dir, 5)
 
129
 
 
130
  # Set up the externals properties on A/B/ and A/D/.
 
131
  externals_desc = \
 
132
           "exdir_G       " + other_repo_url + "/A/D/G" + "\n" + \
 
133
           "exdir_H  -r 1 " + other_repo_url + "/A/D/H" + "\n"
 
134
 
 
135
  tmp_f = os.tempnam(wc_init_dir, 'tmp')
 
136
  svntest.main.file_append(tmp_f, externals_desc)
 
137
  svntest.actions.run_and_verify_svn("", None, [],
 
138
                                     'pset',
 
139
                                     '-F', tmp_f, 'svn:externals', C_path)
 
140
   
 
141
  os.remove(tmp_f)
 
142
 
 
143
  externals_desc = \
 
144
           "exdir_A           " + other_repo_url + "/A"      + \
 
145
           "\n"                                              + \
 
146
           "exdir_A/G/        " + other_repo_url + "/A/D/G/" + \
 
147
           "\n"                                              + \
 
148
           "exdir_A/H   -r 1  " + other_repo_url + "/A/D/H"  + \
 
149
           "\n"                                              + \
 
150
           "x/y/z/blah        " + other_repo_url + "/A/B"    + \
 
151
           "\n"
 
152
 
 
153
  svntest.main.file_append(tmp_f, externals_desc)
 
154
  svntest.actions.run_and_verify_svn("", None, [], 'pset',
 
155
                                     '-F', tmp_f, 'svn:externals', D_path)
 
156
 
 
157
  os.remove(tmp_f)
 
158
 
 
159
  # Commit the property changes.
 
160
 
 
161
  expected_output = svntest.wc.State(wc_init_dir, {
 
162
    'A/C' : Item(verb='Sending'),
 
163
    'A/D' : Item(verb='Sending'),
 
164
    })
 
165
 
 
166
  expected_status = svntest.actions.get_virginal_state(wc_init_dir, 5)
 
167
  expected_status.tweak('A/C', 'A/D', wc_rev=6, status='  ')
 
168
 
 
169
  svntest.actions.run_and_verify_commit(wc_init_dir,
 
170
                                        expected_output,
 
171
                                        expected_status,
 
172
                                        None, None, None, None, None,
 
173
                                        wc_init_dir)
 
174
 
 
175
 
 
176
def change_external(path, new_val):
 
177
  """Change the value of the externals property on PATH to NEW_VAL,
 
178
  and commit the change."""
 
179
  tmp_f = os.tempnam(svntest.main.temp_dir, 'tmp')
 
180
  svntest.main.file_append(tmp_f, new_val)
 
181
  svntest.actions.run_and_verify_svn("", None, [], 'pset',
 
182
                                     '-F', tmp_f, 'svn:externals', path)
 
183
  svntest.actions.run_and_verify_svn("", None, [], 'ci',
 
184
                                     '-m', 'log msg', '--quiet', path)
 
185
  os.remove(tmp_f)
 
186
 
 
187
 
 
188
#----------------------------------------------------------------------
 
189
 
 
190
 
 
191
### todo: It would be great if everything used the new wc.py system to
 
192
### check output/status.  In fact, it would be great to do more output
 
193
### and status checking period!  But must first see how well the
 
194
### output checkers deal with multiple summary lines.  With external
 
195
### modules, you can get the first "Updated to revision X" line, and
 
196
### then there will be more "Updated to..." and "Checked out..." lines
 
197
### following it, one line for each new or changed external.
 
198
 
 
199
 
 
200
#----------------------------------------------------------------------
 
201
 
 
202
def checkout_with_externals(sbox):
 
203
  "test checkouts with externals"
 
204
 
 
205
  externals_test_setup(sbox)
 
206
 
 
207
  wc_dir         = sbox.wc_dir
 
208
  repo_dir       = sbox.repo_dir
 
209
  repo_url       = sbox.repo_url
 
210
 
 
211
  # Create a working copy.
 
212
  svntest.actions.run_and_verify_svn("", None, [],
 
213
                                     'checkout',
 
214
                                     '--username', svntest.main.wc_author,
 
215
                                     '--password', svntest.main.wc_passwd,
 
216
                                     repo_url, wc_dir)
 
217
 
 
218
  # Probe the working copy a bit, see if it's as expected.
 
219
  exdir_G_path    = os.path.join(wc_dir, "A", "C", "exdir_G")
 
220
  exdir_G_pi_path = os.path.join(exdir_G_path, "pi")
 
221
  exdir_H_path       = os.path.join(wc_dir, "A", "C", "exdir_H")
 
222
  exdir_H_omega_path = os.path.join(exdir_H_path, "omega")
 
223
  x_path     = os.path.join(wc_dir, "A", "D", "x")
 
224
  y_path     = os.path.join(x_path, "y")
 
225
  z_path     = os.path.join(y_path, "z")
 
226
  blah_path  = os.path.join(z_path, "blah")
 
227
  alpha_path = os.path.join(blah_path, "E", "alpha")
 
228
  beta_path  = os.path.join(blah_path, "E", "beta")
 
229
 
 
230
  if (not os.path.exists(exdir_G_path)):
 
231
    raise svntest.Failure("Probing for " + exdir_G_path + " failed.")
 
232
  if (not os.path.exists(exdir_G_pi_path)):
 
233
    raise svntest.Failure("Probing for " + exdir_G_pi_path + " failed.")
 
234
  if (not os.path.exists(exdir_H_path)):
 
235
    raise svntest.Failure("Probing for " + exdir_H_path + " failed.")
 
236
  if (not os.path.exists(exdir_H_omega_path)):
 
237
    raise svntest.Failure("Probing for " + exdir_H_omega_path + " failed.")
 
238
  if (not os.path.exists(x_path)):
 
239
    raise svntest.Failure("Probing for " + x_path + " failed.")
 
240
  if (not os.path.exists(y_path)):
 
241
    raise svntest.Failure("Probing for " + y_path + " failed.")
 
242
  if (not os.path.exists(z_path)):
 
243
    raise svntest.Failure("Probing for " + z_path + " failed.")
 
244
  if (not os.path.exists(z_path)):
 
245
    raise svntest.Failure("Probing for " + z_path + " failed.")
 
246
  if (not os.path.exists(alpha_path)):
 
247
    raise svntest.Failure("Probing for " + alpha_path + " failed.")
 
248
  if (not os.path.exists(beta_path)):
 
249
    raise svntest.Failure("Probing for " + beta_path + " failed.")
 
250
 
 
251
  # Pick a file at random, make sure it has the expected contents.
 
252
  fp = open(exdir_H_omega_path, 'r')
 
253
  lines = fp.readlines()
 
254
  if not ((len(lines) == 1) and (lines[0] == "This is the file 'omega'.")):
 
255
    raise svntest.Failure("Unexpected contents for rev 1 of " +
 
256
                          exdir_H_omega_path)
 
257
 
 
258
#----------------------------------------------------------------------
 
259
 
 
260
def update_receive_new_external(sbox):
 
261
  "update to receive a new external module"
 
262
 
 
263
  externals_test_setup(sbox)
 
264
  wc_dir         = sbox.wc_dir
 
265
  
 
266
  other_wc_dir   = sbox.add_wc_path('other')
 
267
  repo_dir       = sbox.repo_dir
 
268
  repo_url       = sbox.repo_url
 
269
  other_repo_url = repo_url + ".other"
 
270
 
 
271
  # Checkout two working copies.
 
272
  svntest.actions.run_and_verify_svn("", None, [],
 
273
                                     'checkout',
 
274
                                     '--username', svntest.main.wc_author,
 
275
                                     '--password', svntest.main.wc_passwd,
 
276
                                     repo_url, wc_dir)
 
277
 
 
278
  svntest.actions.run_and_verify_svn("", None, [],
 
279
                                     'checkout',
 
280
                                     '--username', svntest.main.wc_author,
 
281
                                     '--password', svntest.main.wc_passwd,
 
282
                                     repo_url, other_wc_dir)
 
283
 
 
284
  # Add one new external item to the property on A/D.  The new item is
 
285
  # "exdir_E", deliberately added in the middle not at the end.
 
286
  new_externals_desc = \
 
287
           "exdir_A           " + other_repo_url + "/A"     + \
 
288
           "\n"                                             + \
 
289
           "exdir_A/G         " + other_repo_url + "/A/D/G" + \
 
290
           "\n"                                             + \
 
291
           "exdir_E           " + other_repo_url + "/A/B/E" + \
 
292
           "\n"                                             + \
 
293
           "exdir_A/H   -r 1  " + other_repo_url + "/A/D/H" + \
 
294
           "\n"                                             + \
 
295
           "x/y/z/blah        " + other_repo_url + "/A/B/E" + \
 
296
           "\n"
 
297
 
 
298
  # Set and commit the property
 
299
  change_external(os.path.join(wc_dir, "A/D"), new_externals_desc)
 
300
 
 
301
  # Update the other working copy, see if we get the new item.
 
302
  svntest.actions.run_and_verify_svn("", None, [], 'up', other_wc_dir)
 
303
 
 
304
  exdir_E_path = os.path.join(other_wc_dir, "A", "D", "exdir_E")
 
305
  if (not os.path.exists(exdir_E_path)):
 
306
    raise svntest.Failure("Probing for " + exdir_E_path + " failed.")
 
307
 
 
308
#----------------------------------------------------------------------
 
309
 
 
310
def update_lose_external(sbox):
 
311
  "update to lose an external module"
 
312
 
 
313
  externals_test_setup(sbox)
 
314
  wc_dir         = sbox.wc_dir
 
315
  
 
316
  other_wc_dir   = sbox.add_wc_path('other')
 
317
  repo_dir       = sbox.repo_dir
 
318
  repo_url       = sbox.repo_url
 
319
  other_repo_url = repo_url + ".other"
 
320
 
 
321
  # Checkout two working copies.
 
322
  svntest.actions.run_and_verify_svn("", None, [],
 
323
                                     'checkout',
 
324
                                     '--username', svntest.main.wc_author,
 
325
                                     '--password', svntest.main.wc_passwd,
 
326
                                     repo_url, wc_dir)
 
327
 
 
328
  svntest.actions.run_and_verify_svn("", None, [],
 
329
                                     'checkout',
 
330
                                     '--username', svntest.main.wc_author,
 
331
                                     '--password', svntest.main.wc_passwd,
 
332
                                     repo_url, other_wc_dir)
 
333
 
 
334
  # Lose one new external item from A/D.  The lost item is
 
335
  # "exdir_A", chosen because there are two other externals underneath
 
336
  # it (G and H) which are not being removed.  We expect them to
 
337
  # remain -- in other words:
 
338
  #
 
339
  #      BEFORE                                AFTER
 
340
  #    ------------                          ------------
 
341
  #    A/D/exdir_A                           A/D/exdir_A
 
342
  #    A/D/exdir_A/.svn/...                    <GONE>
 
343
  #    A/D/exdir_A/mu                          <GONE>
 
344
  #    A/D/exdir_A/B/...                       <GONE>
 
345
  #    A/D/exdir_A/C/...                       <GONE>
 
346
  #    A/D/exdir_A/D/...                       <GONE>
 
347
  #    A/D/exdir_A/G/...                     A/D/exdir_A/G/...
 
348
  #    A/D/exdir_A/H/...                     A/D/exdir_A/H/...
 
349
 
 
350
  new_externals_desc = \
 
351
           "exdir_A/G         " + other_repo_url + "/A/D/G" + \
 
352
           "\n"                                             + \
 
353
           "exdir_A/H   -r 1  " + other_repo_url + "/A/D/H" + \
 
354
           "\n"                                             + \
 
355
           "x/y/z/blah        " + other_repo_url + "/A/B/E" + \
 
356
           "\n"
 
357
 
 
358
  # Set and commit the property
 
359
  change_external(os.path.join(wc_dir, "A/D"), new_externals_desc)
 
360
 
 
361
  # Update other working copy, see if lose & preserve things appropriately
 
362
  svntest.actions.run_and_verify_svn("", None, [], 'up', other_wc_dir)
 
363
 
 
364
  exdir_A_path = os.path.join(other_wc_dir, "A", "D", "exdir_A")
 
365
  if (not os.path.exists(exdir_A_path)):
 
366
    raise svntest.Failure("Probing for " + exdir_A_path + " failed.")
 
367
 
 
368
  mu_path = os.path.join(other_wc_dir, "A", "D", "exdir_A", "mu")
 
369
  if (os.path.exists(mu_path)):
 
370
    raise svntest.Failure(mu_path + " unexpectedly still exists.")
 
371
 
 
372
  B_path = os.path.join(other_wc_dir, "A", "D", "exdir_A", "B")
 
373
  if (os.path.exists(B_path)):
 
374
    raise svntest.Failure(B_path + " unexpectedly still exists.")
 
375
 
 
376
  C_path = os.path.join(other_wc_dir, "A", "D", "exdir_A", "C")
 
377
  if (os.path.exists(C_path)):
 
378
    raise svntest.Failure(C_path + " unexpectedly still exists.")
 
379
 
 
380
  D_path = os.path.join(other_wc_dir, "A", "D", "exdir_A", "D")
 
381
  if (os.path.exists(D_path)):
 
382
    raise svntest.Failure(D_path + " unexpectedly still exists.")
 
383
 
 
384
  G_path = os.path.join(other_wc_dir, "A", "D", "exdir_A", "G")
 
385
  if (not os.path.exists(G_path)):
 
386
    raise svntest.Failure("Probing for " + G_path + " failed.")
 
387
 
 
388
  H_path = os.path.join(other_wc_dir, "A", "D", "exdir_A", "H")
 
389
  if (not os.path.exists(H_path)):
 
390
    raise svntest.Failure("Probing for " + H_path + " failed.")
 
391
 
 
392
#----------------------------------------------------------------------
 
393
 
 
394
def update_change_pristine_external(sbox):
 
395
  "update change to an unmodified external module"
 
396
 
 
397
  externals_test_setup(sbox)
 
398
  wc_dir         = sbox.wc_dir
 
399
  
 
400
  other_wc_dir   = sbox.add_wc_path('other')
 
401
  repo_dir       = sbox.repo_dir
 
402
  repo_url       = sbox.repo_url
 
403
  other_repo_url = repo_url + ".other"
 
404
 
 
405
  # Checkout two working copies.
 
406
  svntest.actions.run_and_verify_svn("", None, [],
 
407
                                     'checkout',
 
408
                                     '--username', svntest.main.wc_author,
 
409
                                     '--password', svntest.main.wc_passwd,
 
410
                                     repo_url, wc_dir)
 
411
 
 
412
  svntest.actions.run_and_verify_svn("", None, [],
 
413
                                     'checkout',
 
414
                                     '--username', svntest.main.wc_author,
 
415
                                     '--password', svntest.main.wc_passwd,
 
416
                                     repo_url, other_wc_dir)
 
417
 
 
418
  # Change the "x/y/z/blah" external on A/D to point to a different
 
419
  # URL.  Since no changes were made to the old checked-out external,
 
420
  # we should get a clean replace.
 
421
  new_externals_desc = \
 
422
           "exdir_A           " + other_repo_url + "/A"     + \
 
423
           "\n"                                             + \
 
424
           "exdir_A/G         " + other_repo_url + "/A/D/G" + \
 
425
           "\n"                                             + \
 
426
           "exdir_A/H   -r 1  " + other_repo_url + "/A/D/H" + \
 
427
           "\n"                                             + \
 
428
           "x/y/z/blah        " + other_repo_url + "/A/B/F" + \
 
429
           "\n"
 
430
 
 
431
  # Set and commit the property
 
432
  change_external(os.path.join(wc_dir, "A/D"), new_externals_desc)
 
433
 
 
434
  # Update other working copy, see if get the right change.
 
435
  svntest.actions.run_and_verify_svn("", None, [], 'up', other_wc_dir)
 
436
 
 
437
  xyzb_path = os.path.join(other_wc_dir, "x", "y", "z", "blah")
 
438
 
 
439
  alpha_path = os.path.join(xyzb_path, "alpha")
 
440
  if (os.path.exists(alpha_path)):
 
441
    raise svntest.Failure(alpha_path + " unexpectedly still exists.")
 
442
 
 
443
  beta_path = os.path.join(xyzb_path, "beta")
 
444
  if (os.path.exists(beta_path)):
 
445
    raise svntest.Failure(beta_path + " unexpectedly still exists.")
 
446
 
 
447
def update_change_modified_external(sbox):
 
448
  "update changes to a modified external module"
 
449
 
 
450
  externals_test_setup(sbox)
 
451
  wc_dir         = sbox.wc_dir
 
452
 
 
453
  other_wc_dir   = sbox.add_wc_path('other')
 
454
  repo_dir       = sbox.repo_dir
 
455
  repo_url       = sbox.repo_url
 
456
  other_repo_url = repo_url + ".other"
 
457
 
 
458
  # Checkout two working copies.
 
459
  svntest.actions.run_and_verify_svn("", None, [],
 
460
                                     'checkout',
 
461
                                     '--username', svntest.main.wc_author,
 
462
                                     '--password', svntest.main.wc_passwd,
 
463
                                     repo_url, wc_dir)
 
464
 
 
465
  svntest.actions.run_and_verify_svn("", None, [],
 
466
                                     'checkout',
 
467
                                     '--username', svntest.main.wc_author,
 
468
                                     '--password', svntest.main.wc_passwd,
 
469
                                     repo_url, other_wc_dir)
 
470
 
 
471
  # Make a couple of mods in the "x/y/z/blah/" external.
 
472
  alpha_path = os.path.join(other_wc_dir, "A", "D",
 
473
                            "x", "y", "z", "blah", "alpha")
 
474
  svntest.main.file_append(alpha_path, "\nSome new text in alpha.")
 
475
  new_file = os.path.join(other_wc_dir, "A", "D",
 
476
                          "x", "y", "z", "blah", "fish.txt")
 
477
  svntest.main.file_append(new_file, "This is an unversioned file.")
 
478
 
 
479
  # Change the "x/y/z/blah" external on A/D to point to a different
 
480
  # URL.  There are some local mods under the old checked-out external,
 
481
  # so the old dir should be saved under a new name.
 
482
  new_externals_desc = \
 
483
           "exdir_A           " + other_repo_url + "/A"     + \
 
484
           "\n"                                             + \
 
485
           "exdir_A/G         " + other_repo_url + "/A/D/G" + \
 
486
           "\n"                                             + \
 
487
           "exdir_A/H   -r 1  " + other_repo_url + "/A/D/H" + \
 
488
           "\n"                                             + \
 
489
           "x/y/z/blah        " + other_repo_url + "/A/B/F" + \
 
490
           "\n"
 
491
 
 
492
  # Set and commit the property
 
493
  change_external(os.path.join(wc_dir, "A/D"), new_externals_desc)
 
494
 
 
495
  # Update other working copy, see if get the right change.
 
496
  svntest.actions.run_and_verify_svn("", None, [], 'up', other_wc_dir)
 
497
 
 
498
  xyzb_path = os.path.join(other_wc_dir, "x", "y", "z", "blah")
 
499
 
 
500
  alpha_path = os.path.join(xyzb_path, "alpha")
 
501
  if (os.path.exists(alpha_path)):
 
502
    raise svntest.Failure(alpha_path + " unexpectedly still exists.")
 
503
 
 
504
  beta_path = os.path.join(xyzb_path, "beta")
 
505
  if (os.path.exists(beta_path)):
 
506
    raise svntest.Failure(beta_path + " unexpectedly still exists.")
 
507
 
 
508
def update_receive_change_under_external(sbox):
 
509
  "update changes under an external module"
 
510
 
 
511
  externals_test_setup(sbox)
 
512
  wc_dir         = sbox.wc_dir
 
513
  
 
514
  other_wc_dir   = sbox.add_wc_path('other')
 
515
  repo_dir       = sbox.repo_dir
 
516
  repo_url       = sbox.repo_url
 
517
  other_repo_url = repo_url + ".other"
 
518
 
 
519
  # Checkout two working copies.
 
520
  svntest.actions.run_and_verify_svn("", None, [],
 
521
                                     'checkout',
 
522
                                     '--username', svntest.main.wc_author,
 
523
                                     '--password', svntest.main.wc_passwd,
 
524
                                     repo_url, wc_dir)
 
525
 
 
526
  svntest.actions.run_and_verify_svn("", None, [],
 
527
                                     'checkout',
 
528
                                     '--username', svntest.main.wc_author,
 
529
                                     '--password', svntest.main.wc_passwd,
 
530
                                     other_repo_url, other_wc_dir)
 
531
 
 
532
  # Commit some modifications from the other_wc.
 
533
  other_gamma_path = os.path.join(other_wc_dir, 'A', 'D', 'gamma')
 
534
  svntest.main.file_append(other_gamma_path, "\nNew text in other gamma.")
 
535
 
 
536
  expected_output = svntest.wc.State(other_wc_dir, {
 
537
    'A/D/gamma' : Item(verb='Sending'),
 
538
    })
 
539
  expected_status = svntest.actions.get_virginal_state(other_wc_dir, 5)
 
540
  expected_status.tweak('A/D/gamma', wc_rev=6)
 
541
  svntest.actions.run_and_verify_commit(other_wc_dir,
 
542
                                        expected_output,
 
543
                                        expected_status,
 
544
                                        None, None, None, None, None,
 
545
                                        other_wc_dir)
 
546
  
 
547
  # Now update the regular wc to see if we get the change.  Note that
 
548
  # none of the module *properties* in this wc have been changed; only
 
549
  # the source repository of the modules has received a change, and
 
550
  # we're verifying that an update here pulls that change.
 
551
 
 
552
  # The output's going to be all screwy because of the module
 
553
  # notifications, so don't bother parsing it, just run update
 
554
  # directly.
 
555
  svntest.actions.run_and_verify_svn("", None, [], 'up', wc_dir)
 
556
 
 
557
  external_gamma_path = os.path.join(wc_dir, 'A', 'D', 'exdir_A', 'D', 'gamma')
 
558
  fp = open(external_gamma_path, 'r')
 
559
  lines = fp.readlines()
 
560
  if not ((len(lines) == 2)
 
561
          and (lines[0] == "This is the file 'gamma'.\n")
 
562
          and (lines[1] == "New text in other gamma.")):
 
563
    raise svntest.Failure("Unexpected contents for externally modified " +
 
564
                          external_gamma_path)
 
565
  fp.close()
 
566
 
 
567
  # Commit more modifications
 
568
  other_rho_path = os.path.join(other_wc_dir, 'A', 'D', 'G', 'rho')
 
569
  svntest.main.file_append(other_rho_path, "\nNew text in other rho.")
 
570
 
 
571
  expected_output = svntest.wc.State(other_wc_dir, {
 
572
    'A/D/G/rho' : Item(verb='Sending'),
 
573
    })
 
574
  expected_status = svntest.actions.get_virginal_state(other_wc_dir, 5)
 
575
  expected_status.tweak('A/D/gamma', wc_rev=6)
 
576
  expected_status.tweak('A/D/G/rho', wc_rev=7)
 
577
  svntest.actions.run_and_verify_commit(other_wc_dir,
 
578
                                        expected_output,
 
579
                                        expected_status,
 
580
                                        None, None, None, None, None,
 
581
                                        other_wc_dir)
 
582
 
 
583
  svntest.actions.run_and_verify_svn("", None, [],
 
584
                                     'up', os.path.join(wc_dir, "A", "C"))
 
585
 
 
586
  external_rho_path = os.path.join(wc_dir, 'A', 'C', 'exdir_G', 'rho')
 
587
  fp = open(external_rho_path, 'r')
 
588
  lines = fp.readlines()
 
589
  if not ((len(lines) == 2)
 
590
          and (lines[0] == "This is the file 'rho'.\n")
 
591
          and (lines[1] == "New text in other rho.")):
 
592
    raise svntest.Failure("Unexpected contents for externally modified " +
 
593
                          external_rho_path)
 
594
  fp.close()
 
595
 
 
596
#----------------------------------------------------------------------
 
597
 
 
598
def modify_and_update_receive_new_external(sbox):
 
599
  "commit and update additional externals"
 
600
 
 
601
  externals_test_setup(sbox)
 
602
  wc_dir         = sbox.wc_dir
 
603
 
 
604
  repo_dir       = sbox.repo_dir
 
605
  repo_url       = sbox.repo_url
 
606
  other_repo_url = repo_url + ".other"
 
607
 
 
608
  # Checkout a working copy
 
609
  svntest.actions.run_and_verify_svn("", None, [],
 
610
                                     'checkout',
 
611
                                     '--username', svntest.main.wc_author,
 
612
                                     '--password', svntest.main.wc_passwd,
 
613
                                     repo_url, wc_dir)
 
614
 
 
615
  # Add one more external item
 
616
  B_path = os.path.join(wc_dir, "A/B")
 
617
  externals_desc = \
 
618
          "exdir_G       " + other_repo_url + "/A/D/G" + "\n" + \
 
619
          "exdir_H  -r 1 " + other_repo_url + "/A/D/H" + "\n" + \
 
620
          "exdir_Z       " + other_repo_url + "/A/D/H" + "\n"
 
621
 
 
622
  tmp_f = os.tempnam()
 
623
  svntest.main.file_append(tmp_f, externals_desc)
 
624
  svntest.actions.run_and_verify_svn("", None, [],
 
625
                                     'pset', '-F', tmp_f,
 
626
                                     'svn:externals', B_path)
 
627
  os.remove(tmp_f)
 
628
 
 
629
  # Now cd into A/B and try updating
 
630
  was_cwd = os.getcwd()
 
631
  os.chdir(B_path)
 
632
  try:
 
633
    # Once upon a time there was a core-dump here
 
634
    
 
635
    svntest.actions.run_and_verify_svn("update failed",
 
636
                                       SVNAnyOutput, [], 'up' )
 
637
 
 
638
  finally:
 
639
    os.chdir(was_cwd)
 
640
 
 
641
  exdir_Z_path = os.path.join(B_path, "exdir_Z")
 
642
  if not os.path.exists(exdir_Z_path):
 
643
    raise svntest.Failure("Probing for " + exdir_Z_path + " failed.")
 
644
 
 
645
#----------------------------------------------------------------------
 
646
 
 
647
def disallow_dot_or_dotdot_directory_reference(sbox):
 
648
  "error if external target dir involves '.' or '..'"
 
649
  sbox.build()
 
650
  wc_dir         = sbox.wc_dir
 
651
  repo_url       = sbox.repo_url
 
652
 
 
653
  # Try to set illegal externals in the original WC.
 
654
  def set_externals_for_path_expect_error(path, val, dir):
 
655
    tmp_f = os.tempnam(dir, 'tmp')
 
656
    svntest.main.file_append(tmp_f, val)
 
657
    svntest.actions.run_and_verify_svn("", None, SVNAnyOutput,
 
658
                                       'pset', '-F', tmp_f,
 
659
                                       'svn:externals', path)
 
660
    os.remove(tmp_f)
 
661
 
 
662
  B_path = os.path.join(wc_dir, 'A', 'B')
 
663
  G_path = os.path.join(wc_dir, 'A', 'D', 'G')
 
664
  H_path = os.path.join(wc_dir, 'A', 'D', 'H')
 
665
  C_path = os.path.join(wc_dir, 'A', 'C')
 
666
  F_path = os.path.join(wc_dir, 'A', 'C', 'F')
 
667
  externals_value_1 = "../foo"         + " " + repo_url + "/A/B/E" + "\n"
 
668
  externals_value_2 = "foo/bar/../baz" + " " + repo_url + "/A/B/E" + "\n"
 
669
  externals_value_3 = "foo/.."         + " " + repo_url + "/A/B/E" + "\n"
 
670
  externals_value_4 = "."              + " " + repo_url + "/A/B/E" + "\n"
 
671
  externals_value_5 = "./"             + " " + repo_url + "/A/B/E" + "\n"
 
672
  externals_value_6 = ".."             + " " + repo_url + "/A/B/E" + "\n"
 
673
  externals_value_7 = "././/.///."     + " " + repo_url + "/A/B/E" + "\n"
 
674
  externals_value_8 = "/foo"           + " " + repo_url + "/A/B/E" + "\n"
 
675
 
 
676
 
 
677
  set_externals_for_path_expect_error(B_path, externals_value_1, wc_dir)
 
678
  set_externals_for_path_expect_error(G_path, externals_value_2, wc_dir)
 
679
  set_externals_for_path_expect_error(H_path, externals_value_3, wc_dir)
 
680
  set_externals_for_path_expect_error(C_path, externals_value_4, wc_dir)
 
681
  set_externals_for_path_expect_error(F_path, externals_value_5, wc_dir)
 
682
  set_externals_for_path_expect_error(B_path, externals_value_6, wc_dir)
 
683
  set_externals_for_path_expect_error(G_path, externals_value_7, wc_dir)
 
684
  set_externals_for_path_expect_error(H_path, externals_value_8, wc_dir)
 
685
 
 
686
 
 
687
#----------------------------------------------------------------------
 
688
 
 
689
def export_with_externals(sbox):
 
690
  "test exports with externals"
 
691
 
 
692
  externals_test_setup(sbox)
 
693
 
 
694
  wc_dir         = sbox.wc_dir
 
695
  repo_dir       = sbox.repo_dir
 
696
  repo_url       = sbox.repo_url
 
697
 
 
698
  # Create a working copy.
 
699
  svntest.actions.run_and_verify_svn("", None, [],
 
700
                                     'export',
 
701
                                     '--username', svntest.main.wc_author,
 
702
                                     '--password', svntest.main.wc_passwd,
 
703
                                     repo_url, wc_dir)
 
704
 
 
705
  # Probe the working copy a bit, see if it's as expected.
 
706
  exdir_G_path    = os.path.join(wc_dir, "A", "C", "exdir_G")
 
707
  exdir_G_pi_path = os.path.join(exdir_G_path, "pi")
 
708
  exdir_H_path       = os.path.join(wc_dir, "A", "C", "exdir_H")
 
709
  exdir_H_omega_path = os.path.join(exdir_H_path, "omega")
 
710
  x_path     = os.path.join(wc_dir, "A", "D", "x")
 
711
  y_path     = os.path.join(x_path, "y")
 
712
  z_path     = os.path.join(y_path, "z")
 
713
  blah_path  = os.path.join(z_path, "blah")
 
714
  alpha_path = os.path.join(blah_path, "E", "alpha")
 
715
  beta_path  = os.path.join(blah_path, "E", "beta")
 
716
 
 
717
  if (not os.path.exists(exdir_G_path)):
 
718
    raise svntest.Failure("Probing for " + exdir_G_path + " failed.")
 
719
  if (not os.path.exists(exdir_G_pi_path)):
 
720
    raise svntest.Failure("Probing for " + exdir_G_pi_path + " failed.")
 
721
  if (not os.path.exists(exdir_H_path)):
 
722
    raise svntest.Failure("Probing for " + exdir_H_path + " failed.")
 
723
  if (not os.path.exists(exdir_H_omega_path)):
 
724
    raise svntest.Failure("Probing for " + exdir_H_omega_path + " failed.")
 
725
  if (not os.path.exists(x_path)):
 
726
    raise svntest.Failure("Probing for " + x_path + " failed.")
 
727
  if (not os.path.exists(y_path)):
 
728
    raise svntest.Failure("Probing for " + y_path + " failed.")
 
729
  if (not os.path.exists(z_path)):
 
730
    raise svntest.Failure("Probing for " + z_path + " failed.")
 
731
  if (not os.path.exists(z_path)):
 
732
    raise svntest.Failure("Probing for " + z_path + " failed.")
 
733
  if (not os.path.exists(alpha_path)):
 
734
    raise svntest.Failure("Probing for " + alpha_path + " failed.")
 
735
  if (not os.path.exists(beta_path)):
 
736
    raise svntest.Failure("Probing for " + beta_path + " failed.")
 
737
 
 
738
  # Pick some files, make sure their contents are as expected.
 
739
  fp = open(exdir_G_pi_path, 'r')
 
740
  lines = fp.readlines()
 
741
  if not ((len(lines) == 2) \
 
742
          and (lines[0] == "This is the file 'pi'.\n") \
 
743
          and (lines[1] == "Added to pi in revision 3.\n")):
 
744
    raise svntest.Failure("Unexpected contents for rev 1 of " +
 
745
                          exdir_G_pi_path)
 
746
  fp = open(exdir_H_omega_path, 'r')
 
747
  lines = fp.readlines()
 
748
  if not ((len(lines) == 1) and (lines[0] == "This is the file 'omega'.")):
 
749
    raise svntest.Failure("Unexpected contents for rev 1 of " +
 
750
                          exdir_H_omega_path)
 
751
 
 
752
 
 
753
 
 
754
########################################################################
 
755
# Run the tests
 
756
 
 
757
 
 
758
# list all tests here, starting with None:
 
759
test_list = [ None,
 
760
              checkout_with_externals,
 
761
              update_receive_new_external,
 
762
              update_lose_external,
 
763
              update_change_pristine_external,
 
764
              update_change_modified_external,
 
765
              update_receive_change_under_external,
 
766
              modify_and_update_receive_new_external,
 
767
              disallow_dot_or_dotdot_directory_reference,
 
768
              export_with_externals,
 
769
             ]
 
770
 
 
771
if __name__ == '__main__':
 
772
  warnings.filterwarnings('ignore', 'tempnam', RuntimeWarning)
 
773
  svntest.main.run_tests(test_list)
 
774
  # NOTREACHED
 
775
 
 
776
 
 
777
### End of file.