1
# Copyright (C) 2005 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
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
18
"""Tests of bound branches (binding, unbinding, commit, etc) command.
23
from cStringIO import StringIO
25
from bzrlib.selftest import TestCaseInTempDir
26
from bzrlib.branch import Branch
28
class TestBoundBranches(TestCaseInTempDir):
30
def create_branches(self):
32
self.build_tree(['base/', 'base/a', 'base/b'])
37
bzr('commit', '-m', 'init')
41
bzr('get', '--bound', 'base', 'child')
43
self.failUnlessExists('child')
47
self.failUnlessExists('.bzr/bound')
50
def check_revno(self, val, loc=None):
54
self.assertEquals(self.capture('revno').strip(), str(val))
58
def test_simple_binding(self):
60
self.build_tree(['base/', 'base/a', 'base/b'])
65
bzr('commit', '-m', 'init')
68
bzr('branch', 'base', 'child')
71
bzr('bind', '../base')
73
self.failUnlessExists('.bzr/bound')
76
self.failIf(os.path.lexists('.bzr/bound'))
78
# TODO: Should unbinding a non-bound branch fail?
81
def test_bound_commit(self):
83
self.create_branches()
86
open('a', 'wb').write('new contents\n')
87
bzr('commit', '-m', 'child')
91
# Make sure it committed on the parent
95
def test_bound_fail(self):
96
"""Make sure commit fails if out of date."""
98
self.create_branches()
101
open('a', 'wb').write('new base contents\n')
102
bzr('commit', '-m', 'base')
105
open('b', 'wb').write('new b child contents\n')
106
bzr('commit', '-m', 'child', retcode=3)
111
bzr('commit', '-m', 'child')
116
def test_double_binding(self):
118
self.create_branches()
120
bzr('branch', 'child', 'child2')
123
# Double binding succeeds, but committing to child2 should fail
124
bzr('bind', '../child')
126
bzr('commit', '-m', 'child2', '--unchanged', retcode=3)
128
def test_unbinding(self):
130
self.create_branches()
133
open('a', 'wb').write('new base contents\n')
134
bzr('commit', '-m', 'base')
138
open('b', 'wb').write('new b child contents\n')
140
bzr('commit', '-m', 'child', retcode=3)
143
bzr('commit', '-m', 'child')
146
bzr('bind', retcode=3)
148
def test_commit_remote_bound(self):
149
# It is not possible to commit to a branch
150
# which is bound to a branch which is bound
152
self.create_branches()
153
bzr('branch', 'base', 'newbase')
156
# There is no way to know that B has already
157
# been bound by someone else, otherwise it
158
# might be nice if this would fail
159
bzr('bind', '../newbase')
162
bzr('commit', '-m', 'failure', '--unchanged', retcode=3)
165
def test_pull_updates_both(self):
167
self.create_branches()
168
bzr('branch', 'base', 'newchild')
170
open('b', 'wb').write('newchild b contents\n')
171
bzr('commit', '-m', 'newchild')
175
# The pull should succeed, and update
176
# the bound parent branch
177
bzr('pull', '../newchild')
183
def test_bind_diverged(self):
185
self.create_branches()
190
bzr('commit', '-m', 'child', '--unchanged')
195
bzr('commit', '-m', 'base', '--unchanged')
199
# These branches have diverged
200
bzr('bind', '../base', retcode=3)
202
# TODO: In the future, this might require actual changes
203
# to have occurred, rather than just a new revision entry
204
bzr('merge', '../base')
205
bzr('commit', '-m', 'merged')
208
# After a merge, trying to bind again should succeed
209
# by pushing the new change to base
210
bzr('bind', '../base')
212
self.check_revno(3, '../base')
214
# After binding, the revision history should be identical
215
child_rh = self.capture('revision-history')
217
base_rh = self.capture('revision-history')
218
self.assertEquals(child_rh, base_rh)
220
def test_bind_parent_ahead(self):
222
self.create_branches()
228
bzr('commit', '-m', 'base', '--unchanged')
232
bzr('bind', '../base')
237
# Check and make sure it also works if parent is ahead multiple
239
bzr('commit', '-m', 'base 3', '--unchanged')
240
bzr('commit', '-m', 'base 4', '--unchanged')
241
bzr('commit', '-m', 'base 5', '--unchanged')
249
def test_bind_child_ahead(self):
251
self.create_branches()
255
bzr('commit', '-m', 'child', '--unchanged')
257
self.check_revno(1, '../base')
259
bzr('bind', '../base')
260
self.check_revno(2, '../base')
262
# Check and make sure it also works if child is ahead multiple
264
bzr('commit', '-m', 'child 3', '--unchanged')
265
bzr('commit', '-m', 'child 4', '--unchanged')
266
bzr('commit', '-m', 'child 5', '--unchanged')
269
self.check_revno(2, '../base')
271
self.check_revno(5, '../base')