18
18
"""Tests of bound branches (binding, unbinding, commit, etc) command."""
22
20
from bzrlib import (
26
from bzrlib.branch import Branch
27
from bzrlib.bzrdir import BzrDir
28
26
from bzrlib.tests import script
42
40
child_tree = branch.create_checkout('child')
44
42
self.check_revno(1, 'child')
45
d = BzrDir.open('child')
43
d = bzrdir.BzrDir.open('child')
46
44
self.assertNotEqual(None, d.open_branch().get_master_branch())
48
46
return base_tree, child_tree
50
48
def check_revno(self, val, loc='.'):
52
val, BzrDir.open(loc).open_branch().last_revision_info()[0])
50
val, bzrdir.BzrDir.open(loc).open_branch().last_revision_info()[0])
54
52
def test_simple_binding(self):
55
53
tree = self.make_branch_and_tree('base')
56
54
self.build_tree(['base/a', 'base/b'])
58
56
tree.commit(message='init')
61
58
tree.bzrdir.sprout('child')
63
60
self.run_bzr('bind ../base', working_dir='child')
65
d = BzrDir.open('child')
62
d = bzrdir.BzrDir.open('child')
66
63
self.assertNotEqual(None, d.open_branch().get_master_branch())
68
65
self.run_bzr('unbind', working_dir='child')
73
70
def test_bind_branch6(self):
74
71
branch1 = self.make_branch('branch1', format='dirstate-tags')
75
72
error = self.run_bzr('bind', retcode=3, working_dir='branch1')[1]
76
self.assertContainsRe(error, 'no previous location known')
74
error, 'No location supplied and no previous location known\n')
78
76
def setup_rebind(self, format):
79
77
branch1 = self.make_branch('branch1')
84
82
def test_rebind_branch6(self):
85
83
self.setup_rebind('dirstate-tags')
86
84
self.run_bzr('bind', working_dir='branch2')
87
b = Branch.open('branch2')
88
self.assertContainsRe(b.get_bound_location(), '\/branch1\/$')
85
b = branch.Branch.open('branch2')
86
self.assertEndsWith(b.get_bound_location(), '/branch1/')
90
88
def test_rebind_branch5(self):
91
89
self.setup_rebind('knit')
92
90
error = self.run_bzr('bind', retcode=3, working_dir='branch2')[1]
93
self.assertContainsRe(error, 'old locations')
92
error, 'No location supplied. This format does not remember'
95
95
def test_bound_commit(self):
96
96
child_tree = self.create_branches()[1]
181
181
# the bound parent branch
182
182
self.run_bzr('pull ../newchild', working_dir='child')
183
183
self.check_revno(2, 'child')
185
184
self.check_revno(2, 'base')
187
186
def test_pull_local_updates_local(self):
195
194
# the bound parent branch
196
195
self.run_bzr('pull ../newchild --local', working_dir='child')
197
196
self.check_revno(2, 'child')
199
197
self.check_revno(1, 'base')
201
199
def test_bind_diverged(self):
221
219
child_tree.update()
222
220
child_tree.commit(message='merged')
223
221
self.check_revno(3, 'child')
226
child_tree.branch.last_revision(),
227
base_tree.branch.last_revision())
222
self.assertEquals(child_tree.branch.last_revision(),
223
base_tree.branch.last_revision())
229
225
def test_bind_parent_ahead(self):
230
226
base_tree = self.create_branches()[0]
286
282
working_dir='tree_1')
287
283
self.assertIs(None, tree.branch.get_bound_location())
289
def test_bind_nick(self):
290
"""Bind should not update implicit nick."""
291
base = self.make_branch_and_tree('base')
292
child = self.make_branch_and_tree('child')
293
self.assertEqual(child.branch.nick, 'child')
294
self.assertEqual(False,
295
child.branch.get_config().has_explicit_nickname())
296
self.run_bzr('bind ../base', working_dir='child')
297
# Refresh the child tree/branch objects as 'bind' modified them
298
child = BzrDir.open('child').open_workingtree()
299
self.assertEqual(child.branch.nick, base.branch.nick)
300
self.assertEqual(False,
301
child.branch.get_config().has_explicit_nickname())
303
def test_bind_explicit_nick(self):
304
"""Bind should update explicit nick."""
305
base = self.make_branch_and_tree('base')
306
child = self.make_branch_and_tree('child')
307
child.branch.nick = "explicit_nick"
308
self.assertEqual("explicit_nick", child.branch.nick)
309
self.assertEqual("explicit_nick",
310
child.branch.get_config()._get_explicit_nickname())
311
self.run_bzr('bind ../base', working_dir='child')
312
# Refresh the child tree/branch objects as 'bind' modified them
313
child = BzrDir.open('child').open_workingtree()
314
self.assertEqual(child.branch.nick, base.branch.nick)
315
self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
318
285
def test_commit_after_merge(self):
319
286
base_tree, child_tree = self.create_branches()
344
311
# Commit should succeed, and cause merged revisions to
345
312
# be pulled into base
346
313
self.run_bzr(['commit', '-m', 'merge other'], working_dir='child')
348
314
self.check_revno(2, 'child')
350
315
self.check_revno(2, 'base')
352
316
self.assertTrue(base_tree.branch.repository.has_revision(new_rev_id))
354
318
def test_pull_overwrite(self):
390
354
branch = tree.branch
391
355
tree.bzrdir.sprout('child')
392
356
self.run_bzr('bind --directory=child base')
393
d = BzrDir.open('child')
357
d = bzrdir.BzrDir.open('child')
394
358
self.assertNotEqual(None, d.open_branch().get_master_branch())
395
359
self.run_bzr('unbind -d child')
396
360
self.assertEqual(None, d.open_branch().get_master_branch())