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,
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'])
313
class BundleTester1(TestCaseWithTransport):
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())
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())
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')
339
write_bundle(source.branch.repository, 'two-id', None, text,
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))
350
class V08BundleTester(TestCaseWithTransport):
354
def bzrdir_format(self):
355
format = bzrdir.BzrDirMetaFormat1()
356
format.repository_format = knitrepo.RepositoryFormatKnit1()
359
def make_branch_and_tree(self, path, format=None):
361
format = self.bzrdir_format()
362
return TestCaseWithTransport.make_branch_and_tree(self, path, format)
364
def make_branch(self, path, format=None):
366
format = self.bzrdir_format()
367
return TestCaseWithTransport.make_branch(self, path, format)
304
class BundleTester(TestCaseWithTransport):
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)
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')
378
315
rev = self.b1.repository.get_revision(rev_id)
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)
459
ancestors = write_bundle(self.b1.repository, rev_id, None, s,
396
ancestors = write_bundle(self.b1.repository, rev_id, None, s)
462
398
assert isinstance(s.getvalue(), str), (
463
399
"Bundle isn't a bytestring:\n %s..." % repr(s.getvalue())[:40])
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(
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',
648
579
bundle = self.get_valid_bundle('a@cset-0-6', 'a@cset-0-7')
743
674
tt.create_file('file2', trans_id)
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',
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')
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
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')