3 # import_tests.py: import tests
5 # Subversion is a tool for revision control.
6 # See http://subversion.tigris.org for more information.
8 # ====================================================================
9 # Copyright (c) 2000-2007 CollabNet. All rights reserved.
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.
17 ######################################################################
24 from svntest
import wc
27 Skip
= svntest
.testcase
.Skip
28 SkipUnless
= svntest
.testcase
.SkipUnless
29 XFail
= svntest
.testcase
.XFail
32 ######################################################################
35 # Each test must return on success or raise on failure.
37 #----------------------------------------------------------------------
38 # this test should be SKIPped on systems without the executable bit
39 def import_executable(sbox
):
40 "import of executable files"
45 # create a new directory with files of various permissions
46 xt_path
= os
.path
.join(wc_dir
, "XT")
48 all_path
= os
.path
.join(wc_dir
, "XT/all_exe")
49 none_path
= os
.path
.join(wc_dir
, "XT/none_exe")
50 user_path
= os
.path
.join(wc_dir
, "XT/user_exe")
51 group_path
= os
.path
.join(wc_dir
, "XT/group_exe")
52 other_path
= os
.path
.join(wc_dir
, "XT/other_exe")
54 for path
in [all_path
, none_path
, user_path
, group_path
, other_path
]:
55 svntest
.main
.file_append(path
, "some text")
58 os
.chmod(all_path
, 0777)
59 os
.chmod(none_path
, 0666)
60 os
.chmod(user_path
, 0766)
61 os
.chmod(group_path
, 0676)
62 os
.chmod(other_path
, 0667)
64 # import new files into repository
66 exit_code
, output
, errput
= svntest
.actions
.run_and_verify_svn(
67 None, None, [], 'import',
68 '-m', 'Log message for new import', xt_path
, url
)
70 lastline
= output
.pop().strip()
71 cm
= re
.compile ("(Committed|Imported) revision [0-9]+.")
72 match
= cm
.search (lastline
)
74 ### we should raise a less generic error here. which?
77 # remove (uncontrolled) local files
78 svntest
.main
.safe_rmtree(xt_path
)
80 # Create expected disk tree for the update (disregarding props)
81 expected_disk
= svntest
.main
.greek_state
.copy()
83 'all_exe' : Item('some text', props
={'svn:executable' : ''}),
84 'none_exe' : Item('some text'),
85 'user_exe' : Item('some text', props
={'svn:executable' : ''}),
86 'group_exe' : Item('some text'),
87 'other_exe' : Item('some text'),
90 # Create expected status tree for the update (disregarding props).
91 # Newly imported file should be at revision 2.
92 expected_status
= svntest
.actions
.get_virginal_state(wc_dir
, 2)
94 'all_exe' : Item(status
=' ', wc_rev
=2),
95 'none_exe' : Item(status
=' ', wc_rev
=2),
96 'user_exe' : Item(status
=' ', wc_rev
=2),
97 'group_exe' : Item(status
=' ', wc_rev
=2),
98 'other_exe' : Item(status
=' ', wc_rev
=2),
101 # Create expected output tree for the update.
102 expected_output
= svntest
.wc
.State(wc_dir
, {
103 'all_exe' : Item(status
='A '),
104 'none_exe' : Item(status
='A '),
105 'user_exe' : Item(status
='A '),
106 'group_exe' : Item(status
='A '),
107 'other_exe' : Item(status
='A '),
109 # do update and check three ways
110 svntest
.actions
.run_and_verify_update(wc_dir
,
117 #----------------------------------------------------------------------
118 def import_ignores(sbox
):
119 'do not import ignored files in imported dirs'
125 # where dir contains some items that match the ignore list and some
126 # do not would add all items, ignored or not.
128 # This has been fixed by testing each item with the new
129 # svn_wc_is_ignored function.
134 dir_path
= os
.path
.join(wc_dir
, 'dir')
135 foo_c_path
= os
.path
.join(dir_path
, 'foo.c')
136 foo_o_path
= os
.path
.join(dir_path
, 'foo.o')
138 os
.mkdir(dir_path
, 0755)
139 open(foo_c_path
, 'w')
140 open(foo_o_path
, 'w')
142 # import new dir into repository
143 url
= sbox
.repo_url
+ '/dir'
145 exit_code
, output
, errput
= svntest
.actions
.run_and_verify_svn(
146 None, None, [], 'import',
147 '-m', 'Log message for new import',
150 lastline
= output
.pop().strip()
151 cm
= re
.compile ("(Committed|Imported) revision [0-9]+.")
152 match
= cm
.search (lastline
)
154 ### we should raise a less generic error here. which?
155 raise svntest
.verify
.SVNUnexpectedOutput
157 # remove (uncontrolled) local dir
158 svntest
.main
.safe_rmtree(dir_path
)
160 # Create expected disk tree for the update (disregarding props)
161 expected_disk
= svntest
.main
.greek_state
.copy()
163 'dir/foo.c' : Item(''),
166 # Create expected status tree for the update (disregarding props).
167 # Newly imported file should be at revision 2.
168 expected_status
= svntest
.actions
.get_virginal_state(wc_dir
, 2)
169 expected_status
.add({
170 'dir' : Item(status
=' ', wc_rev
=2),
171 'dir/foo.c' : Item(status
=' ', wc_rev
=2),
174 # Create expected output tree for the update.
175 expected_output
= svntest
.wc
.State(wc_dir
, {
176 'dir' : Item(status
='A '),
177 'dir/foo.c' : Item(status
='A '),
180 # do update and check three ways
181 svntest
.actions
.run_and_verify_update(wc_dir
,
188 #----------------------------------------------------------------------
189 def import_no_ignores(sbox
):
190 'import ignored files in imported dirs'
192 # import ignored files using the "--no-ignore" option
197 dir_path
= os
.path
.join(wc_dir
, 'dir')
198 foo_c_path
= os
.path
.join(dir_path
, 'foo.c')
199 foo_o_path
= os
.path
.join(dir_path
, 'foo.o')
200 foo_lo_path
= os
.path
.join(dir_path
, 'foo.lo')
201 foo_rej_path
= os
.path
.join(dir_path
, 'foo.rej')
203 os
.mkdir(dir_path
, 0755)
204 open(foo_c_path
, 'w')
205 open(foo_o_path
, 'w')
206 open(foo_lo_path
, 'w')
207 open(foo_rej_path
, 'w')
209 # import new dir into repository
210 url
= sbox
.repo_url
+ '/dir'
212 exit_code
, output
, errput
= svntest
.actions
.run_and_verify_svn(
213 None, None, [], 'import',
214 '-m', 'Log message for new import', '--no-ignore',
217 lastline
= output
.pop().strip()
218 cm
= re
.compile ("(Committed|Imported) revision [0-9]+.")
219 match
= cm
.search (lastline
)
221 raise svntest
.Failure
223 # remove (uncontrolled) local dir
224 svntest
.main
.safe_rmtree(dir_path
)
226 # Create expected disk tree for the update (disregarding props)
227 expected_disk
= svntest
.main
.greek_state
.copy()
229 'dir/foo.c' : Item(''),
230 'dir/foo.o' : Item(''),
231 'dir/foo.lo' : Item(''),
232 'dir/foo.rej' : Item(''),
235 # Create expected status tree for the update (disregarding props).
236 # Newly imported file should be at revision 2.
237 expected_status
= svntest
.actions
.get_virginal_state(wc_dir
, 2)
238 expected_status
.add({
239 'dir' : Item(status
=' ', wc_rev
=2),
240 'dir/foo.c' : Item(status
=' ', wc_rev
=2),
241 'dir/foo.o' : Item(status
=' ', wc_rev
=2),
242 'dir/foo.lo' : Item(status
=' ', wc_rev
=2),
243 'dir/foo.rej' : Item(status
=' ', wc_rev
=2),
246 # Create expected output tree for the update.
247 expected_output
= svntest
.wc
.State(wc_dir
, {
248 'dir' : Item(status
='A '),
249 'dir/foo.c' : Item(status
='A '),
250 'dir/foo.o' : Item(status
='A '),
251 'dir/foo.lo' : Item(status
='A '),
252 'dir/foo.rej' : Item(status
='A '),
255 # do update and check three ways
256 svntest
.actions
.run_and_verify_update(wc_dir
,
262 #----------------------------------------------------------------------
263 def import_avoid_empty_revision(sbox
):
264 "avoid creating empty revisions with import"
269 # create a new directory
270 empty_dir
= os
.path
.join(wc_dir
, "empty_dir")
271 os
.makedirs(empty_dir
)
274 svntest
.actions
.run_and_verify_svn(None, None, [], 'import',
275 '-m', 'Log message for new import',
278 svntest
.main
.safe_rmtree(empty_dir
)
280 # Verify that an empty revision has not been created
281 svntest
.actions
.run_and_verify_svn(None, [ "At revision 1.\n"],
284 #----------------------------------------------------------------------
286 # test for issue 2433: "import" does not handle eol-style correctly
287 def import_eol_style(sbox
):
288 "import should honor the eol-style property"
293 # setup a custom config, we need autoprops
294 config_contents
= '''\
296 enable-auto-props = yes
299 *.dsp = svn:eol-style=CRLF
301 tmp_dir
= os
.path
.abspath(svntest
.main
.temp_dir
)
302 config_dir
= os
.path
.join(tmp_dir
, 'autoprops_config')
303 svntest
.main
.create_config_dir(config_dir
, config_contents
)
305 # create a new file and import it
306 file_name
= "test.dsp"
307 file_path
= os
.path
.join(wc_dir
, file_name
)
308 imp_dir_path
= os
.path
.join(wc_dir
, 'dir')
309 imp_file_path
= os
.path
.join(imp_dir_path
, file_name
)
311 os
.mkdir(imp_dir_path
, 0755)
312 svntest
.main
.file_write(imp_file_path
, "This is file test.dsp.\n")
314 svntest
.actions
.run_and_verify_svn(None, None, [], 'import',
315 '-m', 'Log message for new import',
318 '--config-dir', config_dir
)
320 svntest
.main
.run_svn(None, 'update', wc_dir
, '--config-dir', config_dir
)
322 # change part of the file
323 svntest
.main
.file_append(file_path
, "Extra line\n")
325 # get a diff of the file, if the eol style is handled correctly, we'll
326 # only see our added line here.
327 # Before the issue was fixed, we would have seen something like this:
329 # -This is file test.dsp.
330 # +This is file test.dsp.
333 # eol styl of test.dsp is CRLF, so diff will use that too. Make sure we
334 # define CRLF in a platform independent way.
340 "Index: svn-test-work/working_copies/import_tests-5/test.dsp\n",
341 "===================================================================\n",
342 "--- svn-test-work/working_copies/import_tests-5/test.dsp\t(revision 2)\n",
343 "+++ svn-test-work/working_copies/import_tests-5/test.dsp\t(working copy)\n",
345 " This is file test.dsp." + crlf
,
349 svntest
.actions
.run_and_verify_svn(None, expected_output
, [],
352 '--config-dir', config_dir
)
354 #----------------------------------------------------------------------
355 ########################################################################
359 # list all tests here, starting with None:
361 SkipUnless(import_executable
, svntest
.main
.is_posix_os
),
363 import_avoid_empty_revision
,
368 if __name__
== '__main__':
369 svntest
.main
.run_tests(test_list
)