316
314
def test_mismatched_bundle(self):
317
315
format = bzrdir.BzrDirMetaFormat1()
318
format.repository_format = knitrepo.RepositoryFormatKnit3()
316
format.repository_format = repository.RepositoryFormatKnit2()
319
317
serializer = BundleSerializerV08('0.8')
320
318
b = self.make_branch('.', format=format)
321
self.assertRaises(errors.IncompatibleBundleFormat, serializer.write,
319
self.assertRaises(errors.IncompatibleFormat, serializer.write,
322
320
b.repository, [], {}, StringIO())
324
322
def test_matched_bundle(self):
325
"""Don't raise IncompatibleBundleFormat for knit2 and bundle0.9"""
323
"""Don't raise IncompatibleFormat for knit2 and bundle0.9"""
326
324
format = bzrdir.BzrDirMetaFormat1()
327
format.repository_format = knitrepo.RepositoryFormatKnit3()
325
format.repository_format = repository.RepositoryFormatKnit2()
328
326
serializer = BundleSerializerV09('0.9')
329
327
b = self.make_branch('.', format=format)
330
328
serializer.write(b.repository, [], {}, StringIO())
332
330
def test_mismatched_model(self):
333
331
"""Try copying a bundle from knit2 to knit1"""
334
332
format = bzrdir.BzrDirMetaFormat1()
335
format.repository_format = knitrepo.RepositoryFormatKnit3()
333
format.repository_format = repository.RepositoryFormatKnit2()
336
334
source = self.make_branch_and_tree('source', format=format)
337
335
source.commit('one', rev_id='one-id')
338
336
source.commit('two', rev_id='two-id')
339
337
text = StringIO()
340
write_bundle(source.branch.repository, 'two-id', 'null:', text,
338
write_bundle(source.branch.repository, 'two-id', None, text,
344
342
format = bzrdir.BzrDirMetaFormat1()
345
format.repository_format = knitrepo.RepositoryFormatKnit1()
343
format.repository_format = repository.RepositoryFormatKnit1()
346
344
target = self.make_branch('target', format=format)
347
345
self.assertRaises(errors.IncompatibleRevision, install_bundle,
348
346
target.repository, read_bundle(text))
785
781
u'William Dod\xe9\n').encode('utf-8'))
788
self.tree1.add([u'with Dod\xe9'], ['withdod-id'])
789
self.tree1.commit(u'i18n commit from William Dod\xe9',
784
self.tree1.add([u'with Dod\xe9'])
785
self.tree1.commit(u'i18n commit from William Dod\xe9',
790
786
rev_id='i18n-1', committer=u'William Dod\xe9')
792
if sys.platform == 'darwin':
793
# On Mac the '\xe9' gets changed to 'e\u0301'
794
self.assertEqual([u'.bzr', u'with Dode\u0301'],
795
sorted(os.listdir(u'b1')))
796
delta = self.tree1.changes_from(self.tree1.basis_tree())
797
self.assertEqual([(u'with Dod\xe9', 'withdod-id', 'file')],
799
self.knownFailure("Mac OSX doesn't preserve unicode"
800
" combining characters.")
803
bundle = self.get_valid_bundle('null:', 'i18n-1')
789
bundle = self.get_valid_bundle(None, 'i18n-1')
806
792
f = open(u'b1/with Dod\xe9', 'wb')
891
877
self.tree1 = self.make_branch_and_tree('b1')
892
878
self.b1 = self.tree1.branch
893
879
self.tree1.commit('message', rev_id='revid1')
894
bundle = self.get_valid_bundle('null:', 'revid1')
880
bundle = self.get_valid_bundle(None, 'revid1')
895
881
tree = bundle.revision_tree(self.b1.repository, 'revid1')
896
882
self.assertEqual('revid1', tree.inventory.root.revision)
898
def test_install_revisions(self):
899
self.tree1 = self.make_branch_and_tree('b1')
900
self.b1 = self.tree1.branch
901
self.tree1.commit('message', rev_id='rev2a')
902
bundle = self.get_valid_bundle('null:', 'rev2a')
903
branch2 = self.make_branch('b2')
904
self.assertFalse(branch2.repository.has_revision('rev2a'))
905
target_revision = bundle.install_revisions(branch2.repository)
906
self.assertTrue(branch2.repository.has_revision('rev2a'))
907
self.assertEqual('rev2a', target_revision)
909
def test_bundle_empty_property(self):
910
"""Test serializing revision properties with an empty value."""
911
tree = self.make_branch_and_memory_tree('tree')
913
self.addCleanup(tree.unlock)
914
tree.add([''], ['TREE_ROOT'])
915
tree.commit('One', revprops={'one':'two', 'empty':''}, rev_id='rev1')
916
self.b1 = tree.branch
917
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
918
self.assertContainsRe(bundle_sio.getvalue(),
920
'# branch-nick: tree\n'
924
bundle = read_bundle(bundle_sio)
925
revision_info = bundle.revisions[0]
926
self.assertEqual('rev1', revision_info.revision_id)
927
rev = revision_info.as_revision()
928
self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
931
def test_bundle_empty_property_alt(self):
932
"""Test serializing revision properties with an empty value.
934
Older readers had a bug when reading an empty property.
935
They assumed that all keys ended in ': \n'. However they would write an
936
empty value as ':\n'. This tests make sure that all newer bzr versions
937
can handle th second form.
939
tree = self.make_branch_and_memory_tree('tree')
941
self.addCleanup(tree.unlock)
942
tree.add([''], ['TREE_ROOT'])
943
tree.commit('One', revprops={'one':'two', 'empty':''}, rev_id='rev1')
944
self.b1 = tree.branch
945
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
946
txt = bundle_sio.getvalue()
947
loc = txt.find('# empty: ') + len('# empty:')
948
# Create a new bundle, which strips the trailing space after empty
949
bundle_sio = StringIO(txt[:loc] + txt[loc+1:])
951
self.assertContainsRe(bundle_sio.getvalue(),
953
'# branch-nick: tree\n'
957
bundle = read_bundle(bundle_sio)
958
revision_info = bundle.revisions[0]
959
self.assertEqual('rev1', revision_info.revision_id)
960
rev = revision_info.as_revision()
961
self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
964
def test_bundle_sorted_properties(self):
965
"""For stability the writer should write properties in sorted order."""
966
tree = self.make_branch_and_memory_tree('tree')
968
self.addCleanup(tree.unlock)
970
tree.add([''], ['TREE_ROOT'])
971
tree.commit('One', rev_id='rev1',
972
revprops={'a':'4', 'b':'3', 'c':'2', 'd':'1'})
973
self.b1 = tree.branch
974
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
975
self.assertContainsRe(bundle_sio.getvalue(),
979
'# branch-nick: tree\n'
983
bundle = read_bundle(bundle_sio)
984
revision_info = bundle.revisions[0]
985
self.assertEqual('rev1', revision_info.revision_id)
986
rev = revision_info.as_revision()
987
self.assertEqual({'branch-nick':'tree', 'a':'4', 'b':'3', 'c':'2',
988
'd':'1'}, rev.properties)
990
def test_bundle_unicode_properties(self):
991
"""We should be able to round trip a non-ascii property."""
992
tree = self.make_branch_and_memory_tree('tree')
994
self.addCleanup(tree.unlock)
996
tree.add([''], ['TREE_ROOT'])
997
# Revisions themselves do not require anything about revision property
998
# keys, other than that they are a basestring, and do not contain
1000
# However, Testaments assert than they are str(), and thus should not
1002
tree.commit('One', rev_id='rev1',
1003
revprops={'omega':u'\u03a9', 'alpha':u'\u03b1'})
1004
self.b1 = tree.branch
1005
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
1006
self.assertContainsRe(bundle_sio.getvalue(),
1008
'# alpha: \xce\xb1\n'
1009
'# branch-nick: tree\n'
1010
'# omega: \xce\xa9\n'
1012
bundle = read_bundle(bundle_sio)
1013
revision_info = bundle.revisions[0]
1014
self.assertEqual('rev1', revision_info.revision_id)
1015
rev = revision_info.as_revision()
1016
self.assertEqual({'branch-nick':'tree', 'omega':u'\u03a9',
1017
'alpha':u'\u03b1'}, rev.properties)
1020
885
class V09BundleKnit2Tester(V08BundleTester):