23
23
except ImportError:
26
from bzrlib.plugins.bzrtools import cmd_baz_import
27
from bzrlib.plugins.bzrtools.baz_import import (import_version,
26
from bzrlib.plugins.bzrtools import cmd_baz_import
27
from bzrlib.plugins.bzrtools.baz_import import (import_version,
72
72
pybaz.Version(self._empty_tag))
74
74
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
75
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
75
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
76
76
+ '--base-0', None)
77
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
77
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
78
78
+ '--patch-1', None)
79
79
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
80
80
pybaz.Version(self._empty_merged_tag))
86
86
msg["summary"]="did a merge, yarh"
88
88
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
90
90
# tree, two commits, includes merge of other branch
91
91
self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
92
92
self._empty_merged_tag_2_bzr_base = revision_id(
114
114
tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
115
115
os.path.join(self._tmpdir, 'tree'))
116
116
from bzrlib.plugins.bzrtools.baz_import import add_file
117
add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
117
add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
118
118
'this_id/needs%escaping')
119
119
msg = tree.log_message()
120
120
msg["summary"] = "commit something which needs escaping."
153
153
def make_empty_import(self):
154
154
self._import = 'demo@DONOTUSE/c--import--0'
155
155
os.mkdir(os.path.join(self._tmpdir, 'tree'))
156
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
156
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
158
158
msg = tree.log_message()
159
159
msg["summary"] = "I am importing now"
163
163
def make_utf8_log(self):
164
164
self._utf8 = 'demo@DONOTUSE/c--utf8--0'
165
165
os.mkdir(os.path.join(self._tmpdir, 'tree'))
166
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
166
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
168
168
msg = tree.log_message()
169
169
msg["summary"] = u"I am importing now\u1234".encode('utf-8')
175
175
self._archive = make_archive('demo-gone@DONOTUSE',
176
176
str(self._archivegoneroot))
177
177
self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
178
self._missing_import_bzr = revision_id(self._missing_import
178
self._missing_import_bzr = revision_id(self._missing_import
179
179
+ '--base-0', None)
180
180
self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
181
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
181
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
182
182
+ '--base-0', None)
183
183
os.mkdir(os.path.join(self._tmpdir, 'tree'))
184
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
184
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
185
185
self._missing_import)
186
186
msg = tree.log_message()
187
187
msg["summary"] = "I am importing now"
194
194
# make an import for testing history-reuse logic.
195
195
# note the use of a namespace layout here.
196
self._missing_import_imported = os.path.join(self._tmpdir,
196
self._missing_import_imported = os.path.join(self._tmpdir,
197
197
'archivegone-bzr')
198
198
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr'))
199
199
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
200
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
200
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
202
202
pybaz.Version(self._missing_import), None)
203
203
# and make it inaccessible
206
206
def make_inbranch_continuation(self):
207
207
self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
208
208
self._inbranch_tag_base = self._inbranch_tag + '--base-0'
209
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
209
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
211
211
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
212
212
pybaz.Version(self._inbranch_tag))
255
255
def test_import_empty(self):
256
256
import_version('output', pybaz.Version(self._baz._import), None)
257
257
# expected results:
258
# one commit, no files, revision identifier of
258
# one commit, no files, revision identifier of
259
259
# 'demo@DONOTUSE_c--import--0--base-0'
260
260
branch = Branch.open('output')
261
261
repo = branch.repository
281
281
def test_empty_tagged(self):
282
282
import_version('output', pybaz.Version(self._baz._empty_tag), None)
283
283
# expected results:
284
# two commits, no files, revision identifiers of
284
# two commits, no files, revision identifiers of
285
285
# 'demo@DONOTUSE_c--import--0--base-0' and
286
286
# self._baz._empty_tag_bzr
287
287
branch = Branch.open('output')
300
300
# and we should get some expected values:
301
301
self.assertEqual(rev.committer, "Test User<test@example.org>")
302
self.assertEqual(rev.message,
302
self.assertEqual(rev.message,
303
303
"tag of demo@DONOTUSE/c--import--0--base-0")
304
304
self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
306
306
def test_empty_merged_tagged(self):
307
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
307
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
309
309
# expected results:
310
# two commits, no files, revision identifiers of
310
# two commits, no files, revision identifiers of
311
311
# 'demo@DONOTUSE_c--import--0--base-0' and
312
312
# self._baz._empty_merged_tag_bzr_base
313
313
# self._baz._empty_merged_tag_bzr
320
320
self._baz._empty_merged_tag_bzr_base,
321
321
self._baz._empty_merged_tag_bzr])
323
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
323
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
325
325
branch2 = Branch.open('output2')
326
326
repo2 = branch2.repository
327
327
# and import what we should be merged up against for checking with.
328
328
import_version('output3', pybaz.Version(self._baz._empty_tag), None)
329
329
branch3 = Branch.open('output3')
331
331
self.assertEqual(branch.revision_history(), branch2.revision_history())
332
self.assertNotEqual(branch.revision_history(),
332
self.assertNotEqual(branch.revision_history(),
333
333
branch3.revision_history())
334
334
# check revisions in the history.
335
335
rev = repo.get_revision(self._baz._empty_merged_tag_bzr_base)
338
338
self.assertEqual(rev, rev2)
339
339
# and we should get some expected values:
340
340
self.assertEqual(rev.committer, "Test User<test@example.org>")
341
self.assertEqual(rev.message,
341
self.assertEqual(rev.message,
342
342
"tag of demo@DONOTUSE/c--import--0--base-0")
343
343
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
344
344
self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
357
357
self._baz._empty_merged_tag_bzr_base)
358
358
self.assertEqual(rev.parent_ids[1], self._baz._empty_tag_bzr)
360
# this tree should have nothing missing from that tree.
360
# this tree should have nothing missing from that tree.
361
361
# FIXME there is no code for this right now.
362
362
# self.assertEqual(branch.missing_revisions(branch3), [])
364
364
def test_merge_branch_with_merges(self):
365
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
365
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
367
367
# expected results:
368
# two commits, no files, revision identifiers of
368
# two commits, no files, revision identifiers of
369
369
# 'demo@DONOTUSE_c--import--0--base-0' and
370
370
# self._baz._empty_merged_tag_2_bzr_base
371
371
# self._baz._empty_merged_tag_2_bzr
386
386
import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
388
388
branch3 = Branch.open('output3')
390
390
self.assertEqual(branch.revision_history(), branch2.revision_history())
391
self.assertNotEqual(branch.revision_history(),
391
self.assertNotEqual(branch.revision_history(),
392
392
branch3.revision_history())
393
393
# check revisions in the history.
394
394
rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr_base)
397
397
self.assertEqual(rev, rev2)
398
398
# and we should get some expected values:
399
399
self.assertEqual(rev.committer, "Test User<test@example.org>")
400
self.assertEqual(rev.message,
400
self.assertEqual(rev.message,
401
401
"tag of demo@DONOTUSE/c--import--0--base-0")
402
self.assertEqual(rev.revision_id,
402
self.assertEqual(rev.revision_id,
403
403
self._baz._empty_merged_tag_2_bzr_base)
405
405
# check next revisions in the history.
416
416
self.assertEqual(rev.parent_ids[1],
417
417
self._baz._empty_merged_tag_bzr)
419
# this tree should have nothing missing from that tree.
419
# this tree should have nothing missing from that tree.
420
420
# FIXME there is no code for this right now.
421
421
# self.assertEqual(branch.missing_revisions(branch3), [])
423
423
def test_import_symlink(self):
424
import_version('output', pybaz.Version(self._baz._import_symlink),
424
import_version('output', pybaz.Version(self._baz._import_symlink),
425
425
None, max_count=1)
426
426
# expected results:
427
# two commits, no files, revision identifier of
427
# two commits, no files, revision identifier of
428
428
# 'demo@DONOTUSE_c--import--0--base-0'
429
429
branch = Branch.open('output')
430
430
self.assertEqual(branch.revision_history(),
459
459
import_version('output', pybaz.Version(self._baz._missing_ancestor),
461
461
# expected results:
462
# one commits, no files, revision identifiers of
462
# one commits, no files, revision identifiers of
463
463
# 'demo@DONOTUSE_c--gone--0--base-0' and
464
464
# a merge of demo-gone@DONOTUSE%c--import--0
465
465
branch = Branch.open('output')
467
467
[self._baz._missing_ancestor_bzr])
468
468
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
470
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
470
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
472
472
branch2 = Branch.open('output2')
473
473
self.assertEqual(branch.revision_history(), branch2.revision_history())
478
478
# and we should get some expected values:
479
479
self.assertEqual(rev.committer, "Test User<test@example.org>")
480
self.assertEqual(rev.message,
480
self.assertEqual(rev.message,
481
481
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
482
482
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
483
483
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
484
484
self.assertEqual(1, len(rev.parent_ids))
486
486
# must NOT be able to get the merged evision
487
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
487
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
488
488
self._baz._missing_import_bzr)
490
490
def test_missing_ancestor_reusing_history(self):
493
493
reuse_history_from=[self._baz._missing_import_imported])
494
494
# expected results:
495
# one commits, no files, revision identifiers of
496
# 'demo-gone@DONOTUSE%c--import--0--base-0' and
495
# one commits, no files, revision identifiers of
496
# 'demo-gone@DONOTUSE%c--import--0--base-0' and
497
497
# 'demo@DONOTUSE%c--gone--0--base-0'
498
498
branch = Branch.open('output')
499
499
self.assertEqual(branch.revision_history(),
516
516
# and we should get some expected values:
517
517
self.assertEqual(rev.committer, "Test User<test@example.org>")
518
self.assertEqual(rev.message,
518
self.assertEqual(rev.message,
519
519
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
520
520
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
521
521
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
524
524
def test_bad_file_id(self):
525
525
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
526
526
# expected results:
527
# three commits, one files, revision identifiers of
527
# three commits, one files, revision identifiers of
528
528
# 'demo@DONOTUSE_c--import--0--base-0' ,
529
529
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
530
530
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
542
542
import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
544
544
# expected results:
545
# three commits, one files, revision identifiers of
545
# three commits, one files, revision identifiers of
546
546
# 'demo@DONOTUSE_c--import--0--base-0' ,
547
547
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
548
548
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
571
571
def test_appending_revisions_all_already_present(self):
572
572
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
573
573
# expected results:
574
# three commits, one files, revision identifiers of
574
# three commits, one files, revision identifiers of
575
575
# 'demo@DONOTUSE_c--import--0--base-0' ,
576
576
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
577
577
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
601
601
def test_inbranch_conversion(self):
602
602
import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
603
603
# expected results:
604
# three commits, no files, revision identifiers of
604
# three commits, no files, revision identifiers of
605
605
# 'demo@DONOTUSE_c--import--0--base-0' and
606
606
# self._baz._inbranch_tag_base_bzr
607
607
# self._baz._inbranch_tag_head_bzr
615
615
import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
616
616
branch2 = Branch.open('output2')
618
618
self.assertEqual(branch.revision_history(), branch2.revision_history())
619
619
# check revisions in the history.
620
620
rev = branch.repository.get_revision(self._baz._inbranch_tag_base_bzr)
644
644
branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
645
645
import_version(path, pybaz.Version(self._baz._import), None)
646
646
# expected results:
647
# one commit, revision identifier of
647
# one commit, revision identifier of
648
648
# 'demo@DONOTUSE_c--import--0--base-0'
649
649
self.assertEqual(branch.revision_history(),
650
650
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
662
662
def test_patch1_base0(self):
663
663
self.assertEqual(namespace_previous(self.version['patch-1']),
664
664
self.version['base-0'])
666
666
def test_patch3000_patch2999(self):
667
667
self.assertEqual(namespace_previous(self.version['patch-3000']),
668
668
self.version['patch-2999'])
670
670
def test_version0_raises(self):
671
671
self.assertRaises(RuntimeError, namespace_previous,
672
672
self.version['version-0'])
693
693
from bzrlib.plugins.bzrtools.baz_import import map_namespace
694
694
category = pybaz.Category('foo@example.com/c')
695
695
self.assertRaises(pybaz.errors.NamespaceError, map_namespace, category)
696
self.assertEqual('c/+trunk',
696
self.assertEqual('c/+trunk',
697
697
map_namespace(pybaz.Version("%s--0" % category)))
698
698
self.assertEqual('c/0.1/+trunk',
699
699
map_namespace(pybaz.Version('%s--0.1' % category)))
726
726
def make_import(self, namespace):
727
727
self._import = 'demo@DONOTUSE/%s' % namespace
728
728
os.mkdir(os.path.join(self._tmpdir, 'tree'))
729
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
729
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
731
731
msg = tree.log_message()
732
732
msg["summary"] = "I am importing now"
749
749
command = cmd_baz_import()
750
750
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
751
751
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
752
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
752
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
754
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
754
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
755
755
'c1', '0.2','branch')))
756
756
default_format = repository.RepositoryFormat.get_default_format()
757
757
if getattr(default_format, 'rich_root_data', False):
766
766
command = cmd_baz_import()
767
767
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
768
768
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
770
770
def test_accepts_reuse_history(self):
771
771
self.make_import('c--0')
772
772
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
773
773
'demo@DONOTUSE', '.', '.')
775
775
def test_does_not_need_reuse_history(self):
776
776
self.make_import('c--0')
777
777
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
786
786
self.make_import('c--0')
787
787
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
789
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
790
Branch.open(os.path.join(self._tmpdir,
789
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
790
Branch.open(os.path.join(self._tmpdir,
791
791
'output/c/+trunk')).revision_history())
792
792
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output2'),
793
793
'demo@DONOTUSE', '--encoding', 'utf-8')
794
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
795
Branch.open(os.path.join(self._tmpdir,
794
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
795
Branch.open(os.path.join(self._tmpdir,
796
796
'output2/c/+trunk')).revision_history())
797
797
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir, 'output3'),
798
798
'demo@DONOTUSE/c--0')
799
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
800
Branch.open(os.path.join(self._tmpdir,
799
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
800
Branch.open(os.path.join(self._tmpdir,
801
801
'output3')).revision_history())
802
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir,
802
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir,
803
803
'output4'), 'demo@DONOTUSE/c--0', '--encoding', 'utf-8')
804
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
805
Branch.open(os.path.join(self._tmpdir,
804
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
805
Branch.open(os.path.join(self._tmpdir,
806
806
'output4')).revision_history())