~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-25 18:42:17 UTC
  • mfrom: (2039.1.2 progress-cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20060925184217-fd144de117df49c3
cleanup progress properly when interrupted during fetch (#54000)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2004-2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
import sys
20
20
import tempfile
21
21
 
22
 
from bzrlib import (
23
 
    bzrdir,
24
 
    errors,
25
 
    inventory,
26
 
    repository,
27
 
    treebuilder,
28
 
    )
29
 
from bzrlib.builtins import _merge_helper
 
22
from bzrlib import inventory, treebuilder
 
23
from bzrlib.builtins import merge
30
24
from bzrlib.bzrdir import BzrDir
31
25
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
32
26
from bzrlib.bundle.bundle_data import BundleTree
33
27
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
36
28
from bzrlib.branch import Branch
37
29
from bzrlib.diff import internal_diff
38
30
from bzrlib.errors import (BzrError, TestamentMismatch, NotABundle, BadBundle, 
39
31
                           NoSuchFile,)
40
32
from bzrlib.merge import Merge3Merger
41
 
from bzrlib.repofmt import knitrepo
42
33
from bzrlib.osutils import has_symlinks, sha_file
43
34
from bzrlib.tests import (TestCaseInTempDir, TestCaseWithTransport,
44
35
                          TestCase, TestSkipped)
310
301
            [inventory.ROOT_ID, 'a', 'b', 'd', 'e'])
311
302
 
312
303
 
313
 
class BundleTester1(TestCaseWithTransport):
314
 
 
315
 
    def test_mismatched_bundle(self):
316
 
        format = bzrdir.BzrDirMetaFormat1()
317
 
        format.repository_format = knitrepo.RepositoryFormatKnit2()
318
 
        serializer = BundleSerializerV08('0.8')
319
 
        b = self.make_branch('.', format=format)
320
 
        self.assertRaises(errors.IncompatibleBundleFormat, serializer.write, 
321
 
                          b.repository, [], {}, StringIO())
322
 
 
323
 
    def test_matched_bundle(self):
324
 
        """Don't raise IncompatibleBundleFormat for knit2 and bundle0.9"""
325
 
        format = bzrdir.BzrDirMetaFormat1()
326
 
        format.repository_format = knitrepo.RepositoryFormatKnit2()
327
 
        serializer = BundleSerializerV09('0.9')
328
 
        b = self.make_branch('.', format=format)
329
 
        serializer.write(b.repository, [], {}, StringIO())
330
 
 
331
 
    def test_mismatched_model(self):
332
 
        """Try copying a bundle from knit2 to knit1"""
333
 
        format = bzrdir.BzrDirMetaFormat1()
334
 
        format.repository_format = knitrepo.RepositoryFormatKnit2()
335
 
        source = self.make_branch_and_tree('source', format=format)
336
 
        source.commit('one', rev_id='one-id')
337
 
        source.commit('two', rev_id='two-id')
338
 
        text = StringIO()
339
 
        write_bundle(source.branch.repository, 'two-id', None, text, 
340
 
                     format='0.9')
341
 
        text.seek(0)
342
 
 
343
 
        format = bzrdir.BzrDirMetaFormat1()
344
 
        format.repository_format = knitrepo.RepositoryFormatKnit1()
345
 
        target = self.make_branch('target', format=format)
346
 
        self.assertRaises(errors.IncompatibleRevision, install_bundle, 
347
 
                          target.repository, read_bundle(text))
348
 
 
349
 
 
350
 
class V08BundleTester(TestCaseWithTransport):
351
 
 
352
 
    format = '0.8'
353
 
 
354
 
    def bzrdir_format(self):
355
 
        format = bzrdir.BzrDirMetaFormat1()
356
 
        format.repository_format = knitrepo.RepositoryFormatKnit1()
357
 
        return format
358
 
 
359
 
    def make_branch_and_tree(self, path, format=None):
360
 
        if format is None:
361
 
            format = self.bzrdir_format()
362
 
        return TestCaseWithTransport.make_branch_and_tree(self, path, format)
363
 
 
364
 
    def make_branch(self, path, format=None):
365
 
        if format is None:
366
 
            format = self.bzrdir_format()
367
 
        return TestCaseWithTransport.make_branch(self, path, format)
 
304
class BundleTester(TestCaseWithTransport):
368
305
 
369
306
    def create_bundle_text(self, base_rev_id, rev_id):
370
307
        bundle_txt = StringIO()
371
308
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id, 
372
 
                               bundle_txt, format=self.format)
 
309
                               bundle_txt)
373
310
        bundle_txt.seek(0)
374
311
        self.assertEqual(bundle_txt.readline(), 
375
 
                         '# Bazaar revision bundle v%s\n' % self.format)
 
312
                         '# Bazaar revision bundle v0.8\n')
376
313
        self.assertEqual(bundle_txt.readline(), '#\n')
377
314
 
378
315
        rev = self.b1.repository.get_revision(rev_id)
454
391
        else:
455
392
            if not os.path.exists(checkout_dir):
456
393
                os.mkdir(checkout_dir)
457
 
        tree = self.make_branch_and_tree(checkout_dir)
 
394
        tree = BzrDir.create_standalone_workingtree(checkout_dir)
458
395
        s = StringIO()
