/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-03-08 04:06:06 UTC
  • mfrom: (2323.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2442.
  • Revision ID: robertc@robertcollins.net-20070308040606-84gsniv56huiyjt4
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
2
 
 
 
1
# Copyright (C) 2005 Canonical Ltd
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
"""Tests of bound branches (binding, unbinding, commit, etc) command.
19
 
"""
 
18
"""Tests of bound branches (binding, unbinding, commit, etc) command."""
20
19
 
21
20
import os
22
21
from cStringIO import StringIO
23
22
 
24
 
from bzrlib.tests import TestCaseWithTransport
 
23
from bzrlib import (
 
24
    bzrdir,
 
25
    )
25
26
from bzrlib.branch import Branch
26
27
from bzrlib.bzrdir import (BzrDir, BzrDirFormat, BzrDirMetaFormat1)
27
28
from bzrlib.osutils import getcwd
 
29
from bzrlib.tests import TestCaseWithTransport
 
30
import bzrlib.urlutils as urlutils
28
31
from bzrlib.workingtree import WorkingTree
29
32
 
30
33
 
41
44
        # bind on a format 6 bzrdir should error
42
45
        out,err = self.run_bzr('bind', '../master', retcode=3)
43
46
        self.assertEqual('', out)
 
47
        # TODO: jam 20060427 Probably something like this really should
 
48
        #       print out the actual path, rather than the URL
 
49
        cwd = urlutils.local_path_to_url(getcwd())
44
50
        self.assertEqual('bzr: ERROR: To use this feature you must '
45
 
                         'upgrade your branch at %s/.\n' % getcwd(), err)
 
51
                         'upgrade your branch at %s/.\n' % cwd, err)
46
52
    
47
53
    def test_unbind_format_6_bzrdir(self):
48
54
        # bind on a format 6 bzrdir should error
49
55
        out,err = self.run_bzr('unbind', retcode=3)
50
56
        self.assertEqual('', out)
 
57
        cwd = urlutils.local_path_to_url(getcwd())
51
58
        self.assertEqual('bzr: ERROR: To use this feature you must '
52
 
                         'upgrade your branch at %s/.\n' % getcwd(), err)
 
59
                         'upgrade your branch at %s/.\n' % cwd, err)
53
60
 
54
61
 
55
62
class TestBoundBranches(TestCaseWithTransport):
95
102
 
96
103
        self.run_bzr('unbind', retcode=3)
97
104
 
 
105
    def test_bind_branch6(self):
 
106
        branch1 = self.make_branch('branch1', format='dirstate-with-subtree')
 
107
        os.chdir('branch1')
 
108
        error = self.run_bzr('bind', retcode=3)[1]
 
109
        self.assertContainsRe(error, 'no previous location known')
 
110
 
 
111
    def setup_rebind(self, format):
 
112
        branch1 = self.make_branch('branch1')
 
113
        branch2 = self.make_branch('branch2', format=format)
 
114
        branch2.bind(branch1)
 
115
        branch2.unbind()
 
116
 
 
117
    def test_rebind_branch6(self):
 
118
        self.setup_rebind('dirstate-with-subtree')
 
119
        os.chdir('branch2')
 
120
        self.run_bzr('bind')
 
121
        b = Branch.open('.')
 
122
        self.assertContainsRe(b.get_bound_location(), '\/branch1\/$')
 
123
 
 
124
    def test_rebind_branch5(self):
 
125
        self.setup_rebind('knit')
 
126
        os.chdir('branch2')
 
127
        error = self.run_bzr('bind', retcode=3)[1]
 
128
        self.assertContainsRe(error, 'old locations')
 
129
 
98
130
    def init_meta_branch(self, path):
99
 
        old_format = BzrDirFormat.get_default_format()
100
 
        BzrDirFormat.set_default_format(BzrDirMetaFormat1())
101
 
        try:
102
 
            return BzrDir.create_branch_convenience(
103
 
                path, BzrDirMetaFormat1())
104
 
        finally:
105
 
            BzrDirFormat.set_default_format(old_format)
 
131
        format = bzrdir.format_registry.make_bzrdir('knit')
 
132
        return BzrDir.create_branch_convenience(path, format=format)
106
133
 
107
134
    def test_bound_commit(self):
108
135
        bzr = self.run_bzr
230
257
        bzr('commit', '-m', 'merged')
231
258
        self.check_revno(3)
232
259
 
 
260
        # After binding, the revision history should be unaltered
 
261
        base_branch = Branch.open('../base')
 
262
        child_branch = Branch.open('.')
 
