15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
from cStringIO import StringIO
19
22
from bzrlib.builtins import merge
20
23
from bzrlib.bzrdir import BzrDir
21
24
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
22
25
from bzrlib.bundle.bundle_data import BundleTree
23
26
from bzrlib.bundle.serializer import write_bundle, read_bundle
27
from bzrlib.branch import Branch
24
28
from bzrlib.diff import internal_diff
29
from bzrlib.delta import compare_trees
25
30
from bzrlib.errors import BzrError, TestamentMismatch, NotABundle, BadBundle
26
31
from bzrlib.merge import Merge3Merger
27
32
from bzrlib.osutils import has_symlinks, sha_file
72
76
def make_entry(self, file_id, path):
73
from os.path import basename
74
77
from bzrlib.inventory import (InventoryEntry, InventoryFile
75
78
, InventoryDirectory, InventoryLink)
79
name = os.path.basename(path)
77
80
kind = self.get_file_kind(file_id)
78
81
parent_id = self.parent_id(file_id)
79
82
text_sha_1, text_size = self.contents_stats(file_id)
398
398
for ancestor in ancestors:
399
399
old = self.b1.repository.revision_tree(ancestor)
400
400
new = tree.branch.repository.revision_tree(ancestor)
402
# Check that there aren't any inventory level changes
403
delta = compare_trees(old, new)
404
self.assertFalse(delta.has_changed(),
405
'Revision %s not copied correctly.'
408
# Now check that the file contents are all correct
401
409
for inventory_id in old:
403
411
old_file = old.get_file(inventory_id)
546
555
open('b1/sub/dir/WithCaps.txt', 'ab').write('\nAdding some text\n')
547
open('b1/sub/dir/trailing space ', 'ab').write('\nAdding some\nDOS format lines\n')
556
open('b1/sub/dir/ pre space', 'ab').write('\r\nAdding some\r\nDOS format lines\r\n')
548
557
open('b1/sub/dir/nolastnewline.txt', 'ab').write('\n')
549
self.tree1.rename_one('sub/dir/trailing space ',
550
'sub/ start and end space ')
558
self.tree1.rename_one('sub/dir/ pre space',
551
560
self.tree1.commit('Modified files', rev_id='a@cset-0-5')
552
561
bundle = self.get_valid_bundle('a@cset-0-4', 'a@cset-0-5')
554
# Handle international characters
556
f = open(u'b1/with Dod\xe9', 'wb')
557
except UnicodeEncodeError:
558
raise TestSkipped("Filesystem doesn't support unicode")
560
u'With international man of mystery\n'
561
u'William Dod\xe9\n').encode('utf-8'))
562
self.tree1.add([u'with Dod\xe9'])
563
# BUG: (sort of) You must set verbose=False, so that python doesn't try
564
# and print the name of William Dode as part of the commit
565
self.tree1.commit(u'i18n commit from William Dod\xe9',
566
rev_id='a@cset-0-6', committer=u'William Dod\xe9',
568
bundle = self.get_valid_bundle('a@cset-0-5', 'a@cset-0-6')
569
563
self.tree1.rename_one('sub/dir/WithCaps.txt', 'temp')
570
564
self.tree1.rename_one('with space.txt', 'WithCaps.txt')
571
565
self.tree1.rename_one('temp', 'with space.txt')
572
self.tree1.commit(u'swap filenames', rev_id='a@cset-0-7',
566
self.tree1.commit(u'swap filenames', rev_id='a@cset-0-6',
568
bundle = self.get_valid_bundle('a@cset-0-5', 'a@cset-0-6')
569
other = self.get_checkout('a@cset-0-5')
570
other.rename_one('sub/dir/nolastnewline.txt', 'sub/nolastnewline.txt')
571
other.commit('rename file', rev_id='a@cset-0-6b')
572
merge([other.basedir, -1], [None, None], this_dir=self.tree1.basedir)
573
self.tree1.commit(u'Merge', rev_id='a@cset-0-7',
574
575
bundle = self.get_valid_bundle('a@cset-0-6', 'a@cset-0-7')
575
other = self.get_checkout('a@cset-0-6')
576
other.rename_one('sub/dir/nolastnewline.txt', 'sub/nolastnewline.txt')
577
other.commit('rename file', rev_id='a@cset-0-7b')
578
merge([other.basedir, -1], [None, None], this_dir=self.tree1.basedir)
579
self.tree1.commit(u'Merge', rev_id='a@cset-0-8',
581
bundle = self.get_valid_bundle('a@cset-0-7', 'a@cset-0-8')
583
577
def test_symlink_bundle(self):
584
578
if not has_symlinks():
689
683
self.assertContainsRe(bundle_file.getvalue(), 'one')
690
684
self.assertContainsRe(bundle_file.getvalue(), 'three')
686
def test_unicode_bundle(self):
687
# Handle international characters
690
f = open(u'b1/with Dod\xe9', 'wb')
691
except UnicodeEncodeError:
692
raise TestSkipped("Filesystem doesn't support unicode")
694
self.tree1 = self.make_branch_and_tree('b1')
695
self.b1 = self.tree1.branch
698
u'With international man of mystery\n'
699
u'William Dod\xe9\n').encode('utf-8'))
702
self.tree1.add([u'with Dod\xe9'])
703
self.tree1.commit(u'i18n commit from William Dod\xe9',
704
rev_id='i18n-1', committer=u'William Dod\xe9')
707
bundle = self.get_valid_bundle(None, 'i18n-1')
710
f = open(u'b1/with Dod\xe9', 'wb')
711
f.write(u'Modified \xb5\n'.encode('utf8'))
713
self.tree1.commit(u'modified', rev_id='i18n-2')
715
bundle = self.get_valid_bundle('i18n-1', 'i18n-2')
718
self.tree1.rename_one(u'with Dod\xe9', u'B\xe5gfors')
719
self.tree1.commit(u'renamed, the new i18n man', rev_id='i18n-3',
720
committer=u'Erik B\xe5gfors')
722
bundle = self.get_valid_bundle('i18n-2', 'i18n-3')
725
self.tree1.remove([u'B\xe5gfors'])
726
self.tree1.commit(u'removed', rev_id='i18n-4')
728
bundle = self.get_valid_bundle('i18n-3', 'i18n-4')
731
bundle = self.get_valid_bundle(None, 'i18n-4')
734
def test_whitespace_bundle(self):
735
if sys.platform in ('win32', 'cygwin'):
736
raise TestSkipped('Windows doesn\'t support filenames'
737
' with tabs or trailing spaces')
738
self.tree1 = self.make_branch_and_tree('b1')
739
self.b1 = self.tree1.branch
741
self.build_tree(['b1/trailing space '])
742
self.tree1.add(['trailing space '])
743
# TODO: jam 20060701 Check for handling files with '\t' characters
744
# once we actually support them
747
self.tree1.commit('funky whitespace', rev_id='white-1')
749
bundle = self.get_valid_bundle(None, 'white-1')
752
open('b1/trailing space ', 'ab').write('add some text\n')
753
self.tree1.commit('add text', rev_id='white-2')
755
bundle = self.get_valid_bundle('white-1', 'white-2')
758
self.tree1.rename_one('trailing space ', ' start and end space ')
759
self.tree1.commit('rename', rev_id='white-3')
761
bundle = self.get_valid_bundle('white-2', 'white-3')
764
self.tree1.remove([' start and end space '])
765
self.tree1.commit('removed', rev_id='white-4')
767
bundle = self.get_valid_bundle('white-3', 'white-4')
769
# Now test a complet roll-up
770
bundle = self.get_valid_bundle(None, 'white-4')
693
773
class MungedBundleTester(TestCaseWithTransport):