23
23
except ImportError:
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,
26
from bzrlib.plugins.bzrtools import cmd_baz_import
27
from bzrlib.plugins.bzrtools.baz_import import (import_version,
37
32
from StringIO import StringIO
39
34
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
43
38
from bzrlib.errors import NoSuchRevision
45
from bzrtools.fai import namespace_previous
47
from bzrlib.plugins.bzrtools.fai import namespace_previous
39
from bzrlib.plugins.bzrtools.fai import namespace_previous
48
40
from bzrlib.branch import Branch
80
72
pybaz.Version(self._empty_tag))
82
74
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
83
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
84
76
+ '--base-0', None)
85
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
77
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
86
78
+ '--patch-1', None)
87
79
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
88
80
pybaz.Version(self._empty_merged_tag))
94
86
msg["summary"]="did a merge, yarh"
96
88
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
98
90
# tree, two commits, includes merge of other branch
99
91
self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
100
92
self._empty_merged_tag_2_bzr_base = revision_id(
122
114
tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
123
115
os.path.join(self._tmpdir, 'tree'))
124
116
from bzrlib.plugins.bzrtools.baz_import import add_file
125
add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
117
add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
126
118
'this_id/needs%escaping')
127
119
msg = tree.log_message()
128
120
msg["summary"] = "commit something which needs escaping."
161
153
def make_empty_import(self):
162
154
self._import = 'demo@DONOTUSE/c--import--0'
163
155
os.mkdir(os.path.join(self._tmpdir, 'tree'))
164
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
156
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
166
158
msg = tree.log_message()
167
159
msg["summary"] = "I am importing now"
171
163
def make_utf8_log(self):
172
164
self._utf8 = 'demo@DONOTUSE/c--utf8--0'
173
165
os.mkdir(os.path.join(self._tmpdir, 'tree'))
174
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
166
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
176
168
msg = tree.log_message()
177
169
msg["summary"] = u"I am importing now\u1234".encode('utf-8')
183
175
self._archive = make_archive('demo-gone@DONOTUSE',
184
176
str(self._archivegoneroot))
185
177
self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
186
self._missing_import_bzr = revision_id(self._missing_import
178
self._missing_import_bzr = revision_id(self._missing_import
187
179
+ '--base-0', None)
188
180
self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
189
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
181
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
190
182
+ '--base-0', None)
191
183
os.mkdir(os.path.join(self._tmpdir, 'tree'))
192
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
184
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
193
185
self._missing_import)
194
186
msg = tree.log_message()
195
187
msg["summary"] = "I am importing now"
202
194
# make an import for testing history-reuse logic.
203
195
# note the use of a namespace layout here.
204
self._missing_import_imported = os.path.join(self._tmpdir,
196
self._missing_import_imported = os.path.join(self._tmpdir,
205
197
'archivegone-bzr')
206
198
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr'))
207
199
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
208
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
200
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
210
202
pybaz.Version(self._missing_import), None)
211
203
# and make it inaccessible
214
206
def make_inbranch_continuation(self):
215
207
self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
216
208
self._inbranch_tag_base = self._inbranch_tag + '--base-0'
217
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
209
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
219
211
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
220
212
pybaz.Version(self._inbranch_tag))
263
255
def test_import_empty(self):
264
256
import_version('output', pybaz.Version(self._baz._import), None)
265
257
# expected results:
266
# one commit, no files, revision identifier of
258
# one commit, no files, revision identifier of
267
259
# 'demo@DONOTUSE_c--import--0--base-0'
268
260
branch = Branch.open('output')
269
261
repo = branch.repository
289
281
def test_empty_tagged(self):
290
282
import_version('output', pybaz.Version(self._baz._empty_tag), None)
291
283
# expected results:
292
# two commits, no files, revision identifiers of
284
# two commits, no files, revision identifiers of
293
285
# 'demo@DONOTUSE_c--import--0--base-0' and
294
286
# self._baz._empty_tag_bzr
295
287
branch = Branch.open('output')
308
300
# and we should get some expected values:
309
301
self.assertEqual(rev.committer, "Test User<test@example.org>")
310
self.assertEqual(rev.message,
302
self.assertEqual(rev.message,
311
303
"tag of demo@DONOTUSE/c--import--0--base-0")
312
304
self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
314
306
def test_empty_merged_tagged(self):
315
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
307
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
317
309
# expected results:
318
# two commits, no files, revision identifiers of
310
# two commits, no files, revision identifiers of
319
311
# 'demo@DONOTUSE_c--import--0--base-0' and
320
312
# self._baz._empty_merged_tag_bzr_base
321
313
# self._baz._empty_merged_tag_bzr
328
320
self._baz._empty_merged_tag_bzr_base,
329
321
self._baz._empty_merged_tag_bzr])
331
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
323
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
333
325
branch2 = Branch.open('output2')
334
326
repo2 = branch2.repository
335
327
# and import what we should be merged up against for checking with.
336
328
import_version('output3', pybaz.Version(self._baz._empty_tag), None)
337
329
branch3 = Branch.open('output3')
339
331
self.assertEqual(branch.revision_history(), branch2.revision_history())
340
self.assertNotEqual(branch.revision_history(),
332
self.assertNotEqual(branch.revision_history(),
341
333
branch3.revision_history())
342
334
# check revisions in the history.
343
335
rev = repo.get_revision(self._baz._empty_merged_tag_bzr_base)
346
338
self.assertEqual(rev, rev2)
347
339
# and we should get some expected values:
348
340
self.assertEqual(rev.committer, "Test User<test@example.org>")
349
self.assertEqual(rev.message,
341
self.assertEqual(rev.message,
350
342
"tag of demo@DONOTUSE/c--import--0--base-0")
351
343
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
352
344
self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
365
357
self._baz._empty_merged_tag_bzr_base)
366
358
self.assertEqual(rev.parent_ids[1], self._baz._empty_tag_bzr)
368
# this tree should have nothing missing from that tree.
360
# this tree should have nothing missing from that tree.
369
361
# FIXME there is no code for this right now.
370
362
# self.assertEqual(branch.missing_revisions(branch3), [])
372
364
def test_merge_branch_with_merges(self):
373
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
365
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
375
367
# expected results:
376
# two commits, no files, revision identifiers of
368
# two commits, no files, revision identifiers of
377
369
# 'demo@DONOTUSE_c--import--0--base-0' and
378
370
# self._baz._empty_merged_tag_2_bzr_base
379
371
# self._baz._empty_merged_tag_2_bzr
394
386
import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
396
388
branch3 = Branch.open('output3')
398
390
self.assertEqual(branch.revision_history(), branch2.revision_history())
399
self.assertNotEqual(branch.revision_history(),
391
self.assertNotEqual(branch.revision_history(),
400
392
branch3.revision_history())
401
393
# check revisions in the history.
402
394
rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr_base)
405
397
self.assertEqual(rev, rev2)
406
398
# and we should get some expected values:
407
399
self.assertEqual(rev.committer, "Test User<test@example.org>")
408
self.assertEqual(rev.message,
400
self.assertEqual(rev.message,
409
401
"tag of demo@DONOTUSE/c--import--0--base-0")
410
self.assertEqual(rev.revision_id,
402
self.assertEqual(rev.revision_id,
411
403
self._baz._empty_merged_tag_2_bzr_base)
413
405
# check next revisions in the history.
424
416
self.assertEqual(rev.parent_ids[1],
425
417
self._baz._empty_merged_tag_bzr)
427
# this tree should have nothing missing from that tree.
419
# this tree should have nothing missing from that tree.
428
420
# FIXME there is no code for this right now.
429
421
# self.assertEqual(branch.missing_revisions(branch3), [])
431
423
def test_import_symlink(self):
432
import_version('output', pybaz.Version(self._baz._import_symlink),
424
import_version('output', pybaz.Version(self._baz._import_symlink),
433
425
None, max_count=1)
434
426
# expected results:
435
# two commits, no files, revision identifier of
427
# two commits, no files, revision identifier of
436
428
# 'demo@DONOTUSE_c--import--0--base-0'
437
429
branch = Branch.open('output')
438
430
self.assertEqual(branch.revision_history(),
459
451
self.assertEqual(entry.kind, 'symlink')
460
452
self.assertEqual(entry.symlink_target, 'missing-file-name')
462
# current bzr doesn't handle type changes
463
self.assertRaises(AssertionError, import_version, 'output3',
464
pybaz.Version(self._baz._import_symlink), None)
454
# Test kind change for import
455
import_version('output3', pybaz.Version(self._baz._import_symlink),
466
458
def test_missing_ancestor(self):
467
459
import_version('output', pybaz.Version(self._baz._missing_ancestor),
469
461
# expected results:
470
# one commits, no files, revision identifiers of
462
# one commits, no files, revision identifiers of
471
463
# 'demo@DONOTUSE_c--gone--0--base-0' and
472
464
# a merge of demo-gone@DONOTUSE%c--import--0
473
465
branch = Branch.open('output')
475
467
[self._baz._missing_ancestor_bzr])
476
468
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
478
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
470
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
480
472
branch2 = Branch.open('output2')
481
473
self.assertEqual(branch.revision_history(), branch2.revision_history())
486
478
# and we should get some expected values:
487
479
self.assertEqual(rev.committer, "Test User<test@example.org>")
488
self.assertEqual(rev.message,
480
self.assertEqual(rev.message,
489
481
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
490
482
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
491
483
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
492
484
self.assertEqual(1, len(rev.parent_ids))
494
486
# must NOT be able to get the merged evision
495
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
487
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
496
488
self._baz._missing_import_bzr)
498
490
def test_missing_ancestor_reusing_history(self):
501
493
reuse_history_from=[self._baz._missing_import_imported])
502
494
# expected results:
503
# one commits, no files, revision identifiers of
504
# '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
505
497
# 'demo@DONOTUSE%c--gone--0--base-0'
506
498
branch = Branch.open('output')
507
499
self.assertEqual(branch.revision_history(),
524
516
# and we should get some expected values:
525
517
self.assertEqual(rev.committer, "Test User<test@example.org>")
526
self.assertEqual(rev.message,
518
self.assertEqual(rev.message,
527
519
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
528
520
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
529
521
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
532
524
def test_bad_file_id(self):
533
525
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
534
526
# expected results:
535
# three commits, one files, revision identifiers of
527
# three commits, one files, revision identifiers of
536
528
# 'demo@DONOTUSE_c--import--0--base-0' ,
537
529
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
538
530
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
550
542
import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
552
544
# expected results:
553
# three commits, one files, revision identifiers of
545
# three commits, one files, revision identifiers of
554
546
# 'demo@DONOTUSE_c--import--0--base-0' ,
555
547
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
556
548
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
579
571
def test_appending_revisions_all_already_present(self):
580
572
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
581
573
# expected results:
582
# three commits, one files, revision identifiers of
574
# three commits, one files, revision identifiers of
583
575
# 'demo@DONOTUSE_c--import--0--base-0' ,
584
576
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
585
577
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
609
601
def test_inbranch_conversion(self):
610
602
import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
611
603
# expected results:
612
# three commits, no files, revision identifiers of
604
# three commits, no files, revision identifiers of
613
605
# 'demo@DONOTUSE_c--import--0--base-0' and
614
606
# self._baz._inbranch_tag_base_bzr
615
607
# self._baz._inbranch_tag_head_bzr
623
615
import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
624
616
branch2 = Branch.open('output2')
626
618
self.assertEqual(branch.revision_history(), branch2.revision_history())
627
619
# check revisions in the history.
628
620
rev = branch.repository.get_revision(self._baz._inbranch_tag_base_bzr)
652
644
branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
653
645
import_version(path, pybaz.Version(self._baz._import), None)
654
646
# expected results:
655
# one commit, revision identifier of
647
# one commit, revision identifier of
656
648
# 'demo@DONOTUSE_c--import--0--base-0'
657
649
self.assertEqual(branch.revision_history(),
658
650
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
670
662
def test_patch1_base0(self):
671
663
self.assertEqual(namespace_previous(self.version['patch-1']),
672
664
self.version['base-0'])
674
666
def test_patch3000_patch2999(self):
675
667
self.assertEqual(namespace_previous(self.version['patch-3000']),
676
668
self.version['patch-2999'])
678
670
def test_version0_raises(self):
679
671
self.assertRaises(RuntimeError, namespace_previous,
680
672
self.version['version-0'])
701
693
from bzrlib.plugins.bzrtools.baz_import import map_namespace
702
694
category = pybaz.Category('foo@example.com/c')
703
695
self.assertRaises(pybaz.errors.NamespaceError, map_namespace, category)
704
self.assertEqual('c/+trunk',
696
self.assertEqual('c/+trunk',
705
697
map_namespace(pybaz.Version("%s--0" % category)))
706
698
self.assertEqual('c/0.1/+trunk',
707
699
map_namespace(pybaz.Version('%s--0.1' % category)))
734
726
def make_import(self, namespace):
735
727
self._import = 'demo@DONOTUSE/%s' % namespace
736
728
os.mkdir(os.path.join(self._tmpdir, 'tree'))
737
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
729
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
739
731
msg = tree.log_message()
740
732
msg["summary"] = "I am importing now"
757
749
command = cmd_baz_import()
758
750
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
759
751
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
760
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
752
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
762
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
754
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
763
755
'c1', '0.2','branch')))
764
756
default_format = repository.RepositoryFormat.get_default_format()
765
757
if getattr(default_format, 'rich_root_data', False):
774
766
command = cmd_baz_import()
775
767
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
776
768
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
778
770
def test_accepts_reuse_history(self):
779
771
self.make_import('c--0')
780
772
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
781
773
'demo@DONOTUSE', '.', '.')
783
775
def test_does_not_need_reuse_history(self):
784
776
self.make_import('c--0')
785
777
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
794
786
self.make_import('c--0')
795
787
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,
789
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
790
Branch.open(os.path.join(self._tmpdir,
799
791
'output/c/+trunk')).revision_history())
800
792
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output2'),
801
793
'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,
794
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
795
Branch.open(os.path.join(self._tmpdir,
804
796
'output2/c/+trunk')).revision_history())
805
797
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir, 'output3'),
806
798
'demo@DONOTUSE/c--0')
807
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
808
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,
809
801
'output3')).revision_history())
810
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir,
802
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir,
811
803
'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,
804
self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
805
Branch.open(os.path.join(self._tmpdir,
814
806
'output4')).revision_history())