comparison tests/test_push_command.py @ 304:ce676eff002b

First merge, totally untested.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 01 May 2009 10:28:59 +0200
parents 3848a7f9b983
children 75f082b5897e
comparison
equal deleted inserted replaced
303:f423a8780832 304:ce676eff002b
6 from mercurial import context 6 from mercurial import context
7 from mercurial import hg 7 from mercurial import hg
8 from mercurial import node 8 from mercurial import node
9 from mercurial import ui 9 from mercurial import ui
10 from mercurial import revlog 10 from mercurial import revlog
11 11 from mercurial import util as hgutil
12 import fetch_command 12
13 import push_cmd 13 import wrappers
14 import test_util 14 import test_util
15 import time 15 import time
16 16
17 17
18 class PushOverSvnserveTests(test_util.TestBase): 18 class PushOverSvnserveTests(test_util.TestBase):
36 assert False, ('You appear to be running your own svnserve!' 36 assert False, ('You appear to be running your own svnserve!'
37 ' You can probably ignore this test failure.') 37 ' You can probably ignore this test failure.')
38 args = ['svnserve', '-d', '--foreground', '-r', self.repo_path] 38 args = ['svnserve', '-d', '--foreground', '-r', self.repo_path]
39 self.svnserve_pid = subprocess.Popen(args).pid 39 self.svnserve_pid = subprocess.Popen(args).pid
40 time.sleep(2) 40 time.sleep(2)
41 fetch_command.fetch_revisions(ui.ui(), 41 wrappers.clone(None, ui.ui(), source='svn://localhost/',
42 svn_url='svn://localhost/', 42 dest=self.wc_path, noupdate=True)
43 hg_repo_path=self.wc_path)
44 43
45 def tearDown(self): 44 def tearDown(self):
46 os.system('kill -9 %d' % self.svnserve_pid) 45 os.system('kill -9 %d' % self.svnserve_pid)
47 test_util.TestBase.tearDown(self) 46 test_util.TestBase.tearDown(self)
48 47
68 {'branch': 'default',}) 67 {'branch': 'default',})
69 new_hash = repo.commitctx(ctx) 68 new_hash = repo.commitctx(ctx)
70 if not commit: 69 if not commit:
71 return # some tests use this test as an extended setup. 70 return # some tests use this test as an extended setup.
72 hg.update(repo, repo['tip'].node()) 71 hg.update(repo, repo['tip'].node())
73 push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo, 72 oldauthor = repo['tip'].user()
74 hg_repo_path=self.wc_path, 73 wrappers.push(None, ui.ui(), repo=self.repo)
75 svn_url='svn://localhost/') 74 tip = self.repo['tip']
76 tip = self.repo['tip'] 75 self.assertNotEqual(oldauthor, tip.user())
77 self.assertNotEqual(tip.node(), old_tip) 76 self.assertNotEqual(tip.node(), old_tip)
78 self.assertEqual(tip.parents()[0].node(), expected_parent) 77 self.assertEqual(tip.parents()[0].node(), expected_parent)
79 self.assertEqual(tip['adding_file'].data(), 'foo') 78 self.assertEqual(tip['adding_file'].data(), 'foo')
80 self.assertEqual(tip.branch(), 'default') 79 self.assertEqual(tip.branch(), 'default')
81 80
84 def setUp(self): 83 def setUp(self):
85 test_util.TestBase.setUp(self) 84 test_util.TestBase.setUp(self)
86 test_util.load_fixture_and_fetch('simple_branch.svndump', 85 test_util.load_fixture_and_fetch('simple_branch.svndump',
87 self.repo_path, 86 self.repo_path,
88 self.wc_path) 87 self.wc_path)
88
89 def test_cant_push_empty_ctx(self):
90 repo = self.repo
91 def file_callback(repo, memctx, path):
92 if path == 'adding_file':
93 return context.memfilectx(path=path,
94 data='foo',
95 islink=False,
96 isexec=False,
97 copied=False)
98 raise IOError()
99 ctx = context.memctx(repo,
100 (repo['default'].node(), node.nullid),
101 'automated test',
102 [],
103 file_callback,
104 'an_author',
105 '2008-10-07 20:59:48 -0500',
106 {'branch': 'default',})
107 new_hash = repo.commitctx(ctx)
108 hg.update(repo, repo['tip'].node())
109 old_tip = repo['tip'].node()
110 self.pushrevisions()
111 tip = self.repo['tip']
112 self.assertEqual(tip.node(), old_tip)
113
89 114
90 def test_push_to_default(self, commit=True): 115 def test_push_to_default(self, commit=True):
91 repo = self.repo 116 repo = self.repo
92 old_tip = repo['tip'].node() 117 old_tip = repo['tip'].node()
93 expected_parent = repo['default'].node() 118 expected_parent = repo['default'].node()
145 '2008-12-21 16:32:00 -0500', 170 '2008-12-21 16:32:00 -0500',
146 {'branch': 'localbranch', }) 171 {'branch': 'localbranch', })
147 newhash = self.repo.commitctx(ctx) 172 newhash = self.repo.commitctx(ctx)
148 repo = self.repo 173 repo = self.repo
149 hg.update(repo, newhash) 174 hg.update(repo, newhash)
150 push_cmd.push_revisions_to_subversion(ui.ui(), 175 wrappers.push(None, ui.ui(), repo=repo)
151 repo=repo,
152 svn_url=test_util.fileurl(self.repo_path),
153 hg_repo_path=self.wc_path)
154 self.assertEqual(self.repo['tip'].parents()[0].parents()[0].node(), oldtiphash) 176 self.assertEqual(self.repo['tip'].parents()[0].parents()[0].node(), oldtiphash)
155 self.assertEqual(self.repo['tip'].files(), ['delta', ]) 177 self.assertEqual(self.repo['tip'].files(), ['delta', ])
156 self.assertEqual(self.repo['tip'].manifest().keys(), 178 self.assertEqual(self.repo['tip'].manifest().keys(),
157 ['alpha', 'beta', 'gamma', 'delta']) 179 ['alpha', 'beta', 'gamma', 'delta'])
158 180
261 file_callback, 283 file_callback,
262 'author', 284 'author',
263 '2008-10-29 21:26:00 -0500', 285 '2008-10-29 21:26:00 -0500',
264 {'branch': 'default', }) 286 {'branch': 'default', })
265 new_hash = repo.commitctx(ctx) 287 new_hash = repo.commitctx(ctx)
266 hg.update(repo, repo['tip'].node()) 288 hg.clean(repo, repo['tip'].node())
267 self.pushrevisions() 289 self.pushrevisions()
268 tip = self.repo['tip'] 290 tip = self.repo['tip']
269 self.assertNotEqual(tip.node(), new_hash) 291 self.assertNotEqual(tip.node(), new_hash)
270 self.assert_('@' in tip.user()) 292 self.assert_('@' in self.repo['tip'].user())
271 self.assertEqual(tip['gamma'].flags(), 'x') 293 self.assertEqual(tip['gamma'].flags(), 'x')
272 self.assertEqual(tip['gamma'].data(), 'foo') 294 self.assertEqual(tip['gamma'].data(), 'foo')
273 self.assertEqual([x for x in tip.manifest().keys() if 'x' not in 295 self.assertEqual([x for x in tip.manifest().keys() if 'x' not in
274 tip[x].flags()], ['alpha', 'beta', 'adding_file', ]) 296 tip[x].flags()], ['alpha', 'beta', 'adding_file', ])
275 297
380 tip = self.repo['tip'] 402 tip = self.repo['tip']
381 self.assertNotEqual(tip.node(), new_hash) 403 self.assertNotEqual(tip.node(), new_hash)
382 self.assertEqual(tip['alpha'].data(), 'bar') 404 self.assertEqual(tip['alpha'].data(), 'bar')
383 self.assertEqual(tip.parents()[0]['alpha'].flags(), expected_flags) 405 self.assertEqual(tip.parents()[0]['alpha'].flags(), expected_flags)
384 self.assertEqual(tip['alpha'].flags(), '') 406 self.assertEqual(tip['alpha'].flags(), '')
407
408 def test_push_outdated_base_text(self):
409 self.test_push_two_revs()
410 changes = [('adding_file', 'adding_file', 'different_content', ),
411 ]
412 self.commitchanges(changes, parent='tip')
413 self.pushrevisions()
414 changes = [('adding_file', 'adding_file',
415 'even_more different_content', ),
416 ]
417 self.commitchanges(changes, parent=3)
418 try:
419 self.pushrevisions()
420 assert False, 'This should have aborted!'
421 except hgutil.Abort, e:
422 self.assertEqual(e.args[0],
423 'Base text was out of date, maybe rebase?')
385 424
386 425
387 def suite(): 426 def suite():
388 test_classes = [PushTests, PushOverSvnserveTests] 427 test_classes = [PushTests, PushOverSvnserveTests]
389 tests = [] 428 tests = []