1
# Copyright (C) 2005 Canonical Ltd
1
# Copyright (C) 2005-2010 Canonical Ltd
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
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
18
18
"""Tests of bound branches (binding, unbinding, commit, etc) command."""
23
23
from bzrlib import (
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
35
class TestLegacyFormats(TestCaseWithTransport):
36
class TestLegacyFormats(tests.TestCaseWithTransport):
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'))
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)
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)
64
class TestBoundBranches(TestCaseWithTransport):
65
class TestBoundBranches(tests.TestCaseWithTransport):
66
67
def create_branches(self):
67
self.build_tree(['base/', 'base/a', 'base/b'])
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
branch = base_tree.branch
76
76
child_tree = branch.create_checkout('child')
86
86
val, len(BzrDir.open(loc).open_branch().revision_history()))
88
88
def test_simple_binding(self):
89
self.build_tree(['base/', 'base/a', 'base/b'])
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'])
94
92
tree.commit(message='init')
96
95
tree.bzrdir.sprout('child')
131
130
error = self.run_bzr('bind', retcode=3)[1]
132
131
self.assertContainsRe(error, 'old locations')
134
def init_meta_branch(self, path):
135
format = bzrdir.format_registry.make_bzrdir('default')
136
return BzrDir.create_branch_convenience(path, format=format)
138
133
def test_bound_commit(self):
139
134
child_tree = self.create_branches()[1]
229
224
self.check_revno(2, '../base')
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')
234
# The pull should succeed, and update
235
# the bound parent branch
236
self.run_bzr('pull ../newchild --local')
239
self.check_revno(1, '../base')
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)
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
290
300
child_tree = self.create_branches()[1]
317
327
working_dir='tree_1')
318
328
self.assertIs(None, tree.branch.get_bound_location())
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')
335
self.assertEqual(child.branch.nick, 'child')
336
self.assertEqual(child.branch.get_config().has_explicit_nickname(),
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(),
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')
348
child.branch.nick = "explicit_nick"
349
self.assertEqual(child.branch.nick, "explicit_nick")
350
self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
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(),
320
357
def test_commit_after_merge(self):
321
358
base_tree, child_tree = self.create_branches()
384
421
# both the local and master should have been updated.
385
422
self.check_revno(4)
386
423
self.check_revno(4, '../base')
426
class TestBind(script.TestCaseWithTransportAndScript):
428
def test_bind_when_bound(self):
435
2>bzr: ERROR: Branch is already bound
438
def test_bind_before_bound(self):
443
2>bzr: ERROR: No location supplied and no previous location known