459
 
        ancestors = write_bundle(self.b1.repository, rev_id, None, s,
460
 
                                 format=self.format)
 
396
        ancestors = write_bundle(self.b1.repository, rev_id, None, s)
461
397
        s.seek(0)
462
398
        assert isinstance(s.getvalue(), str), (
463
399
            "Bundle isn't a bytestring:\n %s..." % repr(s.getvalue())[:40])
635
571
                          verbose=False)
636
572
        bundle = self.get_valid_bundle('a@cset-0-5', 'a@cset-0-6')
637
573
        other = self.get_checkout('a@cset-0-5')
638
 
        tree1_inv = self.tree1.branch.repository.get_inventory_xml(
639
 
            'a@cset-0-5')
640
 
        tree2_inv = other.branch.repository.get_inventory_xml('a@cset-0-5')
641
 
        self.assertEqualDiff(tree1_inv, tree2_inv)
642
574
        other.rename_one('sub/dir/nolastnewline.txt', 'sub/nolastnewline.txt')
643
575
        other.commit('rename file', rev_id='a@cset-0-6b')
644
 
        _merge_helper([other.basedir, -1], [None, None],
645
 
                      this_dir=self.tree1.basedir)
 
576
        merge([other.basedir, -1], [None, None], this_dir=self.tree1.basedir)
646
577
        self.tree1.commit(u'Merge', rev_id='a@cset-0-7',
647
578
                          verbose=False)
648
579
        bundle = self.get_valid_bundle('a@cset-0-6', 'a@cset-0-7')
650
581
    def test_symlink_bundle(self):
651
582
        if not has_symlinks():
652
583
            raise TestSkipped("No symlink support")
653
 
        self.tree1 = self.make_branch_and_tree('b1')
 
584
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
654
585
        self.b1 = self.tree1.branch
655
586
        tt = TreeTransform(self.tree1)
656
587
        tt.new_symlink('link', tt.root, 'bar/foo', 'link-1')
680
611
        self.get_valid_bundle('l@cset-0-3', 'l@cset-0-4')
681
612
 
682
613
    def test_binary_bundle(self):
683
 
        self.tree1 = self.make_branch_and_tree('b1')
 
614
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
684
615
        self.b1 = self.tree1.branch
685
616
        tt = TreeTransform(self.tree1)
686
617
        
722
653
        self.get_valid_bundle(None, 'b@cset-0-4')
723
654
 
724
655
    def test_last_modified(self):
725
 
        self.tree1 = self.make_branch_and_tree('b1')
 
656
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
726
657
        self.b1 = self.tree1.branch
727
658
        tt = TreeTransform(self.tree1)
728
659
        tt.new_file('file', tt.root, 'file', 'file')
743
674
        tt.create_file('file2', trans_id)
744
675
        tt.apply()
745
676
        other.commit('modify text in another tree', rev_id='a@lmod-0-2b')
746
 
        _merge_helper([other.basedir, -1], [None, None],
747
 
                      this_dir=self.tree1.basedir)
 
677
        merge([other.basedir, -1], [None, None], this_dir=self.tree1.basedir)
748
678
        self.tree1.commit(u'Merge', rev_id='a@lmod-0-3',
749
679
                          verbose=False)
750
680
        self.tree1.commit(u'Merge', rev_id='a@lmod-0-4')
751
681
        bundle = self.get_valid_bundle('a@lmod-0-2a', 'a@lmod-0-4')
752
682
 
753
683
    def test_hide_history(self):
754
 
        self.tree1 = self.make_branch_and_tree('b1')
 
684
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
755
685
        self.b1 = self.tree1.branch
756
686
 
757
687
        open('b1/one', 'wb').write('one\n')
763
693
        self.tree1.commit('modify', rev_id='a@cset-0-3')
764
694
        bundle_file = StringIO()
765
695
        rev_ids = write_bundle(self.tree1.branch.repository, 'a@cset-0-3',
766
 
                               'a@cset-0-1', bundle_file, format=self.format)
 
696
                               'a@cset-0-1', bundle_file)
767
697
        self.assertNotContainsRe(bundle_file.getvalue(), 'two')
768
698
        self.assertContainsRe(bundle_file.getvalue(), 'one')
769
699
        self.assertContainsRe(bundle_file.getvalue(), 'three')
885
815
        self.assertEqual('revid1', tree.inventory.root.revision)
886
816
 
887
817
 
888
 
class V09BundleKnit2Tester(V08BundleTester):
889
 
 
890
 
    format = '0.9'
891
 
 
892
 
    def bzrdir_format(self):
893
 
        format = bzrdir.BzrDirMetaFormat1()
894
 
        format.repository_format = knitrepo.RepositoryFormatKnit2()
895
 
        return format
896
 
 
897
 
 
898
 
class V09BundleKnit1Tester(V08BundleTester):
899
 
 
900
 
    format = '0.9'
901
 
 
902
 
    def bzrdir_format(self):
903
 
        format = bzrdir.BzrDirMetaFormat1()
904
 
        format.repository_format = knitrepo.RepositoryFormatKnit1()
905
 
        return format
906
 
 
907
 
 
908
818
class MungedBundleTester(TestCaseWithTransport):
909
819
 
910
820
    def build_test_bundle(self):