~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:
1
 
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006, 2007 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
38
38
from bzrlib.errors import (BzrError, TestamentMismatch, NotABundle, BadBundle, 
39
39
                           NoSuchFile,)
40
40
from bzrlib.merge import Merge3Merger
 
41
from bzrlib.repofmt import knitrepo
41
42
from bzrlib.osutils import has_symlinks, sha_file
42
43
from bzrlib.tests import (TestCaseInTempDir, TestCaseWithTransport,
43
44
                          TestCase, TestSkipped)
313
314
 
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
320
        self.assertRaises(errors.IncompatibleBundleFormat, serializer.write, 
322
323
    def test_matched_bundle(self):
323
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())
330
331
    def test_mismatched_model(self):
331
332
        """Try copying a bundle from knit2 to knit1"""
332
333
        format = bzrdir.BzrDirMetaFormat1()
333
 
        format.repository_format = repository.RepositoryFormatKnit2()
 
334
        format.repository_format = knitrepo.RepositoryFormatKnit3()
334
335
        source = self.make_branch_and_tree('source', format=format)
335
336
        source.commit('one', rev_id='one-id')
336
337
        source.commit('two', rev_id='two-id')
340
341
        text.seek(0)
341
342
 
342
343
        format = bzrdir.BzrDirMetaFormat1()
343
 
        format.repository_format = repository.RepositoryFormatKnit1()
 
344
        format.repository_format = knitrepo.RepositoryFormatKnit1()
344
345
        target = self.make_branch('target', format=format)
345
346
        self.assertRaises(errors.IncompatibleRevision, install_bundle, 
346
347
                          target.repository, read_bundle(text))
352
353
 
353
354
    def bzrdir_format(self):
354
355
        format = bzrdir.BzrDirMetaFormat1()
355
 
        format.repository_format = repository.RepositoryFormatKnit1()
 
356
        format.repository_format = knitrepo.RepositoryFormatKnit1()
356
357
        return format
357
358
 
358
359
    def make_branch_and_tree(self, path, format=None):
487
488
            tree.update()
488
489
            delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
489
490
            self.assertFalse(delta.has_changed(),
490
 
                             'Working tree has modifications')
 
491
                             'Working tree has modifications: %s' % delta)
491
492
        return tree
492
493
 
493
494
    def valid_apply_bundle(self, base_rev_id, info, checkout_dir=None):
763
764
        bundle_file = StringIO()
764
765
        rev_ids = write_bundle(self.tree1.branch.repository, 'a@cset-0-3',
765
766
                               'a@cset-0-1', bundle_file, format=self.format)
766
 
        self.assertNotContainsRe(bundle_file.getvalue(), 'two')
 
767
        self.assertNotContainsRe(bundle_file.getvalue(), '\btwo\b')
767
768
        self.assertContainsRe(bundle_file.getvalue(), 'one')
768
769
        self.assertContainsRe(bundle_file.getvalue(), 'three')
769
770
 
783
784
            u'William Dod\xe9\n').encode('utf-8'))
784
785
        f.close()
785
786
 
786
 
        self.tree1.add([u'with Dod\xe9'])
787
 
        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',
788
789
                          rev_id='i18n-1', committer=u'William Dod\xe9')
789
790
 
 
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')],
 
797
                             delta.removed)
 
798
            self.knownFailure("Mac OSX doesn't preserve unicode"
 
799
                              " combining characters.")
 
800
 
790
801
        # Add
791
802
        bundle = self.get_valid_bundle(None, 'i18n-1')
792
803
 
883
894
        tree = bundle.revision_tree(self.b1.repository, 'revid1')
884
895
        self.assertEqual('revid1', tree.inventory.root.revision)
885
896
 
 
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)
 
907
 
886
908
 
887
909
class V09BundleKnit2Tester(V08BundleTester):
888
910
 
890
912
 
891
913
    def bzrdir_format(self):
892
914
        format = bzrdir.BzrDirMetaFormat1()
893
 
        format.repository_format = repository.RepositoryFormatKnit2()
 
915
        format.repository_format = knitrepo.RepositoryFormatKnit3()
894
916
        return format
895
917
 
896
918
 
900
922
 
901
923
    def bzrdir_format(self):
902
924
        format = bzrdir.BzrDirMetaFormat1()
903
 
        format.repository_format = repository.RepositoryFormatKnit1()
 
925
        format.repository_format = knitrepo.RepositoryFormatKnit1()
904
926
        return format
905
927
 
906
928