1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005 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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
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.
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
18
"""Tests of bound branches (binding, unbinding, commit, etc) command.
18
"""Tests of bound branches (binding, unbinding, commit, etc) command."""
22
21
from cStringIO import StringIO
24
from bzrlib.tests import TestCaseWithTransport
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
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)
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)
55
62
class TestBoundBranches(TestCaseWithTransport):
96
103
self.run_bzr('unbind', retcode=3)
105
def test_bind_branch6(self):
106
branch1 = self.make_branch('branch1', format='dirstate-with-subtree')
108
error = self.run_bzr('bind', retcode=3)[1]
109
self.assertContainsRe(error, 'no previous location known')
111
def setup_rebind(self, format):
112
branch1 = self.make_branch('branch1')
113
branch2 = self.make_branch('branch2', format=format)
114
branch2.bind(branch1)
117
def test_rebind_branch6(self):
118
self.setup_rebind('dirstate-with-subtree')
122
self.assertContainsRe(b.get_bound_location(), '\/branch1\/$')
124
def test_rebind_branch5(self):
125
self.setup_rebind('knit')
127
error = self.run_bzr('bind', retcode=3)[1]
128
self.assertContainsRe(error, 'old locations')
98
130
def init_meta_branch(self, path):
99
old_format = BzrDirFormat.get_default_format()
100
BzrDirFormat.set_default_format(BzrDirMetaFormat1())
102
return BzrDir.create_branch_convenience(
103
path, BzrDirMetaFormat1())
105
BzrDirFormat.set_default_format(old_format)
131
format = bzrdir.format_registry.make_bzrdir('knit')
132
return BzrDir.create_branch_convenience(path, format=format)
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)
260
# After binding, the revision history should be unaltered
261
base_branch = Branch.open('../base')
262
child_branch = Branch.open('.')
264
base_history = base_branch.revision_history()
265
child_history = child_branch.revision_history()
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')
239
# After binding, the revision history should be identical
240
child_rh = bzr('revision-history')[0]
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())
245
277
def test_bind_parent_ahead(self):
246
278
bzr = self.run_bzr
285
318
self.check_revno(1, '../base')
287
320
bzr('bind', '../base')
288
self.check_revno(2, '../base')
321
self.check_revno(1, '../base')
290
323
# Check and make sure it also works if child is ahead multiple
294
327
bzr('commit', '-m', 'child 5', '--unchanged')
295
328
self.check_revno(5)
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')
301
334
def test_commit_after_merge(self):
302
335
bzr = self.run_bzr
319
352
bzr('merge', '../other')
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:])
325
358
# Make sure the local branch has the installed revision
326
359
bzr('cat-revision', new_rev_id)
342
375
bzr('cat-revision', new_rev_id)
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()
365
399
self.check_revno(2)
366
400
self.check_revno(2, '../base')
368
# It might be possible that we want pull --overwrite to
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)
374
# It should fail without changing the local revision
376
self.check_revno(2, '../base')
378
# TODO: jam 20051230 Test that commit & pull fail when the branch we
379
# are bound to is not available
402
bzr('pull', '--overwrite', '../other')
404
# both the local and master should have been updated.
406
self.check_revno(4, '../base')