22
from bzrlib import inventory
23
from bzrlib.builtins import merge
29
from bzrlib.builtins import _merge_helper
24
30
from bzrlib.bzrdir import BzrDir
25
31
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
26
32
from bzrlib.bundle.bundle_data import BundleTree
27
33
from bzrlib.bundle.serializer import write_bundle, read_bundle
34
from bzrlib.bundle.serializer.v08 import BundleSerializerV08
35
from bzrlib.bundle.serializer.v09 import BundleSerializerV09
28
36
from bzrlib.branch import Branch
29
37
from bzrlib.diff import internal_diff
30
from bzrlib.errors import BzrError, TestamentMismatch, NotABundle, BadBundle
38
from bzrlib.errors import (BzrError, TestamentMismatch, NotABundle, BadBundle,
31
40
from bzrlib.merge import Merge3Merger
32
41
from bzrlib.osutils import has_symlinks, sha_file
33
42
from bzrlib.tests import (TestCaseInTempDir, TestCaseWithTransport,
300
309
[inventory.ROOT_ID, 'a', 'b', 'd', 'e'])
303
class BundleTester(TestCaseWithTransport):
312
class BundleTester1(TestCaseWithTransport):
314
def test_mismatched_bundle(self):
315
format = bzrdir.BzrDirMetaFormat1()
316
format.repository_format = repository.RepositoryFormatKnit2()
317
serializer = BundleSerializerV08('0.8')
318
b = self.make_branch('.', format=format)
319
self.assertRaises(errors.IncompatibleFormat, serializer.write,
320
b.repository, [], {}, StringIO())
322
def test_matched_bundle(self):
323
"""Don't raise IncompatibleFormat for knit2 and bundle0.9"""
324
format = bzrdir.BzrDirMetaFormat1()
325
format.repository_format = repository.RepositoryFormatKnit2()
326
serializer = BundleSerializerV09('0.9')
327
b = self.make_branch('.', format=format)
328
serializer.write(b.repository, [], {}, StringIO())
330
def test_mismatched_model(self):
331
"""Try copying a bundle from knit2 to knit1"""
332
format = bzrdir.BzrDirMetaFormat1()
333
format.repository_format = repository.RepositoryFormatKnit2()
334
source = self.make_branch_and_tree('source', format=format)
335
source.commit('one', rev_id='one-id')
336
source.commit('two', rev_id='two-id')
338
write_bundle(source.branch.repository, 'two-id', None, text,
342
format = bzrdir.BzrDirMetaFormat1()
343
format.repository_format = repository.RepositoryFormatKnit1()
344
target = self.make_branch('target', format=format)
345
self.assertRaises(errors.IncompatibleRevision, install_bundle,
346
target.repository, read_bundle(text))
349
class V08BundleTester(TestCaseWithTransport):
353
def bzrdir_format(self):
354
format = bzrdir.BzrDirMetaFormat1()
355
format.repository_format = repository.RepositoryFormatKnit1()
358
def make_branch_and_tree(self, path, format=None):
360
format = self.bzrdir_format()
361
return TestCaseWithTransport.make_branch_and_tree(self, path, format)
363
def make_branch(self, path, format=None):
365
format = self.bzrdir_format()
366
return TestCaseWithTransport.make_branch(self, path, format)
305
368
def create_bundle_text(self, base_rev_id, rev_id):
306
369
bundle_txt = StringIO()
307
370
rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
371
bundle_txt, format=self.format)
309
372
bundle_txt.seek(0)
310
373
self.assertEqual(bundle_txt.readline(),
311
'# Bazaar revision bundle v0.8\n')
374
'# Bazaar revision bundle v%s\n' % self.format)
312
375
self.assertEqual(bundle_txt.readline(), '#\n')
314
377
rev = self.b1.repository.get_revision(rev_id)
391
454
if not os.path.exists(checkout_dir):
392
455
os.mkdir(checkout_dir)
393
tree = BzrDir.create_standalone_workingtree(checkout_dir)
456
tree = self.make_branch_and_tree(checkout_dir)
395
ancestors = write_bundle(self.b1.repository, rev_id, None, s)
458
ancestors = write_bundle(self.b1.repository, rev_id, None, s,
397
461
assert isinstance(s.getvalue(), str), (
398
462
"Bundle isn't a bytestring:\n %s..." % repr(s.getvalue())[:40])
569
635
bundle = self.get_valid_bundle('a@cset-0-5', 'a@cset-0-6')
570
636
other = self.get_checkout('a@cset-0-5')
637
tree1_inv = self.tree1.branch.repository.get_inventory_xml(
639
tree2_inv = other.branch.repository.get_inventory_xml('a@cset-0-5')
640
self.assertEqualDiff(tree1_inv, tree2_inv)
571
641
other.rename_one('sub/dir/nolastnewline.txt', 'sub/nolastnewline.txt')
572
642
other.commit('rename file', rev_id='a@cset-0-6b')
573
merge([other.basedir, -1], [None, None], this_dir=self.tree1.basedir)
643
_merge_helper([other.basedir, -1], [None, None],
644
this_dir=self.tree1.basedir)
574
645
self.tree1.commit(u'Merge', rev_id='a@cset-0-7',
576
647
bundle = self.get_valid_bundle('a@cset-0-6', 'a@cset-0-7')
671
742
tt.create_file('file2', trans_id)
673
744
other.commit('modify text in another tree', rev_id='a@lmod-0-2b')
674
merge([other.basedir, -1], [None, None], this_dir=self.tree1.basedir)
745
_merge_helper([other.basedir, -1], [None, None],
746
this_dir=self.tree1.basedir)
675
747
self.tree1.commit(u'Merge', rev_id='a@lmod-0-3',
677
749
self.tree1.commit(u'Merge', rev_id='a@lmod-0-4')
678
750
bundle = self.get_valid_bundle('a@lmod-0-2a', 'a@lmod-0-4')
680
752
def test_hide_history(self):
681
self.tree1 = BzrDir.create_standalone_workingtree('b1')
753
self.tree1 = self.make_branch_and_tree('b1')
682
754
self.b1 = self.tree1.branch
684
756
open('b1/one', 'wb').write('one\n')
690
762
self.tree1.commit('modify', rev_id='a@cset-0-3')
691
763
bundle_file = StringIO()
692
764
rev_ids = write_bundle(self.tree1.branch.repository, 'a@cset-0-3',
693
'a@cset-0-1', bundle_file)
765
'a@cset-0-1', bundle_file, format=self.format)
694
766
self.assertNotContainsRe(bundle_file.getvalue(), 'two')
695
767
self.assertContainsRe(bundle_file.getvalue(), 'one')
696
768
self.assertContainsRe(bundle_file.getvalue(), 'three')
782
854
bundle = self.get_valid_bundle(None, 'white-4')
784
856
def test_alt_timezone_bundle(self):
785
self.tree1 = self.make_branch_and_tree('b1')
857
self.tree1 = self.make_branch_and_memory_tree('b1')
786
858
self.b1 = self.tree1.branch
859
builder = treebuilder.TreeBuilder()
788
self.build_tree(['b1/newfile'])
789
self.tree1.add(['newfile'])
861
self.tree1.lock_write()
862
builder.start_tree(self.tree1)
863
builder.build(['newfile'])
864
builder.finish_tree()
791
866
# Asia/Colombo offset = 5 hours 30 minutes
792
867
self.tree1.commit('non-hour offset timezone', rev_id='tz-1',
798
873
self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
799
874
self.assertEqual(19800, rev.timezone)
800
875
self.assertEqual(1152544886.0, rev.timestamp)
878
def test_bundle_root_id(self):
879
self.tree1 = self.make_branch_and_tree('b1')
880
self.b1 = self.tree1.branch
881
self.tree1.commit('message', rev_id='revid1')
882
bundle = self.get_valid_bundle(None, 'revid1')
883
tree = bundle.revision_tree(self.b1.repository, 'revid1')
884
self.assertEqual('revid1', tree.inventory.root.revision)
887
class V09BundleKnit2Tester(V08BundleTester):
891
def bzrdir_format(self):
892
format = bzrdir.BzrDirMetaFormat1()
893
format.repository_format = repository.RepositoryFormatKnit2()
897
class V09BundleKnit1Tester(V08BundleTester):
901
def bzrdir_format(self):
902
format = bzrdir.BzrDirMetaFormat1()
903
format.repository_format = repository.RepositoryFormatKnit1()
803
907
class MungedBundleTester(TestCaseWithTransport):