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')
64
self.run_bzr('bind ../base')
60
self.run_bzr('bind ../base', working_dir='child')
62
d = bzrdir.BzrDir.open('child')
67
63
self.assertNotEqual(None, d.open_branch().get_master_branch())
69
self.run_bzr('unbind')
65
self.run_bzr('unbind', working_dir='child')
70
66
self.assertEqual(None, d.open_branch().get_master_branch())
72
self.run_bzr('unbind', retcode=3)
68
self.run_bzr('unbind', retcode=3, working_dir='child')
74
70
def test_bind_branch6(self):
75
71
branch1 = self.make_branch('branch1', format='dirstate-tags')
77
error = self.run_bzr('bind', retcode=3)[1]
78
self.assertContainsRe(error, 'no previous location known')
72
error = self.run_bzr('bind', retcode=3, working_dir='branch1')[1]
74
error, 'No location supplied and no previous location known\n')
80
76
def setup_rebind(self, format):
81
77
branch1 = self.make_branch('branch1')
86
82
def test_rebind_branch6(self):
87
83
self.setup_rebind('dirstate-tags')
91
self.assertContainsRe(b.get_bound_location(), '\/branch1\/$')
84
self.run_bzr('bind', working_dir='branch2')
85
b = branch.Branch.open('branch2')
86
self.assertEndsWith(b.get_bound_location(), '/branch1/')
93
88
def test_rebind_branch5(self):
94
89
self.setup_rebind('knit')
96
error = self.run_bzr('bind', retcode=3)[1]
97
self.assertContainsRe(error, 'old locations')
90
error = self.run_bzr('bind', retcode=3, working_dir='branch2')[1]
92
error, 'No location supplied. This format does not remember'
99
95
def test_bound_commit(self):
100
96
child_tree = self.create_branches()[1]
152
147
self.check_revno(2, 'base')
154
149
self.check_revno(1, 'child')
156
self.run_bzr("commit -m child", retcode=3)
158
self.run_bzr('unbind')
150
self.run_bzr("commit -m child", retcode=3, working_dir='child')
151
self.check_revno(1, 'child')
152
self.run_bzr('unbind', working_dir='child')
159
153
child_tree.commit(message='child')
154
self.check_revno(2, 'child')
162
156
def test_commit_remote_bound(self):
163
157
# It is not possible to commit to a branch
165
159
base_tree, child_tree = self.create_branches()
166
160
base_tree.bzrdir.sprout('newbase')
169
162
# There is no way to know that B has already
170
163
# been bound by someone else, otherwise it
171
164
# might be nice if this would fail
172
self.run_bzr('bind ../newbase')
165
self.run_bzr('bind ../newbase', working_dir='base')
175
self.run_bzr('commit -m failure --unchanged', retcode=3)
167
self.run_bzr('commit -m failure --unchanged', retcode=3,
177
170
def test_pull_updates_both(self):
178
171
base_tree = self.create_branches()[0]
181
174
newchild_tree.commit(message='newchild')
182
175
self.check_revno(2, 'newchild')
185
177
# The pull should succeed, and update
186
178
# the bound parent branch
187
self.run_bzr('pull ../newchild')
190
self.check_revno(2, '../base')
179
self.run_bzr('pull ../newchild', working_dir='child')
180
self.check_revno(2, 'child')
181
self.check_revno(2, 'base')
192
183
def test_pull_local_updates_local(self):
193
184
base_tree = self.create_branches()[0]
196
187
newchild_tree.commit(message='newchild')
197
188
self.check_revno(2, 'newchild')
200
190
# The pull should succeed, and update
201
191
# the bound parent branch
202
self.run_bzr('pull ../newchild --local')
205
self.check_revno(1, '../base')
192
self.run_bzr('pull ../newchild --local', working_dir='child')
193
self.check_revno(2, 'child')
194
self.check_revno(1, 'base')
207
196
def test_bind_diverged(self):
208
197
base_tree, child_tree = self.create_branches()
209
198
base_branch = base_tree.branch
210
199
child_branch = child_tree.branch
213
self.run_bzr('unbind')
201
self.run_bzr('unbind', working_dir='child')
215
203
child_tree.commit(message='child', allow_pointless=True)
204
self.check_revno(2, 'child')
219
206
self.check_revno(1, 'base')
220
207
base_tree.commit(message='base', allow_pointless=True)
221
208
self.check_revno(2, 'base')
224
210
# These branches have diverged, but bind should succeed anyway
225
self.run_bzr('bind ../base')
211
self.run_bzr('bind ../base', working_dir='child')
227
213
# This should turn the local commit into a merge
228
214
child_tree.update()
229
215
child_tree.commit(message='merged')
233
child_tree.branch.last_revision(),
234
base_tree.branch.last_revision())
216
self.check_revno(3, 'child')
217
self.assertEquals(child_tree.branch.last_revision(),
218
base_tree.branch.last_revision())
236
220
def test_bind_parent_ahead(self):
237
221
base_tree = self.create_branches()[0]
240
self.run_bzr('unbind')
223
self.run_bzr('unbind', working_dir='child')
242
225
base_tree.commit(message='base', allow_pointless=True)
245
self.run_bzr('bind ../base')
227
self.check_revno(1, 'child')
228
self.run_bzr('bind ../base', working_dir='child')
247
230
# binding does not pull data:
249
self.run_bzr('unbind')
231
self.check_revno(1, 'child')
232
self.run_bzr('unbind', working_dir='child')
251
234
# Check and make sure it also works if parent is ahead multiple
252
235
base_tree.commit(message='base 3', allow_pointless=True)
253
236
base_tree.commit(message='base 4', allow_pointless=True)
254
237
base_tree.commit(message='base 5', allow_pointless=True)
255
self.check_revno(5, '../base')
238
self.check_revno(5, 'base')
258
self.run_bzr('bind ../base')
240
self.check_revno(1, 'child')
241
self.run_bzr('bind ../base', working_dir='child')
242
self.check_revno(1, 'child')
261
244
def test_bind_child_ahead(self):
262
245
# test binding when the master branches history is a prefix of the
265
248
child_tree = self.create_branches()[1]
268
self.run_bzr('unbind')
250
self.run_bzr('unbind', working_dir='child')
269
251
child_tree.commit(message='child', allow_pointless=True)
271
self.check_revno(1, '../base')
252
self.check_revno(2, 'child')
253
self.check_revno(1, 'base')
273
self.run_bzr('bind ../base')
274
self.check_revno(1, '../base')
255
self.run_bzr('bind ../base', working_dir='child')
256
self.check_revno(1, 'base')
276
258
# Check and make sure it also works if child is ahead multiple
277
self.run_bzr('unbind')
259
self.run_bzr('unbind', working_dir='child')
278
260
child_tree.commit(message='child 3', allow_pointless=True)
279
261
child_tree.commit(message='child 4', allow_pointless=True)
280
262
child_tree.commit(message='child 5', allow_pointless=True)
263
self.check_revno(5, 'child')
283
self.check_revno(1, '../base')
284
self.run_bzr('bind ../base')
285
self.check_revno(1, '../base')
265
self.check_revno(1, 'base')
266
self.run_bzr('bind ../base', working_dir='child')
267
self.check_revno(1, 'base')
287
269
def test_bind_fail_if_missing(self):
288
270
"""We should not be able to bind to a missing branch."""
289
271
tree = self.make_branch_and_tree('tree_1')
290
272
tree.commit('dummy commit')
291
self.run_bzr_error(['Not a branch.*no-such-branch/'], ['bind', '../no-such-branch'],
292
working_dir='tree_1')
273
self.run_bzr_error(['Not a branch.*no-such-branch/'],
274
['bind', '../no-such-branch'],
275
working_dir='tree_1')
293
276
self.assertIs(None, tree.branch.get_bound_location())
295
def test_bind_nick(self):
296
"""Bind should not update implicit nick."""
297
base = self.make_branch_and_tree('base')
298
child = self.make_branch_and_tree('child')
300
self.assertEqual(child.branch.nick, 'child')
301
self.assertEqual(child.branch.get_config().has_explicit_nickname(),
303
self.run_bzr('bind ../base')
304
self.assertEqual(child.branch.nick, base.branch.nick)
305
self.assertEqual(child.branch.get_config().has_explicit_nickname(),
308
def test_bind_explicit_nick(self):
309
"""Bind should update explicit nick."""
310
base = self.make_branch_and_tree('base')
311
child = self.make_branch_and_tree('child')
313
child.branch.nick = "explicit_nick"
314
self.assertEqual(child.branch.nick, "explicit_nick")
315
self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
317
self.run_bzr('bind ../base')
318
self.assertEqual(child.branch.nick, base.branch.nick)
319
self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
322
278
def test_commit_after_merge(self):
323
279
base_tree, child_tree = self.create_branches()
348
304
# Commit should succeed, and cause merged revisions to
349
305
# be pulled into base
351
self.run_bzr(['commit', '-m', 'merge other'])
355
self.check_revno(2, '../base')
306
self.run_bzr(['commit', '-m', 'merge other'], working_dir='child')
307
self.check_revno(2, 'child')
308
self.check_revno(2, 'base')
357
309
self.assertTrue(base_tree.branch.repository.has_revision(new_rev_id))
359
311
def test_pull_overwrite(self):
380
332
self.check_revno(2, 'child')
381
333
self.check_revno(2, 'base')
384
self.run_bzr('pull --overwrite ../other')
335
self.run_bzr('pull --overwrite ../other', working_dir='child')
386
337
# both the local and master should have been updated.
388
self.check_revno(4, '../base')
338
self.check_revno(4, 'child')
339
self.check_revno(4, 'base')
390
341
def test_bind_directory(self):
391
342
"""Test --directory option"""