~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_push.py

  • Committer: John Arbash Meinel
  • Date: 2007-05-04 18:59:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070504185936-1mjdoqmtz74xe5mg
A C implementation of _fields_to_entry_0_parents drops the time from 400ms to 330ms for a 21k-entry tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Black-box tests for bzr push."""
19
19
 
20
20
import os
21
 
import re
22
21
 
23
22
from bzrlib import (
24
23
    errors,
29
28
from bzrlib.osutils import abspath
30
29
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
31
30
from bzrlib.tests.blackbox import ExternalBase
32
 
from bzrlib.transport import register_transport, unregister_transport
33
 
from bzrlib.transport.memory import MemoryServer, MemoryTransport
34
31
from bzrlib.uncommit import uncommit
35
32
from bzrlib.urlutils import local_path_from_url
36
33
from bzrlib.workingtree import WorkingTree
61
58
 
62
59
        # test push for failure without push location set
63
60
        os.chdir('branch_a')
64
 
        out = self.run_bzr('push', retcode=3)
 
61
        out = self.runbzr('push', retcode=3)
65
62
        self.assertEquals(out,
66
63
                ('','bzr: ERROR: No push location known or specified.\n'))
67
64
 
68
65
        # test not remembered if cannot actually push
69
 
        self.run_bzr('push ../path/which/doesnt/exist', retcode=3)
 
66
        self.run_bzr('push', '../path/which/doesnt/exist', retcode=3)
70
67
        out = self.run_bzr('push', retcode=3)
71
68
        self.assertEquals(
72
69
                ('', 'bzr: ERROR: No push location known or specified.\n'),
73
70
                out)
74
71
 
75
72
        # test implicit --remember when no push location set, push fails
76
 
        out = self.run_bzr('push ../branch_b', retcode=3)
 
73
        out = self.run_bzr('push', '../branch_b', retcode=3)
77
74
        self.assertEquals(out,
78
75
                ('','bzr: ERROR: These branches have diverged.  '
79
76
                    'Try using "merge" and then "push".\n'))
94
91
        self.assertEqual(path,
95
92
                         branch_b.bzrdir.root_transport.base)
96
93
        # test explicit --remember
97
 
        self.run_bzr('push ../branch_c --remember')
 
94
        self.run_bzr('push', '../branch_c', '--remember')
98
95
        self.assertEquals(branch_a.get_push_location(),
99
96
                          branch_c.bzrdir.root_transport.base)
100
97
    
101
98
    def test_push_without_tree(self):
102
99
        # bzr push from a branch that does not have a checkout should work.
103
100
        b = self.make_branch('.')
104
 
        out, err = self.run_bzr('push pushed-location')
 
101
        out, err = self.run_bzr('push', 'pushed-location')
105
102
        self.assertEqual('', out)
106
103
        self.assertEqual('Created new branch.\n', err)
107
104
        b2 = Branch.open('pushed-location')
116
113
        t.add('file')
117
114
        t.commit('commit 1')
118
115
        os.chdir('tree')
119
 
        out, err = self.run_bzr('push pushed-to')
 
116
        out, err = self.run_bzr('push', 'pushed-to')
120
117
        os.chdir('..')
121
118
        self.assertEqual('', out)
122
119
        self.assertEqual('Created new branch.\n', err)
153
150
        # Now that we have a repository with shared files, make sure
154
151
        # that things aren't copied out by a 'push'
155
152
        os.chdir('repo/b')
156
 
        self.run_bzr('push ../../push-b')
 
153
        self.run_bzr('push', '../../push-b')
157
154
        pushed_tree = WorkingTree.open('../../push-b')
158
155
        pushed_repo = pushed_tree.branch.repository
159
156
        self.assertFalse(pushed_repo.has_revision('a-1'))
166
163
        self.build_tree(['filename'])
167
164
        t.add('filename', 'funky-chars<>%&;"\'')
168
165
        t.commit('commit filename')
169
 
        self.run_bzr('push ../new-tree')
 
166
        self.run_bzr('push', '../new-tree')
170
167
 
171
168
    def test_push_dash_d(self):
172
169
        t = self.make_branch_and_tree('from')
173
170
        t.commit(allow_pointless=True,
174
171
                message='first commit')
175
 
        self.run_bzr('push -d from to-one')
 
172
        self.runbzr('push -d from to-one')
176
173
        self.failUnlessExists('to-one')
177
 
        self.run_bzr('push -d %s %s' 
 
174
        self.runbzr('push -d %s %s' 
178
175
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
179
176
        self.failUnlessExists('to-two')
180
177
 
190
187
        tree = self.create_simple_tree()
191
188
 
192
189
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
193
 
                           'push ../new/tree',
 
190
                           'push', '../new/tree',
194
191
                           working_dir='tree')
195
 
        self.run_bzr('push ../new/tree --create-prefix',
 
192
        self.run_bzr('push', '../new/tree', '--create-prefix',
196
193
                     working_dir='tree')
197
194
        new_tree = WorkingTree.open('new/tree')
198
195
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
208
205
 
209
206
        self.run_bzr_error(['Target directory ../target already exists',
210
207
                            'Supply --use-existing-dir',
211
 
                           ],
212
 
                           'push ../target', working_dir='tree')
 
208
                           ], 'push', '../target',
 
209
                           working_dir='tree')
213
210
 
214
 
        self.run_bzr('push --use-existing-dir ../target',
 
211
        self.run_bzr('push', '--use-existing-dir', '../target',
215
212
                     working_dir='tree')
216
213
 
217
214
        new_tree = WorkingTree.open('target')
224
221
        tree = self.create_simple_tree()
225
222
        repo = self.make_repository('repo', shared=True)
226
223
 
227
 
        self.run_bzr('push ../repo',
 
224
        self.run_bzr('push', '../repo',
228
225
                     working_dir='tree')
229
226
 
230
227
        # Pushing onto an existing bzrdir will create a repository and
245
242
        a_bzrdir = self.make_bzrdir('dir')
246
243
 
247
244
        self.run_bzr_error(['At ../dir you have a valid .bzr control'],
248
 
                'push ../dir',
 
245
                'push', '../dir',
249
246
                working_dir='tree')
250
 
 
251
 
    def test_push_with_revisionspec(self):
252
 
        """We should be able to push a revision older than the tip."""
253
 
        tree_from = self.make_branch_and_tree('from')
254
 
        tree_from.commit("One.", rev_id="from-1")
255
 
        tree_from.commit("Two.", rev_id="from-2")
256
 
 
257
 
        self.run_bzr('push -r1 ../to', working_dir='from')
258
 
 
259
 
        tree_to = WorkingTree.open('to')
260
 
        repo_to = tree_to.branch.repository
261
 
        self.assertTrue(repo_to.has_revision('from-1'))
262
 
        self.assertFalse(repo_to.has_revision('from-2'))
263
 
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
264
 
 
265
 
        self.run_bzr_error(
266
 
            "bzr: ERROR: bzr push --revision takes one value.\n",
267
 
            'push -r0..2 ../to', working_dir='from')
268
 
 
269
 
 
270
 
class RedirectingMemoryTransport(MemoryTransport):
271
 
 
272
 
    def mkdir(self, path, mode=None):
273
 
        path = self.abspath(path)[len(self._scheme):]
274
 
        if path == '/source':
275
 
            raise errors.RedirectRequested(
276
 
                path, self._scheme + '/target', is_permanent=True)
277
 
        elif path == '/infinite-loop':
278
 
            raise errors.RedirectRequested(
279
 
                path, self._scheme + '/infinite-loop', is_permanent=True)
280
 
        else:
281
 
            return super(RedirectingMemoryTransport, self).mkdir(
282
 
                path, mode)
283
 
 
284
 
 
285
 
class RedirectingMemoryServer(MemoryServer):
286
 
 
287
 
    def setUp(self):
288
 
        self._dirs = {'/': None}
289
 
        self._files = {}
290
 
        self._locks = {}
291
 
        self._scheme = 'redirecting-memory+%s:///' % id(self)
292
 
        register_transport(self._scheme, self._memory_factory)
293
 
 
294
 
    def _memory_factory(self, url):
295
 
        result = RedirectingMemoryTransport(url)
296
 
        result._dirs = self._dirs
297
 
        result._files = self._files
298
 
        result._locks = self._locks
299
 
        return result
300
 
 
301
 
    def tearDown(self):
302
 
        unregister_transport(self._scheme, self._memory_factory)
303
 
 
304
 
 
305
 
class TestPushRedirect(ExternalBase):
306
 
 
307
 
    def setUp(self):
308
 
        ExternalBase.setUp(self)
309
 
        self.memory_server = RedirectingMemoryServer()
310
 
        self.memory_server.setUp()
311
 
        self.addCleanup(self.memory_server.tearDown)
312
 
 
313
 
        # Make the branch and tree that we'll be pushing.
314
 
        t = self.make_branch_and_tree('tree')
315
 
        self.build_tree(['tree/file'])
316
 
        t.add('file')
317
 
        t.commit('commit 1')
318
 
 
319
 
    def test_push_redirects_on_mkdir(self):
320
 
        """If the push requires a mkdir, push respects redirect requests.
321
 
 
322
 
        This is added primarily to handle lp:/ URI support, so that users can
323
 
        push to new branches by specifying lp:/ URIs.
324
 
        """
325
 
        os.chdir('tree')
326
 
        destination_url = self.memory_server.get_url() + 'source'
327
 
        self.run_bzr('push %s' % destination_url)
328
 
        os.chdir('..')
329
 
 
330
 
        local_revision = Branch.open('tree').last_revision()
331
 
        remote_revision = Branch.open(
332
 
            self.memory_server.get_url() + 'target').last_revision()
333
 
        self.assertEqual(remote_revision, local_revision)
334
 
 
335
 
    def test_push_gracefully_handles_too_many_redirects(self):
336
 
        """Push fails gracefully if the mkdir generates a large number of
337
 
        redirects.
338
 
        """
339
 
        os.chdir('tree')
340
 
        destination_url = self.memory_server.get_url() + 'infinite-loop'
341
 
        out, err = self.run_bzr_error(
342
 
            ['Too many redirections trying to make %s\\.\n'
343
 
             % re.escape(destination_url)],
344
 
            'push %s' % destination_url, retcode=3)
345
 
        os.chdir('..')
346
 
        self.assertEqual('', out)