119
119
def test_fetch_revisions(self):
120
120
"""Test fetch-revision operation."""
121
get_transport(self.get_url()).mkdir('b1')
122
get_transport(self.get_url()).mkdir('b2')
123
121
wt = self.make_branch_and_tree('b1')
125
b2 = self.make_branch('b2')
126
file('b1/foo', 'w').write('hello')
123
self.build_tree_contents([('b1/foo', 'hello')])
127
124
wt.add(['foo'], ['foo-id'])
128
125
wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
130
mutter('start fetch')
127
b2 = self.make_branch('b2')
131
128
self.assertEqual((1, []), b2.fetch(b1))
133
130
rev = b2.repository.get_revision('revision-1')
153
150
def get_unbalanced_tree_pair(self):
154
151
"""Return two branches, a and b, with one file in a."""
155
get_transport(self.get_url()).mkdir('a')
156
152
tree_a = self.make_branch_and_tree('a')
157
file('a/b', 'wb').write('b')
153
self.build_tree_contents([('a/b', 'b')])
159
155
tree_a.commit("silly commit", rev_id='A')
161
get_transport(self.get_url()).mkdir('b')
162
157
tree_b = self.make_branch_and_tree('b')
163
158
return tree_a, tree_b
189
185
self.build_tree(['a/two'])
190
186
wt_a.add(['two'])
191
187
wt_a.commit('commit two', rev_id='2')
188
# Now make a copy of the repository.
192
189
repo_b = self.make_repository('b')
193
wt_a.bzrdir.open_repository().copy_content_into(repo_b)
194
br_b = wt_a.bzrdir.open_branch().clone(repo_b.bzrdir, revision_id='1')
190
wt_a.branch.repository.copy_content_into(repo_b)
191
# wt_a might be a lightweight checkout, so get a hold of the actual
192
# branch (because you can't do a partial clone of a lightweight
194
branch = wt_a.branch.bzrdir.open_branch()
195
# Then make a branch where the new repository is, but specify a revision
196
# ID. The new branch's history will stop at the specified revision.
197
br_b = branch.clone(repo_b.bzrdir, revision_id='1')
195
198
self.assertEqual('1', br_b.last_revision())
197
200
def test_sprout_partial(self):
205
208
wt_a.add(['two'])
206
209
wt_a.commit('commit two', rev_id='2')
207
210
repo_b = self.make_repository('b')
208
wt_a.bzrdir.open_repository().copy_content_into(repo_b)
209
br_b = wt_a.bzrdir.open_branch().sprout(repo_b.bzrdir, revision_id='1')
211
repo_a = wt_a.branch.repository
212
repo_a.copy_content_into(repo_b)
213
br_b = wt_a.branch.sprout(repo_b.bzrdir, revision_id='1')
210
214
self.assertEqual('1', br_b.last_revision())
212
216
def get_parented_branch(self):
240
244
branch_d = branch_b.clone(repo_d.bzrdir)
241
245
self.assertEqual(random_parent, branch_d.get_parent())
243
def test_copy_content_incomplete(self):
244
tree = self.make_branch_and_tree('commit_tree')
245
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
247
tree.commit('revision 1', rev_id='1')
248
source = self.make_branch_and_tree('source')
249
# this gives us an incomplete repository
250
tree.bzrdir.open_repository().copy_content_into(
251
source.branch.repository)
252
tree.commit('revision 2', rev_id='2', allow_pointless=True)
253
tree.bzrdir.open_branch().copy_content_into(source.branch)
256
247
def test_sprout_branch_nickname(self):
257
248
# test the nick name is reset always
258
249
raise TestSkipped('XXX branch sprouting is not yet tested..')
347
338
def test_branch_keeps_signatures(self):
348
339
wt = self.make_branch_and_tree('source')
349
340
wt.commit('A', allow_pointless=True, rev_id='A')
350
wt.branch.repository.sign_revision('A',
351
gpg.LoopbackGPGStrategy(None))
341
repo = wt.branch.repository
342
repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
352
343
#FIXME: clone should work to urls,
353
344
# wt.clone should work to disks.
354
345
self.build_tree(['target/'])
355
d2 = wt.bzrdir.clone('target')
356
self.assertEqual(wt.branch.repository.get_signature_text('A'),
346
d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target'))
347
self.assertEqual(repo.get_signature_text('A'),
357
348
d2.open_repository().get_signature_text('A'))
359
350
def test_nicks(self):
360
"""Branch nicknames"""
351
"""Test explicit and implicit branch nicknames.
353
Nicknames are implicitly the name of the branch's directory, unless an
354
explicit nickname is set. That is, an explicit nickname always
355
overrides the implicit one.
361
357
t = get_transport(self.get_url())
363
358
branch = self.make_branch('bzr.dev')
359
# The nick will be 'bzr.dev', because there is no explicit nick set.
364
360
self.assertEqual(branch.nick, 'bzr.dev')
361
# Move the branch to a different directory, 'bzr.ab'. Now that branch
362
# will report its nick as 'bzr.ab'.
365
363
t.move('bzr.dev', 'bzr.ab')
366
364
branch = Branch.open(self.get_url('bzr.ab'))
367
365
self.assertEqual(branch.nick, 'bzr.ab')
368
branch.nick = "Aaron's branch"
369
branch.nick = "Aaron's branch"
373
branch.control_files.controlfilename("branch.conf")
366
# Set the branch nick explicitly. This will ensure there's a branch
367
# config file in the branch.
368
branch.nick = "Aaron's branch"
369
branch.nick = "Aaron's branch"
371
controlfilename = branch.control_files.controlfilename
372
except AttributeError:
373
# remote branches don't have control_files
377
t.has(t.relpath(controlfilename("branch.conf"))))
378
# Because the nick has been set explicitly, the nick is now always
379
# "Aaron's branch", regardless of directory name.
377
380
self.assertEqual(branch.nick, "Aaron's branch")
378
381
t.move('bzr.ab', 'integration')
379
382
branch = Branch.open(self.get_url('integration'))
381
384
branch.nick = u"\u1234"
382
385
self.assertEqual(branch.nick, u"\u1234")
387
def test_commit_nicks(self):
388
"""Nicknames are committed to the revision"""
389
wt = self.make_branch_and_tree('bzr.dev')
391
branch.nick = "My happy branch"
392
wt.commit('My commit respect da nick.')
393
committed = branch.repository.get_revision(branch.last_revision())
394
self.assertEqual(committed.properties["branch-nick"],
384
397
def test_create_open_branch_uses_repository(self):
386
399
repo = self.make_repository('.', shared=True)
387
400
except errors.IncompatibleFormat:
389
repo.bzrdir.root_transport.mkdir('child')
390
child_dir = self.bzrdir_format.initialize('child')
402
child_transport = repo.bzrdir.root_transport.clone('child')
403
child_transport.mkdir('.')
404
child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
392
406
child_branch = self.branch_format.initialize(child_dir)
393
407
except errors.UninitializableFormat:
457
471
"""A lightweight checkout from a readonly branch should succeed."""
458
472
tree_a = self.make_branch_and_tree('a')
459
473
rev_id = tree_a.commit('put some content in the branch')
460
source_branch = bzrlib.branch.Branch.open(
461
'readonly+' + tree_a.bzrdir.root_transport.base)
474
# open the branch via a readonly transport
475
source_branch = bzrlib.branch.Branch.open(self.get_readonly_url('a'))
462
476
# sanity check that the test will be valid
463
477
self.assertRaises((errors.LockError, errors.TransportNotPossible),
464
478
source_branch.lock_write)
469
483
"""A regular checkout from a readonly branch should succeed."""
470
484
tree_a = self.make_branch_and_tree('a')
471
485
rev_id = tree_a.commit('put some content in the branch')
472
source_branch = bzrlib.branch.Branch.open(
473
'readonly+' + tree_a.bzrdir.root_transport.base)
486
# open the branch via a readonly transport
487
source_branch = bzrlib.branch.Branch.open(self.get_readonly_url('a'))
474
488
# sanity check that the test will be valid
475
489
self.assertRaises((errors.LockError, errors.TransportNotPossible),
476
490
source_branch.lock_write)
477
491
checkout = source_branch.create_checkout('c')
478
492
self.assertEqual(rev_id, checkout.last_revision())
494
def test_set_revision_history(self):
495
tree = self.make_branch_and_tree('a')
496
tree.commit('a commit', rev_id='rev1')
498
br.set_revision_history(["rev1"])
499
self.assertEquals(br.revision_history(), ["rev1"])
500
br.set_revision_history([])
501
self.assertEquals(br.revision_history(), [])
481
504
class ChrootedTests(TestCaseWithBranch):
482
505
"""A support class that provides readonly urls outside the local namespace.