263
        # take a copy before
 
264
        base_history = base_branch.revision_history()
 
265
        child_history = child_branch.revision_history()
 
266
 
233
267
        # After a merge, trying to bind again should succeed
234
 
        # by pushing the new change to base
 
268
        # keeping the new change as a local commit.
235
269
        bzr('bind', '../base')
236
270
        self.check_revno(3)
237
 
        self.check_revno(3, '../base')
 
271
        self.check_revno(2, '../base')
238
272
 
239
 
        # After binding, the revision history should be identical
240
 
        child_rh = bzr('revision-history')[0]
241
 
        os.chdir('../base')
242
 
        base_rh = bzr('revision-history')[0]
243
 
        self.assertEquals(child_rh, base_rh)
 
273
        # and compare the revision history now
 
274
        self.assertEqual(base_history, base_branch.revision_history())
 
275
        self.assertEqual(child_history, child_branch.revision_history())
244
276
 
245
277
    def test_bind_parent_ahead(self):
246
278
        bzr = self.run_bzr
256
288
        self.check_revno(1)
257
289
        bzr('bind', '../base')
258
290
 
259
 
        self.check_revno(2)
 
291
        # binding does not pull data:
 
292
        self.check_revno(1)
260
293
        bzr('unbind')
261
294
 
262
295
        # Check and make sure it also works if parent is ahead multiple
267
300
        self.check_revno(5)
268
301
 
269
302
        os.chdir('../child')
270
 
        self.check_revno(2)
 
303
        self.check_revno(1)
271
304
        bzr('bind', '../base')
272
 
        self.check_revno(5)
 
305
        self.check_revno(1)
273
306
 
274
307
    def test_bind_child_ahead(self):
275
308
        # test binding when the master branches history is a prefix of the 
276
 
        # childs
 
309
        # childs - it should bind ok but the revision histories should not
 
310
        # be altered
277
311
        bzr = self.run_bzr
278
312
        self.create_branches()
279
 
        return
280
313
 
281
314
        os.chdir('child')
282
315
        bzr('unbind')
285
318
        self.check_revno(1, '../base')
286
319
 
287
320
        bzr('bind', '../base')
288
 
        self.check_revno(2, '../base')
 
321
        self.check_revno(1, '../base')
289
322
 
290
323
        # Check and make sure it also works if child is ahead multiple
291
324
        bzr('unbind')
294
327
        bzr('commit', '-m', 'child 5', '--unchanged')
295
328
        self.check_revno(5)
296
329
 
297
 
        self.check_revno(2, '../base')
 
330
        self.check_revno(1, '../base')
298
331
        bzr('bind', '../base')
299
 
        self.check_revno(5, '../base')
 
332
        self.check_revno(1, '../base')
300
333
 
301
334
    def test_commit_after_merge(self):
302
335
        bzr = self.run_bzr
319
352
        bzr('merge', '../other')
320
353
 
321
354
        self.failUnlessExists('c')
322
 
        tree = WorkingTree.open('.')
323
 
        self.assertEqual([new_rev_id], tree.pending_merges())
 
355
        tree = WorkingTree.open('.') # opens child
 
356
        self.assertEqual([new_rev_id], tree.get_parent_ids()[1:])
324
357
 
325
358
        # Make sure the local branch has the installed revision
326
359
        bzr('cat-revision', new_rev_id)
341
374
 
342
375
        bzr('cat-revision', new_rev_id)
343
376
 
344
 
    def test_pull_overwrite_fails(self):
 
377
    def test_pull_overwrite(self):
 
378
        # XXX: This test should be moved to branch-implemenations/test_pull
345
379
        bzr = self.run_bzr
346
380
        self.create_branches()
347
381
 
365
399
        self.check_revno(2)
366
400
        self.check_revno(2, '../base')
367
401
 
368
 
        # It might be possible that we want pull --overwrite to
369
 
        # actually succeed.
370
 
        # If we want it, just change this test to make sure that 
371
 
        # both base and child are updated properly
372
 
        bzr('pull', '--overwrite', '../other', retcode=3)
373
 
 
374
 
        # It should fail without changing the local revision
375
 
        self.check_revno(2)
376
 
        self.check_revno(2, '../base')
377
 
 
378
 
    # TODO: jam 20051230 Test that commit & pull fail when the branch we 
379
 
    #       are bound to is not available
380
 
 
381
 
 
 
402
        bzr('pull', '--overwrite', '../other')
 
403
 
 
404
        # both the local and master should have been updated.
 
405
        self.check_revno(4)
 
406
        self.check_revno(4, '../base')