/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: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
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
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
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Tests of bound branches (binding, unbinding, commit, etc) command."""
22
22
 
23
23
from bzrlib import (
24
24
    bzrdir,
25
 
    errors
 
25
    errors,
 
26
    tests,
26
27
    )
27
28
from bzrlib.branch import Branch
28
29
from bzrlib.bzrdir import (BzrDir, BzrDirFormat, BzrDirMetaFormat1)
29
30
from bzrlib.osutils import getcwd
30
 
from bzrlib.tests import TestCaseWithTransport
 
31
from bzrlib.tests import script
31
32
import bzrlib.urlutils as urlutils
32
33
from bzrlib.workingtree import WorkingTree
33
34
 
34
35
 
35
 
class TestLegacyFormats(TestCaseWithTransport):
36
 
    
 
36
class TestLegacyFormats(tests.TestCaseWithTransport):
 
37
 
37
38
    def setUp(self):
38
39
        super(TestLegacyFormats, self).setUp()
39
40
        self.build_tree(['master/', 'child/'])
41
42
        self.make_branch_and_tree('child',
42
43
                        format=bzrdir.format_registry.make_bzrdir('weave'))
43
44
        os.chdir('child')
44
 
    
 
45
 
45
46
    def test_bind_format_6_bzrdir(self):
46
47
        # bind on a format 6 bzrdir should error
47
48
        out,err = self.run_bzr('bind ../master', retcode=3)
51
52
        cwd = urlutils.local_path_to_url(getcwd())
52
53
        self.assertEqual('bzr: ERROR: To use this feature you must '
53
54
                         'upgrade your branch at %s/.\n' % cwd, err)
54
 
    
 
55
 
55
56
    def test_unbind_format_6_bzrdir(self):
56
57
        # bind on a format 6 bzrdir should error
57
58
        out,err = self.run_bzr('unbind', retcode=3)
61
62
                         'upgrade your branch at %s/.\n' % cwd, err)
62
63
 
63
64
 
64
 
class TestBoundBranches(TestCaseWithTransport):
 
65
class TestBoundBranches(tests.TestCaseWithTransport):
65
66
 
66
67
    def create_branches(self):
67
 
        self.build_tree(['base/', 'base/a', 'base/b'])
68
 
 
69
 
        branch = self.init_meta_branch('base')
70
 
        base_tree = branch.bzrdir.open_workingtree()
 
68
        base_tree = self.make_branch_and_tree('base')
71
69
        base_tree.lock_write()
 
70
        self.build_tree(['base/a', 'base/b'])
72
71
        base_tree.add(['a', 'b'])
73
72
        base_tree.commit('init')
74
73
        base_tree.unlock()
 
74
        branch = base_tree.branch
75
75
 
76
76
        child_tree = branch.create_checkout('child')
77
77
 
86
86
            val, len(BzrDir.open(loc).open_branch().revision_history()))
87
87
 
88
88
    def test_simple_binding(self):
89
 
        self.build_tree(['base/', 'base/a', 'base/b'])
90
 
 
91
 
        branch = self.init_meta_branch('base')
92
 
        tree = branch.bzrdir.open_workingtree()
 
89
        tree = self.make_branch_and_tree('base')
 
90
        self.build_tree(['base/a', 'base/b'])
93
91
        tree.add('a', 'b')
94
92
        tree.commit(message='init')
 
93
        branch = tree.branch
95
94
 
96
95
        tree.bzrdir.sprout('child')
97
96
 
131
130
        error = self.run_bzr('bind', retcode=3)[1]
132
131
        self.assertContainsRe(error, 'old locations')
133
132
 
134
 
    def init_meta_branch(self, path):
135
 
        format = bzrdir.format_registry.make_bzrdir('default')
136
 
        return BzrDir.create_branch_convenience(path, format=format)
137
 
 
138
133
    def test_bound_commit(self):
139
134
        child_tree = self.create_branches()[1]
140
135
 
228
223
 
229
224
        self.check_revno(2, '../base')
230
225
 
 
226
    def test_pull_local_updates_local(self):
 
227
        base_tree = self.create_branches()[0]
 
228
        newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
 
229
        self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
 
230
        newchild_tree.commit(message='newchild')
 
231
        self.check_revno(2, 'newchild')
 
232
 
 
233
        os.chdir('child')
 
234
        # The pull should succeed, and update
 
235
        # the bound parent branch
 
236
        self.run_bzr('pull ../newchild --local')
 
237
        self.check_revno(2)
 
238
 
 
239
        self.check_revno(1, '../base')
 
240
 
231
241
    def test_bind_diverged(self):
232
242
        base_tree, child_tree = self.create_branches()
233
243
        base_branch = base_tree.branch
284
294
        self.check_revno(1)
285
295
 
286
296
    def test_bind_child_ahead(self):
287
 
        # test binding when the master branches history is a prefix of the 
 
297
        # test binding when the master branches history is a prefix of the
288
298
        # childs - it should bind ok but the revision histories should not
289
299
        # be altered
290
300
        child_tree = self.create_branches()[1]
317
327
                            working_dir='tree_1')
318
328
        self.assertIs(None, tree.branch.get_bound_location())
319
329
 
 
330
    def test_bind_nick(self):
 
331
        """Bind should not update implicit nick."""
 
332
        base = self.make_branch_and_tree('base')
 
333
        child = self.make_branch_and_tree('child')
 
334
        os.chdir('child')
 
335
        self.assertEqual(child.branch.nick, 'child')
 
336
        self.assertEqual(child.branch.get_config().has_explicit_nickname(),
 
337
            False)
 
338
        self.run_bzr('bind ../base')
 
339
        self.assertEqual(child.branch.nick, base.branch.nick)
 
340
        self.assertEqual(child.branch.get_config().has_explicit_nickname(),
 
341
            False)
 
342
 
 
343
    def test_bind_explicit_nick(self):
 
344
        """Bind should update explicit nick."""
 
345
        base = self.make_branch_and_tree('base')
 
346
        child = self.make_branch_and_tree('child')
 
347
        os.chdir('child')
 
348
        child.branch.nick = "explicit_nick"
 
349
        self.assertEqual(child.branch.nick, "explicit_nick")
 
350
        self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
 
351
            "explicit_nick")
 
352
        self.run_bzr('bind ../base')
 
353
        self.assertEqual(child.branch.nick, base.branch.nick)
 
354
        self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
 
355
            base.branch.nick)
 
356
 
320
357
    def test_commit_after_merge(self):
321
358
        base_tree, child_tree = self.create_branches()
322
359
 
384
421
        # both the local and master should have been updated.
385
422
        self.check_revno(4)
386
423
        self.check_revno(4, '../base')
 
424
 
 
425
 
 
426
class TestBind(script.TestCaseWithTransportAndScript):
 
427
 
 
428
    def test_bind_when_bound(self):
 
429
        self.run_script("""
 
430
$ bzr init trunk
 
431
$ bzr init copy
 
432
$ cd copy
 
433
$ bzr bind ../trunk
 
434
$ bzr bind
 
435
2>bzr: ERROR: Branch is already bound
 
436
""")
 
437
 
 
438
    def test_bind_before_bound(self):
 
439
        self.run_script("""
 
440
$ bzr init trunk
 
441
$ cd trunk
 
442
$ bzr bind
 
443
2>bzr: ERROR: No location supplied and no previous location known
 
444
""")