23
23
except ImportError:
26
from bzrlib.plugins.bzrtools import cmd_baz_import
27
from bzrlib.plugins.bzrtools.baz_import import (import_version,
27
from bzrtools import cmd_baz_import
28
from bzrtools.baz_import import (import_version, revision_id,
29
make_archive, map_file_id)
31
from bzrlib.plugins.bzrtools import cmd_baz_import
32
from bzrlib.plugins.bzrtools.baz_import import (import_version,
32
37
from StringIO import StringIO
34
39
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
38
43
from bzrlib.errors import NoSuchRevision
39
from bzrlib.plugins.bzrtools.fai import namespace_previous
45
from bzrtools.fai import namespace_previous
47
from bzrlib.plugins.bzrtools.fai import namespace_previous
40
48
from bzrlib.branch import Branch
300
308
# and we should get some expected values:
301
309
self.assertEqual(rev.committer, "Test User<test@example.org>")
302
self.assertEqual(rev.message,
310
self.assertEqual(rev.message,
303
311
"tag of demo@DONOTUSE/c--import--0--base-0")
304
312
self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
306
314
def test_empty_merged_tagged(self):
307
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
315
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
309
317
# expected results:
310
# two commits, no files, revision identifiers of
318
# two commits, no files, revision identifiers of
311
319
# 'demo@DONOTUSE_c--import--0--base-0' and
312
320
# self._baz._empty_merged_tag_bzr_base
313
321
# self._baz._empty_merged_tag_bzr
320
328
self._baz._empty_merged_tag_bzr_base,
321
329
self._baz._empty_merged_tag_bzr])
323
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
331
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
325
333
branch2 = Branch.open('output2')
326
334
repo2 = branch2.repository
327
335
# and import what we should be merged up against for checking with.
328
336
import_version('output3', pybaz.Version(self._baz._empty_tag), None)
329
337
branch3 = Branch.open('output3')
331
339
self.assertEqual(branch.revision_history(), branch2.revision_history())
332
self.assertNotEqual(branch.revision_history(),
340
self.assertNotEqual(branch.revision_history(),
333
341
branch3.revision_history())
334
342
# check revisions in the history.
335
343
rev = repo.get_revision(self._baz._empty_merged_tag_bzr_base)
357
365
self._baz._empty_merged_tag_bzr_base)
358
366
self.assertEqual(rev.parent_ids[1], self._baz._empty_tag_bzr)
360
# this tree should have nothing missing from that tree.
368
# this tree should have nothing missing from that tree.
361
369
# FIXME there is no code for this right now.
362
370
# self.assertEqual(branch.missing_revisions(branch3), [])
364
372
def test_merge_branch_with_merges(self):
365
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
373
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
367
375
# expected results:
368
# two commits, no files, revision identifiers of
376
# two commits, no files, revision identifiers of
369
377
# 'demo@DONOTUSE_c--import--0--base-0' and
370
378
# self._baz._empty_merged_tag_2_bzr_base
371
379
# self._baz._empty_merged_tag_2_bzr
416
424
self.assertEqual(rev.parent_ids[1],
417
425
self._baz._empty_merged_tag_bzr)
419
# this tree should have nothing missing from that tree.
427
# this tree should have nothing missing from that tree.
420
428
# FIXME there is no code for this right now.
421
429
# self.assertEqual(branch.missing_revisions(branch3), [])
423
431
def test_import_symlink(self):
424
import_version('output', pybaz.Version(self._baz._import_symlink),
432
import_version('output', pybaz.Version(self._baz._import_symlink),
425
433
None, max_count=1)
426
434
# expected results:
427
# two commits, no files, revision identifier of
435
# two commits, no files, revision identifier of
428
436
# 'demo@DONOTUSE_c--import--0--base-0'
429
437
branch = Branch.open('output')
430
438
self.assertEqual(branch.revision_history(),
451
459
self.assertEqual(entry.kind, 'symlink')
452
460
self.assertEqual(entry.symlink_target, 'missing-file-name')
454
# Test kind change for import
455
import_version('output3', pybaz.Version(self._baz._import_symlink),
462
# current bzr doesn't handle type changes
463
self.assertRaises(AssertionError, import_version, 'output3',
464
pybaz.Version(self._baz._import_symlink), None)
458
466
def test_missing_ancestor(self):
459
467
import_version('output', pybaz.Version(self._baz._missing_ancestor),
461
469
# expected results:
462
# one commits, no files, revision identifiers of
470
# one commits, no files, revision identifiers of
463
471
# 'demo@DONOTUSE_c--gone--0--base-0' and
464
472
# a merge of demo-gone@DONOTUSE%c--import--0
465
473
branch = Branch.open('output')
478
486
# and we should get some expected values:
479
487
self.assertEqual(rev.committer, "Test User<test@example.org>")
480
self.assertEqual(rev.message,
488
self.assertEqual(rev.message,
481
489
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
482
490
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
483
491
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
484
492
self.assertEqual(1, len(rev.parent_ids))
486
494
# must NOT be able to get the merged evision
487
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
495
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
488
496
self._baz._missing_import_bzr)
490
498
def test_missing_ancestor_reusing_history(self):
749
757
command = cmd_baz_import()
750
758
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
751
759
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
752
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
760
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
754
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
762
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
755
763
'c1', '0.2','branch')))
756
764
default_format = repository.RepositoryFormat.get_default_format()
765
if getattr(default_format, 'rich_root_data', False):
757
769
walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
758
self.assertEqual(22, walk_len)
770
self.assertEqual(num_files, walk_len)
760
772
def test_run_twice(self):
761
773
self.make_import('c--0')
762
774
command = cmd_baz_import()
763
775
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
764
776
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
766
778
def test_accepts_reuse_history(self):
767
779
self.make_import('c--0')
768
self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output'),
769
'demo@DONOTUSE', '.', '.'])
771
def test_does_not_need_reuse_history(self):
772
self.make_import('c--0')
773
self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output'),
776
def test_does_not_need_reuse_history(self):
777
self.make_import('c--0')
778
self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output'),
780
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
781
'demo@DONOTUSE', '.', '.')
783
def test_does_not_need_reuse_history(self):
784
self.make_import('c--0')
785
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
788
def test_does_not_need_reuse_history(self):
789
self.make_import('c--0')
790
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
781
793
def test_encoding_flag(self):
782
794
self.make_import('c--0')
783
self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output'),
785
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
786
Branch.open(os.path.join(self._tmpdir,
795
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
797
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
798
Branch.open(os.path.join(self._tmpdir,
787
799
'output/c/+trunk')).revision_history())
788
self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output2'),
789
'demo@DONOTUSE', '--encoding', 'utf-8'])
790
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
791
Branch.open(os.path.join(self._tmpdir,
800
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output2'),
801
'demo@DONOTUSE', '--encoding', 'utf-8')
802
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
803
Branch.open(os.path.join(self._tmpdir,
792
804
'output2/c/+trunk')).revision_history())
793
self.run_bzr(['baz-import-branch', os.path.join(self._tmpdir,
794
'output3'), 'demo@DONOTUSE/c--0'])
795
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
796
Branch.open(os.path.join(self._tmpdir,
805
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir, 'output3'),
806
'demo@DONOTUSE/c--0')
807
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
808
Branch.open(os.path.join(self._tmpdir,
797
809
'output3')).revision_history())
798
self.run_bzr(['baz-import-branch', os.path.join(self._tmpdir,
799
'output4'), 'demo@DONOTUSE/c--0', '--encoding', 'utf-8'])
800
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
801
Branch.open(os.path.join(self._tmpdir,
810
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir,
811
'output4'), 'demo@DONOTUSE/c--0', '--encoding', 'utf-8')
812
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
813
Branch.open(os.path.join(self._tmpdir,
802
814
'output4')).revision_history())