Fix compiler warning due to missing function prototype.
[svn.git] / subversion / tests / cmdline / import_tests.py
blob77b1b81413e3d4a6866f05ce2dec8a4c930d0781
1 #!/usr/bin/env python
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 ######################################################################
19 # General modules
20 import re, os.path
22 # Our testing module
23 import svntest
24 from svntest import wc
26 # (abbreviation)
27 Skip = svntest.testcase.Skip
28 SkipUnless = svntest.testcase.SkipUnless
29 XFail = svntest.testcase.XFail
30 Item = wc.StateItem
32 ######################################################################
33 # Tests
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"
42 sbox.build()
43 wc_dir = sbox.wc_dir
45 # create a new directory with files of various permissions
46 xt_path = os.path.join(wc_dir, "XT")
47 os.makedirs(xt_path)
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")
57 # set executable bits
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
65 url = sbox.repo_url
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)
73 if not match:
74 ### we should raise a less generic error here. which?
75 raise svntest.Failure
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()
82 expected_disk.add({
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)
93 expected_status.add({
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,
111 expected_output,
112 expected_disk,
113 expected_status,
114 None, None, None,
115 None, None, 1)
117 #----------------------------------------------------------------------
118 def import_ignores(sbox):
119 'do not import ignored files in imported dirs'
121 # The bug was that
123 # $ svn import dir
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.
131 sbox.build()
132 wc_dir = sbox.wc_dir
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',
148 dir_path, url)
150 lastline = output.pop().strip()
151 cm = re.compile ("(Committed|Imported) revision [0-9]+.")
152 match = cm.search (lastline)
153 if not match:
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()
162 expected_disk.add({
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,
182 expected_output,
183 expected_disk,
184 expected_status,
185 None, None, None,
186 None, None, 1)
188 #----------------------------------------------------------------------
189 def import_no_ignores(sbox):
190 'import ignored files in imported dirs'
192 # import ignored files using the "--no-ignore" option
194 sbox.build()
195 wc_dir = sbox.wc_dir
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',
215 dir_path, url)
217 lastline = output.pop().strip()
218 cm = re.compile ("(Committed|Imported) revision [0-9]+.")
219 match = cm.search (lastline)
220 if not match:
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()
228 expected_disk.add({
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,
257 expected_output,
258 expected_disk,
259 expected_status,
260 None, None, None,
261 None, None, 1)
262 #----------------------------------------------------------------------
263 def import_avoid_empty_revision(sbox):
264 "avoid creating empty revisions with import"
266 sbox.build()
267 wc_dir = sbox.wc_dir
269 # create a new directory
270 empty_dir = os.path.join(wc_dir, "empty_dir")
271 os.makedirs(empty_dir)
273 url = sbox.repo_url
274 svntest.actions.run_and_verify_svn(None, None, [], 'import',
275 '-m', 'Log message for new import',
276 empty_dir, url)
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"],
282 [], "update",
283 empty_dir)
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"
290 sbox.build()
291 wc_dir = sbox.wc_dir
293 # setup a custom config, we need autoprops
294 config_contents = '''\
295 [miscellany]
296 enable-auto-props = yes
298 [auto-props]
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',
316 imp_dir_path,
317 sbox.repo_url,
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:
328 # @@ -1 +1,2 @@
329 # -This is file test.dsp.
330 # +This is file test.dsp.
331 # +Extra line
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.
335 if os.name == 'nt':
336 crlf = '\n'
337 else:
338 crlf = '\r\n'
339 expected_output = [
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",
344 "@@ -1 +1,2 @@\n",
345 " This is file test.dsp." + crlf,
346 "+Extra line" + crlf
349 svntest.actions.run_and_verify_svn(None, expected_output, [],
350 'diff',
351 file_path,
352 '--config-dir', config_dir)
354 #----------------------------------------------------------------------
355 ########################################################################
356 # Run the tests
359 # list all tests here, starting with None:
360 test_list = [ None,
361 SkipUnless(import_executable, svntest.main.is_posix_os),
362 import_ignores,
363 import_avoid_empty_revision,
364 import_no_ignores,
365 import_eol_style,
368 if __name__ == '__main__':
369 svntest.main.run_tests(test_list)
370 # NOTREACHED
373 ### End of file.