14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from StringIO import StringIO
17
from cStringIO import StringIO
19
19
from bzrlib.builtins import merge
20
20
from bzrlib.bzrdir import BzrDir
25
25
from bzrlib.errors import BzrError, TestamentMismatch, NotABundle
26
26
from bzrlib.merge import Merge3Merger
27
27
from bzrlib.osutils import has_symlinks, sha_file
28
from bzrlib.tests import TestCaseInTempDir, TestCase, TestSkipped
28
from bzrlib.tests import (TestCaseInTempDir, TestCaseWithTransport,
29
TestCase, TestSkipped)
29
30
from bzrlib.transform import TreeTransform
30
31
from bzrlib.workingtree import WorkingTree
294
295
self.assertEqual(self.sorted_ids(btree), ['a', 'b', 'd', 'e'])
297
class CSetTester(TestCaseInTempDir):
299
def get_valid_bundle(self, base_rev_id, rev_id, checkout_dir=None,
301
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
302
Make sure that the text generated is valid, and that it
303
can be applied against the base, and generate the same information.
305
:return: The in-memory bundle
307
from cStringIO import StringIO
298
class BundleTester(TestCaseInTempDir):
300
def create_bundle_text(self, base_rev_id, rev_id):
309
301
bundle_txt = StringIO()
310
302
rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
321
313
open(',,bundle', 'wb').write(bundle_txt.getvalue())
322
314
bundle_txt.seek(0)
315
return bundle_txt, rev_ids
317
def get_valid_bundle(self, base_rev_id, rev_id, checkout_dir=None):
318
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
319
Make sure that the text generated is valid, and that it
320
can be applied against the base, and generate the same information.
322
:return: The in-memory bundle
324
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
323
326
# This should also validate the generated bundle
324
327
bundle = read_bundle(bundle_txt)
325
328
repository = self.b1.repository
350
353
:return: The in-memory bundle
352
from cStringIO import StringIO
354
bundle_txt = StringIO()
355
rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
358
open(',,bundle', 'wb').write(bundle_txt.getvalue())
355
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
360
356
new_text = bundle_txt.getvalue().replace('executable:no',
361
357
'executable:yes')
362
358
bundle_txt = StringIO(new_text)
453
449
# to_tree.get_file(fileid).read())
455
451
def test_bundle(self):
460
452
self.tree1 = BzrDir.create_standalone_workingtree('b1')
461
453
self.b1 = self.tree1.branch
463
open(pjoin('b1/one'), 'wb').write('one\n')
455
open('b1/one', 'wb').write('one\n')
464
456
self.tree1.add('one')
465
457
self.tree1.commit('add one', rev_id='a@cset-0-1')
467
459
bundle = self.get_valid_bundle(None, 'a@cset-0-1')
468
bundle = self.get_valid_bundle(None, 'a@cset-0-1',
469
message='With a specialized message')
460
# FIXME: The current write_bundle api no longer supports
461
# setting a custom summary message
462
# We should re-introduce the ability, and update
463
# the tests to make sure it works.
464
# bundle = self.get_valid_bundle(None, 'a@cset-0-1',
465
# message='With a specialized message')
471
467
# Make sure we can handle files with spaces, tabs, other
472
468
# bogus characters
663
659
bundle = self.get_valid_bundle('a@lmod-0-2a', 'a@lmod-0-4')
665
661
def test_hide_history(self):
669
662
self.tree1 = BzrDir.create_standalone_workingtree('b1')
670
663
self.b1 = self.tree1.branch
672
open(pjoin('b1/one'), 'wb').write('one\n')
665
open('b1/one', 'wb').write('one\n')
673
666
self.tree1.add('one')
674
667
self.tree1.commit('add file', rev_id='a@cset-0-1')
675
open(pjoin('b1/one'), 'wb').write('two\n')
668
open('b1/one', 'wb').write('two\n')
676
669
self.tree1.commit('modify', rev_id='a@cset-0-2')
677
open(pjoin('b1/one'), 'wb').write('three\n')
670
open('b1/one', 'wb').write('three\n')
678
671
self.tree1.commit('modify', rev_id='a@cset-0-3')
679
672
bundle_file = StringIO()
680
673
rev_ids = write_bundle(self.tree1.branch.repository, 'a@cset-0-3',
682
675
self.assertNotContainsRe(bundle_file.getvalue(), 'two')
683
676
self.assertContainsRe(bundle_file.getvalue(), 'one')
684
677
self.assertContainsRe(bundle_file.getvalue(), 'three')
680
class MungedBundleTester(TestCaseWithTransport):
682
def build_test_bundle(self):
683
wt = self.make_branch_and_tree('b1')
685
self.build_tree(['b1/one'])
687
wt.commit('add one', rev_id='a@cset-0-1')
688
self.build_tree(['b1/two'])
690
wt.commit('add two', rev_id='a@cset-0-2')
692
bundle_txt = StringIO()
693
rev_ids = write_bundle(wt.branch.repository, 'a@cset-0-2',
694
'a@cset-0-1', bundle_txt)
695
self.assertEqual(['a@cset-0-2'], rev_ids)
696
bundle_txt.seek(0, 0)
699
def check_valid(self, bundle):
700
"""Check that after whatever munging, the final object is valid."""
701
self.assertEqual(['a@cset-0-2'],
702
[r.revision_id for r in bundle.real_revisions])
704
def test_extra_whitespace(self):
705
bundle_txt = self.build_test_bundle()
707
# Seek to the end of the file
708
# Adding one extra newline used to give us
709
# TypeError: float() argument must be a string or a number
710
bundle_txt.seek(0, 2)
711
bundle_txt.write('\n')
714
bundle = read_bundle(bundle_txt)
715
self.check_valid(bundle)
717
def test_extra_whitespace_2(self):
718
bundle_txt = self.build_test_bundle()
720
# Seek to the end of the file
721
# Adding two extra newlines used to give us
722
# MalformedPatches: The first line of all patches should be ...
723
bundle_txt.seek(0, 2)
724
bundle_txt.write('\n\n')
727
bundle = read_bundle(bundle_txt)
728
self.check_valid(bundle)
730
def test_missing_trailing_whitespace(self):
731
bundle_txt = self.build_test_bundle()
733
# Remove a trailing newline, it shouldn't kill the parser
734
raw = bundle_txt.getvalue()
735
# The contents of the bundle don't have to be this, but this
736
# test is concerned with the exact case where the serializer
737
# creates a blank line at the end, and fails if that
739
self.assertEqual('\n\n', raw[-2:])
740
bundle_text = StringIO(raw[:-1])
742
bundle = read_bundle(bundle_txt)
743
self.check_valid(bundle)