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
72
80
pybaz.Version(self._empty_tag))
74
82
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
75
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
83
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
76
84
+ '--base-0', None)
77
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
85
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
78
86
+ '--patch-1', None)
79
87
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
80
88
pybaz.Version(self._empty_merged_tag))
86
94
msg["summary"]="did a merge, yarh"
88
96
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
90
98
# tree, two commits, includes merge of other branch
91
99
self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
92
100
self._empty_merged_tag_2_bzr_base = revision_id(
114
122
tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
115
123
os.path.join(self._tmpdir, 'tree'))
116
124
from bzrlib.plugins.bzrtools.baz_import import add_file
117
add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
125
add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
118
126
'this_id/needs%escaping')
119
127
msg = tree.log_message()
120
128
msg["summary"] = "commit something which needs escaping."
153
161
def make_empty_import(self):
154
162
self._import = 'demo@DONOTUSE/c--import--0'
155
163
os.mkdir(os.path.join(self._tmpdir, 'tree'))
156
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
164
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
158
166
msg = tree.log_message()
159
167
msg["summary"] = "I am importing now"
163
171
def make_utf8_log(self):
164
172
self._utf8 = 'demo@DONOTUSE/c--utf8--0'
165
173
os.mkdir(os.path.join(self._tmpdir, 'tree'))
166
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
174
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
168
176
msg = tree.log_message()
169
177
msg["summary"] = u"I am importing now\u1234".encode('utf-8')
175
183
self._archive = make_archive('demo-gone@DONOTUSE',
176
184
str(self._archivegoneroot))
177
185
self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
178
self._missing_import_bzr = revision_id(self._missing_import
186
self._missing_import_bzr = revision_id(self._missing_import
179
187
+ '--base-0', None)
180
188
self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
181
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
189
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
182
190
+ '--base-0', None)
183
191
os.mkdir(os.path.join(self._tmpdir, 'tree'))
184
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
192
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
185
193
self._missing_import)
186
194
msg = tree.log_message()
187
195
msg["summary"] = "I am importing now"
194
202
# make an import for testing history-reuse logic.
195
203
# note the use of a namespace layout here.
196
self._missing_import_imported = os.path.join(self._tmpdir,
204
self._missing_import_imported = os.path.join(self._tmpdir,
197
205
'archivegone-bzr')
198
206
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr'))
199
207
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
200
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
208
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
202
210
pybaz.Version(self._missing_import), None)
203
211
# and make it inaccessible
206
214
def make_inbranch_continuation(self):
207
215
self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
208
216
self._inbranch_tag_base = self._inbranch_tag + '--base-0'
209
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
217
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
211
219
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
212
220
pybaz.Version(self._inbranch_tag))
255
263
def test_import_empty(self):
256
264
import_version('output', pybaz.Version(self._baz._import), None)
257
265
# expected results:
258
# one commit, no files, revision identifier of
266
# one commit, no files, revision identifier of
259
267
# 'demo@DONOTUSE_c--import--0--base-0'
260
268
branch = Branch.open('output')
261
269
repo = branch.repository
281
289
def test_empty_tagged(self):
282
290
import_version('output', pybaz.Version(self._baz._empty_tag), None)
283
291
# expected results:
284
# two commits, no files, revision identifiers of
292
# two commits, no files, revision identifiers of
285
293
# 'demo@DONOTUSE_c--import--0--base-0' and
286
294
# self._baz._empty_tag_bzr
287
295
branch = Branch.open('output')
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)
338
346
self.assertEqual(rev, rev2)
339
347
# and we should get some expected values:
340
348
self.assertEqual(rev.committer, "Test User<test@example.org>")
341
self.assertEqual(rev.message,
349
self.assertEqual(rev.message,
342
350
"tag of demo@DONOTUSE/c--import--0--base-0")
343
351
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
344
352
self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
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
386
394
import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
388
396
branch3 = Branch.open('output3')
390
398
self.assertEqual(branch.revision_history(), branch2.revision_history())
391
self.assertNotEqual(branch.revision_history(),
399
self.assertNotEqual(branch.revision_history(),
392
400
branch3.revision_history())
393
401
# check revisions in the history.
394
402
rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr_base)
397
405
self.assertEqual(rev, rev2)
398
406
# and we should get some expected values:
399
407
self.assertEqual(rev.committer, "Test User<test@example.org>")
400
self.assertEqual(rev.message,
408
self.assertEqual(rev.message,
401
409
"tag of demo@DONOTUSE/c--import--0--base-0")
402
self.assertEqual(rev.revision_id,
410
self.assertEqual(rev.revision_id,
403
411
self._baz._empty_merged_tag_2_bzr_base)
405
413
# check next revisions in the history.
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')
467
475
[self._baz._missing_ancestor_bzr])
468
476
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
470
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
478
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
472
480
branch2 = Branch.open('output2')
473
481
self.assertEqual(branch.revision_history(), branch2.revision_history())
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):
493
501
reuse_history_from=[self._baz._missing_import_imported])
494
502
# expected results:
495
# one commits, no files, revision identifiers of
496
# 'demo-gone@DONOTUSE%c--import--0--base-0' and
503
# one commits, no files, revision identifiers of
504
# 'demo-gone@DONOTUSE%c--import--0--base-0' and
497
505
# 'demo@DONOTUSE%c--gone--0--base-0'
498
506
branch = Branch.open('output')
499
507
self.assertEqual(branch.revision_history(),
516
524
# and we should get some expected values:
517
525
self.assertEqual(rev.committer, "Test User<test@example.org>")
518
self.assertEqual(rev.message,
526
self.assertEqual(rev.message,
519
527
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
520
528
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
521
529
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
524
532
def test_bad_file_id(self):
525
533
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
526
534
# expected results:
527
# three commits, one files, revision identifiers of
535
# three commits, one files, revision identifiers of
528
536
# 'demo@DONOTUSE_c--import--0--base-0' ,
529
537
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
530
538
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
542
550
import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
544
552
# expected results:
545
# three commits, one files, revision identifiers of
553
# three commits, one files, revision identifiers of
546
554
# 'demo@DONOTUSE_c--import--0--base-0' ,
547
555
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
548
556
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
571
579
def test_appending_revisions_all_already_present(self):
572
580
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
573
581
# expected results:
574
# three commits, one files, revision identifiers of
582
# three commits, one files, revision identifiers of
575
583
# 'demo@DONOTUSE_c--import--0--base-0' ,
576
584
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
577
585
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
601
609
def test_inbranch_conversion(self):
602
610
import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
603
611
# expected results:
604
# three commits, no files, revision identifiers of
612
# three commits, no files, revision identifiers of
605
613
# 'demo@DONOTUSE_c--import--0--base-0' and
606
614
# self._baz._inbranch_tag_base_bzr
607
615
# self._baz._inbranch_tag_head_bzr
615
623
import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
616
624
branch2 = Branch.open('output2')
618
626
self.assertEqual(branch.revision_history(), branch2.revision_history())
619
627
# check revisions in the history.
620
628
rev = branch.repository.get_revision(self._baz._inbranch_tag_base_bzr)
644
652
branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
645
653
import_version(path, pybaz.Version(self._baz._import), None)
646
654
# expected results:
647
# one commit, revision identifier of
655
# one commit, revision identifier of
648
656
# 'demo@DONOTUSE_c--import--0--base-0'
649
657
self.assertEqual(branch.revision_history(),
650
658
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
662
670
def test_patch1_base0(self):
663
671
self.assertEqual(namespace_previous(self.version['patch-1']),
664
672
self.version['base-0'])
666
674
def test_patch3000_patch2999(self):
667
675
self.assertEqual(namespace_previous(self.version['patch-3000']),
668
676
self.version['patch-2999'])
670
678
def test_version0_raises(self):
671
679
self.assertRaises(RuntimeError, namespace_previous,
672
680
self.version['version-0'])
693
701
from bzrlib.plugins.bzrtools.baz_import import map_namespace
694
702
category = pybaz.Category('foo@example.com/c')
695
703
self.assertRaises(pybaz.errors.NamespaceError, map_namespace, category)
696
self.assertEqual('c/+trunk',
704
self.assertEqual('c/+trunk',
697
705
map_namespace(pybaz.Version("%s--0" % category)))
698
706
self.assertEqual('c/0.1/+trunk',
699
707
map_namespace(pybaz.Version('%s--0.1' % category)))
726
734
def make_import(self, namespace):
727
735
self._import = 'demo@DONOTUSE/%s' % namespace
728
736
os.mkdir(os.path.join(self._tmpdir, 'tree'))
729
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
737
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
731
739
msg = tree.log_message()
732
740
msg["summary"] = "I am importing now"
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()
757
765
if getattr(default_format, 'rich_root_data', False):
766
774
command = cmd_baz_import()
767
775
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
768
776
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
770
778
def test_accepts_reuse_history(self):
771
779
self.make_import('c--0')
772
780
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
773
781
'demo@DONOTUSE', '.', '.')
775
783
def test_does_not_need_reuse_history(self):
776
784
self.make_import('c--0')
777
785
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
786
794
self.make_import('c--0')
787
795
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,
797
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
798
Branch.open(os.path.join(self._tmpdir,
791
799
'output/c/+trunk')).revision_history())
792
800
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output2'),
793
801
'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,
802
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
803
Branch.open(os.path.join(self._tmpdir,
796
804
'output2/c/+trunk')).revision_history())
797
805
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir, 'output3'),
798
806
'demo@DONOTUSE/c--0')
799
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
800
Branch.open(os.path.join(self._tmpdir,
807
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
808
Branch.open(os.path.join(self._tmpdir,
801
809
'output3')).revision_history())
802
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir,
810
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir,
803
811
'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,
812
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
813
Branch.open(os.path.join(self._tmpdir,
806
814
'output4')).revision_history())