101
107
self.run_bzr('unbind', retcode=3)
109
def test_bind_branch6(self):
110
branch1 = self.make_branch('branch1', format='dirstate-tags')
112
error = self.run_bzr('bind', retcode=3)[1]
113
self.assertContainsRe(error, 'no previous location known')
115
def setup_rebind(self, format):
116
branch1 = self.make_branch('branch1')
117
branch2 = self.make_branch('branch2', format=format)
118
branch2.bind(branch1)
121
def test_rebind_branch6(self):
122
self.setup_rebind('dirstate-tags')
126
self.assertContainsRe(b.get_bound_location(), '\/branch1\/$')
128
def test_rebind_branch5(self):
129
self.setup_rebind('knit')
131
error = self.run_bzr('bind', retcode=3)[1]
132
self.assertContainsRe(error, 'old locations')
103
134
def init_meta_branch(self, path):
104
old_format = BzrDirFormat.get_default_format()
105
BzrDirFormat.set_default_format(BzrDirMetaFormat1())
107
return BzrDir.create_branch_convenience(
108
path, BzrDirMetaFormat1())
110
BzrDirFormat.set_default_format(old_format)
135
format = bzrdir.format_registry.make_bzrdir('default')
136
return BzrDir.create_branch_convenience(path, format=format)
112
138
def test_bound_commit(self):
114
self.create_branches()
117
open('a', 'wb').write('new contents\n')
118
bzr('commit', '-m', 'child')
139
child_tree = self.create_branches()[1]
141
self.build_tree_contents([('child/a', 'new contents')])
142
child_tree.commit(message='child')
144
self.check_revno(2, 'child')
122
146
# Make sure it committed on the parent
123
self.check_revno(2, '../base')
147
self.check_revno(2, 'base')
125
149
def test_bound_fail(self):
126
150
# Make sure commit fails if out of date.
128
self.create_branches()
131
open('a', 'wb').write('new base contents\n')
132
bzr('commit', '-m', 'base')
137
open('b', 'wb').write('new b child contents\n')
138
bzr('commit', '-m', 'child', retcode=3)
144
bzr('commit', '-m', 'child')
146
self.check_revno(3, '../base')
151
base_tree, child_tree = self.create_branches()
153
self.build_tree_contents([
154
('base/a', 'new base contents\n' ),
155
('child/b', 'new b child contents\n')])
156
base_tree.commit(message='base')
157
self.check_revno(2, 'base')
159
self.check_revno(1, 'child')
160
self.assertRaises(errors.BoundBranchOutOfDate, child_tree.commit,
162
self.check_revno(1, 'child')
165
self.check_revno(2, 'child')
167
child_tree.commit(message='child')
168
self.check_revno(3, 'child')
169
self.check_revno(3, 'base')
148
171
def test_double_binding(self):
150
self.create_branches()
152
bzr('branch', 'child', 'child2')
172
child_tree = self.create_branches()[1]
174
child2_tree = child_tree.bzrdir.sprout('child2').open_workingtree()
153
176
os.chdir('child2')
155
177
# Double binding succeeds, but committing to child2 should fail
156
bzr('bind', '../child')
178
self.run_bzr('bind ../child')
158
bzr('commit', '-m', 'child2', '--unchanged', retcode=3)
180
self.assertRaises(errors.CommitToDoubleBoundBranch,
181
child2_tree.commit, message='child2', allow_pointless=True)
160
183
def test_unbinding(self):
162
self.create_branches()
165
open('a', 'wb').write('new base contents\n')
166
bzr('commit', '-m', 'base')
170
open('b', 'wb').write('new b child contents\n')
172
bzr('commit', '-m', 'child', retcode=3)
175
bzr('commit', '-m', 'child')
178
bzr('bind', retcode=3)
184
base_tree, child_tree = self.create_branches()
186
self.build_tree_contents([
187
('base/a', 'new base contents\n' ),
188
('child/b', 'new b child contents\n')])
190
base_tree.commit(message='base')
191
self.check_revno(2, 'base')
193
self.check_revno(1, 'child')
195
self.run_bzr("commit -m child", retcode=3)
197
self.run_bzr('unbind')
198
child_tree.commit(message='child')
180
201
def test_commit_remote_bound(self):
181
202
# It is not possible to commit to a branch
182
203
# which is bound to a branch which is bound
184
self.create_branches()
185
bzr('branch', 'base', 'newbase')
204
base_tree, child_tree = self.create_branches()
205
base_tree.bzrdir.sprout('newbase')
188
208
# There is no way to know that B has already
189
209
# been bound by someone else, otherwise it
190
210
# might be nice if this would fail
191
bzr('bind', '../newbase')
211
self.run_bzr('bind ../newbase')
193
213
os.chdir('../child')
194
bzr('commit', '-m', 'failure', '--unchanged', retcode=3)
214
self.run_bzr('commit -m failure --unchanged', retcode=3)
196
216
def test_pull_updates_both(self):
198
self.create_branches()
199
bzr('branch', 'base', 'newchild')
201
open('b', 'wb').write('newchild b contents\n')
202
bzr('commit', '-m', 'newchild')
217
base_tree = self.create_branches()[0]
218
newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
219
self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
220
newchild_tree.commit(message='newchild')
221
self.check_revno(2, 'newchild')
206
224
# The pull should succeed, and update
207
225
# the bound parent branch
208
bzr('pull', '../newchild')
226
self.run_bzr('pull ../newchild')
209
227
self.check_revno(2)
211
229
self.check_revno(2, '../base')
213
231
def test_bind_diverged(self):
215
self.create_branches()
220
bzr('commit', '-m', 'child', '--unchanged')
225
bzr('commit', '-m', 'base', '--unchanged')
229
# These branches have diverged
230
bzr('bind', '../base', retcode=3)
232
# TODO: In the future, this might require actual changes
233
# to have occurred, rather than just a new revision entry
234
bzr('merge', '../base')
235
bzr('commit', '-m', 'merged')
238
# After a merge, trying to bind again should succeed
239
# by pushing the new change to base
240
bzr('bind', '../base')
242
self.check_revno(3, '../base')
244
# After binding, the revision history should be identical
245
child_rh = bzr('revision-history')[0]
247
base_rh = bzr('revision-history')[0]
248
self.assertEquals(child_rh, base_rh)
232
base_tree, child_tree = self.create_branches()
233
base_branch = base_tree.branch
234
child_branch = child_tree.branch
237
self.run_bzr('unbind')
239
child_tree.commit(message='child', allow_pointless=True)
243
self.check_revno(1, 'base')
244
base_tree.commit(message='base', allow_pointless=True)
245
self.check_revno(2, 'base')
248
# These branches have diverged, but bind should succeed anyway
249
self.run_bzr('bind ../base')
251
# This should turn the local commit into a merge
253
child_tree.commit(message='merged')
256
# After binding, the revision history should be unaltered
258
base_history = base_branch.revision_history()
259
child_history = child_branch.revision_history()
250
261
def test_bind_parent_ahead(self):
252
self.create_branches()
262
base_tree = self.create_branches()[0]
254
264
os.chdir('child')
258
bzr('commit', '-m', 'base', '--unchanged')
262
bzr('bind', '../base')
265
self.run_bzr('unbind')
267
base_tree.commit(message='base', allow_pointless=True)
270
self.run_bzr('bind ../base')
272
# binding does not pull data:
274
self.run_bzr('unbind')
267
276
# Check and make sure it also works if parent is ahead multiple
269
bzr('commit', '-m', 'base 3', '--unchanged')
270
bzr('commit', '-m', 'base 4', '--unchanged')
271
bzr('commit', '-m', 'base 5', '--unchanged')
277
base_tree.commit(message='base 3', allow_pointless=True)
278
base_tree.commit(message='base 4', allow_pointless=True)
279
base_tree.commit(message='base 5', allow_pointless=True)
280
self.check_revno(5, '../base')
276
bzr('bind', '../base')
283
self.run_bzr('bind ../base')
279
286
def test_bind_child_ahead(self):
280
287
# test binding when the master branches history is a prefix of the
283
self.create_branches()
288
# childs - it should bind ok but the revision histories should not
290
child_tree = self.create_branches()[1]
286
292
os.chdir('child')
288
bzr('commit', '-m', 'child', '--unchanged')
293
self.run_bzr('unbind')
294
child_tree.commit(message='child', allow_pointless=True)
289
295
self.check_revno(2)
290
296
self.check_revno(1, '../base')
292
bzr('bind', '../base')
293
self.check_revno(2, '../base')
298
self.run_bzr('bind ../base')
299
self.check_revno(1, '../base')
295
301
# Check and make sure it also works if child is ahead multiple
297
bzr('commit', '-m', 'child 3', '--unchanged')
298
bzr('commit', '-m', 'child 4', '--unchanged')
299
bzr('commit', '-m', 'child 5', '--unchanged')
302
self.run_bzr('unbind')
303
child_tree.commit(message='child 3', allow_pointless=True)
304
child_tree.commit(message='child 4', allow_pointless=True)
305
child_tree.commit(message='child 5', allow_pointless=True)
300
306
self.check_revno(5)
302
self.check_revno(2, '../base')
303
bzr('bind', '../base')
304
self.check_revno(5, '../base')
308
self.check_revno(1, '../base')
309
self.run_bzr('bind ../base')
310
self.check_revno(1, '../base')
312
def test_bind_fail_if_missing(self):
313
"""We should not be able to bind to a missing branch."""
314
tree = self.make_branch_and_tree('tree_1')
315
tree.commit('dummy commit')
316
self.run_bzr_error(['Not a branch.*no-such-branch/'], ['bind', '../no-such-branch'],
317
working_dir='tree_1')
318
self.assertIs(None, tree.branch.get_bound_location())
306
320
def test_commit_after_merge(self):
308
self.create_branches()
321
base_tree, child_tree = self.create_branches()
310
323
# We want merge to be able to be a local only
311
324
# operation, because it can be without violating
312
325
# the binding invariants.
313
326
# But we can't fail afterwards
315
bzr('branch', 'child', 'other')
318
open('c', 'wb').write('file c\n')
320
bzr('commit', '-m', 'adding c')
321
new_rev_id = bzr('revision-history')[0].strip().split('\n')[-1]
324
bzr('merge', '../other')
326
self.failUnlessExists('c')
327
tree = WorkingTree.open('.') # opens child
328
self.assertEqual([new_rev_id], tree.get_parent_ids()[1:])
327
other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
328
other_branch = other_tree.branch
330
self.build_tree_contents([('other/c', 'file c\n')])
332
other_tree.commit(message='adding c')
333
new_rev_id = other_branch.revision_history()[-1]
335
child_tree.merge_from_branch(other_branch)
337
self.failUnlessExists('child/c')
338
self.assertEqual([new_rev_id], child_tree.get_parent_ids()[1:])
330
340
# Make sure the local branch has the installed revision
331
bzr('cat-revision', new_rev_id)
341
self.assertTrue(child_tree.branch.repository.has_revision(new_rev_id))
333
343
# And make sure that the base tree does not
335
bzr('cat-revision', new_rev_id, retcode=3)
344
self.assertFalse(base_tree.branch.repository.has_revision(new_rev_id))
337
346
# Commit should succeed, and cause merged revisions to
338
347
# be pulled into base
340
bzr('commit', '-m', 'merge other')
347
bzr('cat-revision', new_rev_id)
349
def test_pull_overwrite_fails(self):
351
self.create_branches()
353
bzr('branch', 'child', 'other')
356
open('a', 'wb').write('new contents\n')
357
bzr('commit', '-m', 'changed a')
359
open('a', 'ab').write('and then some\n')
360
bzr('commit', '-m', 'another a')
362
open('a', 'ab').write('and some more\n')
363
bzr('commit', '-m', 'yet another a')
349
self.run_bzr(['commit', '-m', 'merge other'])
353
self.check_revno(2, '../base')
355
self.assertTrue(base_tree.branch.repository.has_revision(new_rev_id))
357
def test_pull_overwrite(self):
358
# XXX: This test should be moved to branch-implemenations/test_pull
359
child_tree = self.create_branches()[1]
361
other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
363
self.build_tree_contents([('other/a', 'new contents\n')])
364
other_tree.commit(message='changed a')
365
self.check_revno(2, 'other')
366
self.build_tree_contents([
367
('other/a', 'new contents\nand then some\n')])
368
other_tree.commit(message='another a')
369
self.check_revno(3, 'other')
370
self.build_tree_contents([
371
('other/a', 'new contents\nand then some\nand some more\n')])
372
other_tree.commit('yet another a')
373
self.check_revno(4, 'other')
375
self.build_tree_contents([('child/a', 'also changed a\n')])
376
child_tree.commit(message='child modified a')
378
self.check_revno(2, 'child')
379
self.check_revno(2, 'base')
382
self.run_bzr('pull --overwrite ../other')
384
# both the local and master should have been updated.
364
385
self.check_revno(4)
367
open('a', 'wb').write('also changed a\n')
368
bzr('commit', '-m', 'child modified a')
371
self.check_revno(2, '../base')
373
# It might be possible that we want pull --overwrite to
375
# If we want it, just change this test to make sure that
376
# both base and child are updated properly
377
bzr('pull', '--overwrite', '../other', retcode=3)
379
# It should fail without changing the local revision
381
self.check_revno(2, '../base')
383
# TODO: jam 20051230 Test that commit & pull fail when the branch we
384
# are bound to is not available
386
self.check_revno(4, '../base')