175
174
def test_remote_branch_set_append_revisions_only(self):
176
175
# Make a format 1.9 branch, which supports append_revisions_only
177
176
branch = self.make_branch('branch', format='1.9')
177
config = branch.get_config()
178
178
branch.set_append_revisions_only(True)
179
config = branch.get_config_stack()
180
179
self.assertEqual(
181
True, config.get('append_revisions_only'))
180
'True', config.get_user_option('append_revisions_only'))
182
181
branch.set_append_revisions_only(False)
183
config = branch.get_config_stack()
184
182
self.assertEqual(
185
False, config.get('append_revisions_only'))
183
'False', config.get_user_option('append_revisions_only'))
187
185
def test_remote_branch_set_append_revisions_only_upgrade_reqd(self):
188
186
branch = self.make_branch('branch', format='knit')
187
config = branch.get_config()
189
188
self.assertRaises(
190
189
errors.UpgradeRequired, branch.set_append_revisions_only, True)
504
503
self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
507
class TestBzrDirCheckoutMetaDir(TestRemote):
509
def test__get_checkout_format(self):
510
transport = MemoryTransport()
511
client = FakeClient(transport.base)
512
reference_bzrdir_format = bzrdir.format_registry.get('default')()
513
control_name = reference_bzrdir_format.network_name()
514
client.add_expected_call(
515
'BzrDir.checkout_metadir', ('quack/', ),
516
'success', (control_name, '', ''))
517
transport.mkdir('quack')
518
transport = transport.clone('quack')
519
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
521
result = a_bzrdir.checkout_metadir()
522
# We should have got a reference control dir with default branch and
523
# repository formats.
524
self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
525
self.assertEqual(None, result._repository_format)
526
self.assertEqual(None, result._branch_format)
527
self.assertFinished(client)
529
def test_unknown_format(self):
530
transport = MemoryTransport()
531
client = FakeClient(transport.base)
532
client.add_expected_call(
533
'BzrDir.checkout_metadir', ('quack/',),
534
'success', ('dontknow', '', ''))
535
transport.mkdir('quack')
536
transport = transport.clone('quack')
537
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
539
self.assertRaises(errors.UnknownFormatError,
540
a_bzrdir.checkout_metadir)
541
self.assertFinished(client)
544
class TestBzrDirGetBranches(TestRemote):
546
def test_get_branches(self):
547
transport = MemoryTransport()
548
client = FakeClient(transport.base)
549
reference_bzrdir_format = bzrdir.format_registry.get('default')()
550
branch_name = reference_bzrdir_format.get_branch_format().network_name()
551
client.add_success_response_with_body(
553
"foo": ("branch", branch_name),
554
"": ("branch", branch_name)}), "success")
555
client.add_success_response(
556
'ok', '', 'no', 'no', 'no',
557
reference_bzrdir_format.repository_format.network_name())
558
client.add_error_response('NotStacked')
559
client.add_success_response(
560
'ok', '', 'no', 'no', 'no',
561
reference_bzrdir_format.repository_format.network_name())
562
client.add_error_response('NotStacked')
563
transport.mkdir('quack')
564
transport = transport.clone('quack')
565
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
567
result = a_bzrdir.get_branches()
568
self.assertEquals(set(["", "foo"]), set(result.keys()))
570
[('call_expecting_body', 'BzrDir.get_branches', ('quack/',)),
571
('call', 'BzrDir.find_repositoryV3', ('quack/', )),
572
('call', 'Branch.get_stacked_on_url', ('quack/', )),
573
('call', 'BzrDir.find_repositoryV3', ('quack/', )),
574
('call', 'Branch.get_stacked_on_url', ('quack/', ))],
578
506
class TestBzrDirDestroyBranch(TestRemote):
580
508
def test_destroy_default(self):
589
517
a_bzrdir.destroy_branch()
590
518
self.assertFinished(client)
520
def test_destroy_named(self):
521
transport = self.get_transport('quack')
522
referenced = self.make_branch('referenced')
523
client = FakeClient(transport.base)
524
client.add_expected_call(
525
'BzrDir.destroy_branch', ('quack/', "foo"),
527
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
529
a_bzrdir.destroy_branch("foo")
530
self.assertFinished(client)
593
533
class TestBzrDirHasWorkingTree(TestRemote):
970
909
('call', 'BzrDir.find_repositoryV2', ('quack/',)),
971
910
('call', 'BzrDir.find_repository', ('quack/',)),
972
911
('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
973
('call', 'stat', ('/quack/.bzr',)),
974
912
('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
975
913
('call', 'stat', ('/quack/.bzr/repository',)),
1004
941
[('call', 'BzrDir.find_repositoryV3', ('quack/',)),
1005
942
('call', 'BzrDir.find_repositoryV2', ('quack/',)),
1006
943
('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
1007
('call', 'stat', ('/quack/.bzr',)),
1008
944
('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
1009
945
('call', 'stat', ('/quack/.bzr/repository',)),
1457
1393
def test_backwards_compatible(self):
1458
br = self.make_branch_with_tags()
1459
br.get_config_stack().set('branch.fetch_tags', True)
1460
self.addCleanup(br.lock_read().unlock)
1394
branch = self.make_branch_with_tags()
1395
c = branch.get_config()
1396
c.set_user_option('branch.fetch_tags', 'True')
1397
self.addCleanup(branch.lock_read().unlock)
1461
1398
# Disable the heads_to_fetch verb
1462
1399
verb = 'Branch.heads_to_fetch'
1463
1400
self.disable_verb(verb)
1464
1401
self.reset_smart_call_log()
1465
result = br.heads_to_fetch()
1402
result = branch.heads_to_fetch()
1466
1403
self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
1467
1404
self.assertEqual(
1468
['Branch.last_revision_info', 'Branch.get_tags_bytes'],
1405
['Branch.last_revision_info', 'Branch.get_config_file',
1406
'Branch.get_tags_bytes'],
1469
1407
[call.call.method for call in self.hpss_calls])
1471
1409
def test_backwards_compatible_no_tags(self):
1472
br = self.make_branch_with_tags()
1473
br.get_config_stack().set('branch.fetch_tags', False)
1474
self.addCleanup(br.lock_read().unlock)
1410
branch = self.make_branch_with_tags()
1411
c = branch.get_config()
1412
c.set_user_option('branch.fetch_tags', 'False')
1413
self.addCleanup(branch.lock_read().unlock)
1475
1414
# Disable the heads_to_fetch verb
1476
1415
verb = 'Branch.heads_to_fetch'
1477
1416
self.disable_verb(verb)
1478
1417
self.reset_smart_call_log()
1479
result = br.heads_to_fetch()
1418
result = branch.heads_to_fetch()
1480
1419
self.assertEqual((set(['tip']), set()), result)
1481
1420
self.assertEqual(
1482
['Branch.last_revision_info'],
1421
['Branch.last_revision_info', 'Branch.get_config_file'],
1483
1422
[call.call.method for call in self.hpss_calls])
2070
2009
'Branch.get_config_file', ('memory:///', ),
2071
2010
'success', ('ok', ), "# line 1\n")
2072
2011
client.add_expected_call(
2073
'Branch.get_config_file', ('memory:///', ),
2074
'success', ('ok', ), "# line 1\n")
2075
client.add_expected_call(
2076
2012
'Branch.put_config_file', ('memory:///', 'branch token',
2078
2014
'success', ('ok',))
2090
2026
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2091
2027
('call', 'Branch.lock_write', ('memory:///', '', '')),
2092
2028
('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2093
('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2094
2029
('call_with_body_bytes_expecting_body', 'Branch.put_config_file',
2095
2030
('memory:///', 'branch token', 'repo token'),
2096
2031
'# line 1\nemail = The Dude <lebowski@example.com>\n'),
2441
class TestRepositoryReconcile(TestRemoteRepository):
2443
def test_reconcile(self):
2444
transport_path = 'hill'
2445
repo, client = self.setup_fake_client_and_repository(transport_path)
2446
body = ("garbage_inventories: 2\n"
2447
"inconsistent_parents: 3\n")
2448
client.add_expected_call(
2449
'Repository.lock_write', ('hill/', ''),
2450
'success', ('ok', 'a token'))
2451
client.add_success_response_with_body(body, 'ok')
2452
reconciler = repo.reconcile()
2454
[('call', 'Repository.lock_write', ('hill/', '')),
2455
('call_expecting_body', 'Repository.reconcile',
2456
('hill/', 'a token'))],
2458
self.assertEquals(2, reconciler.garbage_inventories)
2459
self.assertEquals(3, reconciler.inconsistent_parents)
2462
2376
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2464
2378
def test_text(self):
4261
4175
'Repository.unlock', ('quack/', 'token', 'False'),
4262
4176
'success', ('ok', ))
4263
4177
repo.pack(['hinta', 'hintb'])
4266
class TestRepositoryIterInventories(TestRemoteRepository):
4267
"""Test Repository.iter_inventories."""
4269
def _serialize_inv_delta(self, old_name, new_name, delta):
4270
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
4271
return "".join(serializer.delta_to_lines(old_name, new_name, delta))
4273
def test_single_empty(self):
4274
transport_path = 'quack'
4275
repo, client = self.setup_fake_client_and_repository(transport_path)
4276
fmt = bzrdir.format_registry.get('2a')().repository_format
4278
stream = [('inventory-deltas', [
4279
versionedfile.FulltextContentFactory('somerevid', None, None,
4280
self._serialize_inv_delta('null:', 'somerevid', []))])]
4281
client.add_expected_call(
4282
'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4283
'success', ('ok', ),
4284
_stream_to_byte_stream(stream, fmt))
4285
ret = list(repo.iter_inventories(["somerevid"]))
4286
self.assertLength(1, ret)
4288
self.assertEquals("somerevid", inv.revision_id)
4290
def test_empty(self):
4291
transport_path = 'quack'
4292
repo, client = self.setup_fake_client_and_repository(transport_path)
4293
ret = list(repo.iter_inventories([]))
4294
self.assertEquals(ret, [])
4296
def test_missing(self):
4297
transport_path = 'quack'
4298
repo, client = self.setup_fake_client_and_repository(transport_path)
4299
client.add_expected_call(
4300
'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4301
'success', ('ok', ), iter([]))
4302
self.assertRaises(errors.NoSuchRevision, list, repo.iter_inventories(