~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import sys
20
20
import tempfile
21
21
 
22
 
from bzrlib import inventory, treebuilder
 
22
from bzrlib import (
 
23
    bzrdir, 
 
24
    errors, 
 
25
    inventory, 
 
26
    repository, 
 
27
    treebuilder,
 
28
    )
23
29
from bzrlib.builtins import merge
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
38
from bzrlib.errors import (BzrError, TestamentMismatch, NotABundle, BadBundle, 
301
309
            [inventory.ROOT_ID, 'a', 'b', 'd', 'e'])
302
310
 
303
311
 
304
 
class BundleTester(TestCaseWithTransport):
 
312
class BundleTester1(TestCaseWithTransport):
 
313
 
 
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())
 
321
 
 
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())
 
329
 
 
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')
 
337
        text = StringIO()
 
338
        write_bundle(source.branch.repository, 'two-id', None, text, 
 
339
                     format='0.9')
 
340
        text.seek(0)
 
341
 
 
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))
 
347
 
 
348
 
 
349
class V08BundleTester(TestCaseWithTransport):
 
350
 
 
351
    format = '0.8'
 
352
 
 
353
    def bzrdir_format(self):
 
354
        format = bzrdir.BzrDirMetaFormat1()
 
355
        format.repository_format = repository.RepositoryFormatKnit1()
 
356
        return format
 
357
 
 
358
    def make_branch_and_tree(self, path, format=None):
 
359
        if format is None:
 
360
            format = self.bzrdir_format()
 
361
        return TestCaseWithTransport.make_branch_and_tree(self, path, format)
 
362
 
 
363
    def make_branch(self, path, format=None):
 
364
        if format is None:
 
365
            format = self.bzrdir_format()
 
366
        return TestCaseWithTransport.make_branch(self, path, format)
305
367
 
306
368
    def create_bundle_text(self, base_rev_id, rev_id):
307
369
        bundle_txt = StringIO()
308
370
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id, 
309
 
                               bundle_txt)
 
371
                               bundle_txt, format=self.format)
310
372
        bundle_txt.seek(0)
311
373
        self.assertEqual(bundle_txt.readline(), 
312
 
                         '# Bazaar revision bundle v0.8\n')
 
374
                         '# Bazaar revision bundle v%s\n' % self.format)
313
375
        self.assertEqual(bundle_txt.readline(), '#\n')
314
376
 
315
377
        rev = self.b1.repository.get_revision(rev_id)
391
453
        else:
392
454
            if not os.path.exists(checkout_dir):
393
455
                os.mkdir(checkout_dir)
394
 
        tree = BzrDir.create_standalone_workingtree(checkout_dir)
 
456
        tree = self.make_branch_and_tree(checkout_dir)
395
457
        s = StringIO()
396
 
        ancestors = write_bundle(self.b1.repository, rev_id, None, s)
 
458
        ancestors = write_bundle(self.b1.repository, rev_id, None, s,
 
459
                                 format=self.format)
397
460
        s.seek(0)
398
461
        assert isinstance(s.getvalue(), str), (
399
462
            "Bundle isn't a bytestring:\n %s..." % repr(s.getvalue())[:40])
571
634
                          verbose=False)
572
635
        bundle = self.get_valid_bundle('a@cset-0-5', 'a@cset-0-6')
573
636
        other = self.get_checkout('a@cset-0-5')
 
637
        tree1_inv = self.tree1.branch.repository.get_inventory_xml(
 
638
            'a@cset-0-5')
 
639
        tree2_inv = other.branch.repository.get_inventory_xml('a@cset-0-5')
 
640
        self.assertEqualDiff(tree1_inv, tree2_inv)
574
641
        other.rename_one('sub/dir/nolastnewline.txt', 'sub/nolastnewline.txt')
575
642
        other.commit('rename file', rev_id='a@cset-0-6b')
576
643
        merge([other.basedir, -1], [None, None], this_dir=self.tree1.basedir)
581
648
    def test_symlink_bundle(self):
582
649
        if not has_symlinks():
583
650
            raise TestSkipped("No symlink support")
584
 
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
 
651
        self.tree1 = self.make_branch_and_tree('b1')
585
652
        self.b1 = self.tree1.branch
586
653
        tt = TreeTransform(self.tree1)
587
654
        tt.new_symlink('link', tt.root, 'bar/foo', 'link-1')
611
678
        self.get_valid_bundle('l@cset-0-3', 'l@cset-0-4')
612
679
 
613
680
    def test_binary_bundle(self):
614
 
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
 
681
        self.tree1 = self.make_branch_and_tree('b1')
615
682
        self.b1 = self.tree1.branch
616
683
        tt = TreeTransform(self.tree1)
617
684
        
653
720
        self.get_valid_bundle(None, 'b@cset-0-4')
654
721
 
655
722
    def test_last_modified(self):
656
 
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
 
723
        self.tree1 = self.make_branch_and_tree('b1')
657
724
        self.b1 = self.tree1.branch
658
725
        tt = TreeTransform(self.tree1)
659
726
        tt.new_file('file', tt.root, 'file', 'file')
681
748
        bundle = self.get_valid_bundle('a@lmod-0-2a', 'a@lmod-0-4')
682
749
 
683
750
    def test_hide_history(self):
684
 
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
 
751
        self.tree1 = self.make_branch_and_tree('b1')
685
752
        self.b1 = self.tree1.branch
686
753
 
687
754
        open('b1/one', 'wb').write('one\n')
693
760
        self.tree1.commit('modify', rev_id='a@cset-0-3')
694
761
        bundle_file = StringIO()
695
762
        rev_ids = write_bundle(self.tree1.branch.repository, 'a@cset-0-3',
696
 
                               'a@cset-0-1', bundle_file)
 
763
                               'a@cset-0-1', bundle_file, format=self.format)
697
764
        self.assertNotContainsRe(bundle_file.getvalue(), 'two')
698
765
        self.assertContainsRe(bundle_file.getvalue(), 'one')
699
766
        self.assertContainsRe(bundle_file.getvalue(), 'three')
815
882
        self.assertEqual('revid1', tree.inventory.root.revision)
816
883
 
817
884
 
 
885
class V09BundleKnit2Tester(V08BundleTester):
 
886
 
 
887
    format = '0.9'
 
888
 
 
889
    def bzrdir_format(self):
 
890
        format = bzrdir.BzrDirMetaFormat1()
 
891
        format.repository_format = repository.RepositoryFormatKnit2()
 
892
        return format
 
893
 
 
894
 
 
895
class V09BundleKnit1Tester(V08BundleTester):
 
896
 
 
897
    format = '0.9'
 
898
 
 
899
    def bzrdir_format(self):
 
900
        format = bzrdir.BzrDirMetaFormat1()
 
901
        format.repository_format = repository.RepositoryFormatKnit1()
 
902
        return format
 
903
 
 
904
 
818
905
class MungedBundleTester(TestCaseWithTransport):
819
906
 
820
907
    def build_test_bundle(self):