314
315
def test_mismatched_bundle(self):
315
316
format = bzrdir.BzrDirMetaFormat1()
316
format.repository_format = repository.RepositoryFormatKnit2()
317
format.repository_format = knitrepo.RepositoryFormatKnit3()
317
318
serializer = BundleSerializerV08('0.8')
318
319
b = self.make_branch('.', format=format)
319
self.assertRaises(errors.IncompatibleFormat, serializer.write,
320
self.assertRaises(errors.IncompatibleBundleFormat, serializer.write,
320
321
b.repository, [], {}, StringIO())
322
323
def test_matched_bundle(self):
323
"""Don't raise IncompatibleFormat for knit2 and bundle0.9"""
324
"""Don't raise IncompatibleBundleFormat for knit2 and bundle0.9"""
324
325
format = bzrdir.BzrDirMetaFormat1()
325
format.repository_format = repository.RepositoryFormatKnit2()
326
format.repository_format = knitrepo.RepositoryFormatKnit3()
326
327
serializer = BundleSerializerV09('0.9')
327
328
b = self.make_branch('.', format=format)
328
329
serializer.write(b.repository, [], {}, StringIO())
781
784
u'William Dod\xe9\n').encode('utf-8'))
784
self.tree1.add([u'with Dod\xe9'])
785
self.tree1.commit(u'i18n commit from William Dod\xe9',
787
self.tree1.add([u'with Dod\xe9'], ['withdod-id'])
788
self.tree1.commit(u'i18n commit from William Dod\xe9',
786
789
rev_id='i18n-1', committer=u'William Dod\xe9')
791
if sys.platform == 'darwin':
792
# On Mac the '\xe9' gets changed to 'e\u0301'
793
self.assertEqual([u'.bzr', u'with Dode\u0301'],
794
sorted(os.listdir(u'b1')))
795
delta = self.tree1.changes_from(self.tree1.basis_tree())
796
self.assertEqual([(u'with Dod\xe9', 'withdod-id', 'file')],
798
self.knownFailure("Mac OSX doesn't preserve unicode"
799
" combining characters.")
789
802
bundle = self.get_valid_bundle(None, 'i18n-1')
881
894
tree = bundle.revision_tree(self.b1.repository, 'revid1')
882
895
self.assertEqual('revid1', tree.inventory.root.revision)
897
def test_install_revisions(self):
898
self.tree1 = self.make_branch_and_tree('b1')
899
self.b1 = self.tree1.branch
900
self.tree1.commit('message', rev_id='rev2a')
901
bundle = self.get_valid_bundle(None, 'rev2a')
902
branch2 = self.make_branch('b2')
903
self.assertFalse(branch2.repository.has_revision('rev2a'))
904
target_revision = bundle.install_revisions(branch2.repository)
905
self.assertTrue(branch2.repository.has_revision('rev2a'))
906
self.assertEqual('rev2a', target_revision)
908
def test_bundle_empty_property(self):
909
"""Test serializing revision properties with an empty value."""
910
tree = self.make_branch_and_memory_tree('tree')
912
self.addCleanup(tree.unlock)
913
tree.add([''], ['TREE_ROOT'])
914
tree.commit('One', revprops={'one':'two', 'empty':''}, rev_id='rev1')
915
self.b1 = tree.branch
916
bundle_sio, revision_ids = self.create_bundle_text(None, 'rev1')
917
self.assertContainsRe(bundle_sio.getvalue(),
919
'# branch-nick: tree\n'
923
bundle = read_bundle(bundle_sio)
924
revision_info = bundle.revisions[0]
925
self.assertEqual('rev1', revision_info.revision_id)
926
rev = revision_info.as_revision()
927
self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
930
def test_bundle_empty_property_alt(self):
931
"""Test serializing revision properties with an empty value.
933
Older readers had a bug when reading an empty property.
934
They assumed that all keys ended in ': \n'. However they would write an
935
empty value as ':\n'. This tests make sure that all newer bzr versions
936
can handle th second form.
938
tree = self.make_branch_and_memory_tree('tree')
940
self.addCleanup(tree.unlock)
941
tree.add([''], ['TREE_ROOT'])
942
tree.commit('One', revprops={'one':'two', 'empty':''}, rev_id='rev1')
943
self.b1 = tree.branch
944
bundle_sio, revision_ids = self.create_bundle_text(None, 'rev1')
945
txt = bundle_sio.getvalue()
946
loc = txt.find('# empty: ') + len('# empty:')
947
# Create a new bundle, which strips the trailing space after empty
948
bundle_sio = StringIO(txt[:loc] + txt[loc+1:])
950
self.assertContainsRe(bundle_sio.getvalue(),
952
'# branch-nick: tree\n'
956
bundle = read_bundle(bundle_sio)
957
revision_info = bundle.revisions[0]
958
self.assertEqual('rev1', revision_info.revision_id)
959
rev = revision_info.as_revision()
960
self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
963
def test_bundle_sorted_properties(self):
964
"""For stability the writer should write properties in sorted order."""
965
tree = self.make_branch_and_memory_tree('tree')
967
self.addCleanup(tree.unlock)
969
tree.add([''], ['TREE_ROOT'])
970
tree.commit('One', rev_id='rev1',
971
revprops={'a':'4', 'b':'3', 'c':'2', 'd':'1'})
972
self.b1 = tree.branch
973
bundle_sio, revision_ids = self.create_bundle_text(None, 'rev1')
974
self.assertContainsRe(bundle_sio.getvalue(),
978
'# branch-nick: tree\n'
982
bundle = read_bundle(bundle_sio)
983
revision_info = bundle.revisions[0]
984
self.assertEqual('rev1', revision_info.revision_id)
985
rev = revision_info.as_revision()
986
self.assertEqual({'branch-nick':'tree', 'a':'4', 'b':'3', 'c':'2',
987
'd':'1'}, rev.properties)
989
def test_bundle_unicode_properties(self):
990
"""We should be able to round trip a non-ascii property."""
991
tree = self.make_branch_and_memory_tree('tree')
993
self.addCleanup(tree.unlock)
995
tree.add([''], ['TREE_ROOT'])
996
# Revisions themselves do not require anything about revision property
997
# keys, other than that they are a basestring, and do not contain
999
# However, Testaments assert than they are str(), and thus should not
1001
tree.commit('One', rev_id='rev1',
1002
revprops={'omega':u'\u03a9', 'alpha':u'\u03b1'})
1003
self.b1 = tree.branch
1004
bundle_sio, revision_ids = self.create_bundle_text(None, 'rev1')
1005
self.assertContainsRe(bundle_sio.getvalue(),
1007
'# alpha: \xce\xb1\n'
1008
'# branch-nick: tree\n'
1009
'# omega: \xce\xa9\n'
1011
bundle = read_bundle(bundle_sio)
1012
revision_info = bundle.revisions[0]
1013
self.assertEqual('rev1', revision_info.revision_id)
1014
rev = revision_info.as_revision()
1015
self.assertEqual({'branch-nick':'tree', 'omega':u'\u03a9',
1016
'alpha':u'\u03b1'}, rev.properties)
885
1019
class V09BundleKnit2Tester(V08BundleTester):