16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
from bzrlib.tests import TestCaseInTempDir, TestCase
19
from bzrlib import repository
20
19
from bzrlib.osutils import has_symlinks
27
from bzrtools import cmd_baz_import
28
26
from bzrtools.baz_import import (import_version, revision_id,
29
make_archive, map_file_id)
27
cmd_baz_import, make_archive, map_file_id)
30
28
except ImportError:
31
from bzrlib.plugins.bzrtools import cmd_baz_import
32
29
from bzrlib.plugins.bzrtools.baz_import import (import_version,
72
70
pybaz.set_my_id("Test User<test@example.org>")
74
72
self.make_empty_import()
77
74
self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
78
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0', None)
75
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
79
76
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
80
77
pybaz.Version(self._empty_tag))
82
79
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
83
80
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
85
82
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
87
84
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
88
85
pybaz.Version(self._empty_merged_tag))
89
86
tree = pybaz.Revision(self._empty_merged_tag + '--base-0').get(
98
95
# tree, two commits, includes merge of other branch
99
96
self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
100
97
self._empty_merged_tag_2_bzr_base = revision_id(
101
self._empty_merged_tag_2 + '--base-0', None)
98
self._empty_merged_tag_2 + '--base-0')
102
99
self._empty_merged_tag_2_bzr = revision_id(
103
self._empty_merged_tag_2 + '--patch-1', None)
100
self._empty_merged_tag_2 + '--patch-1')
104
101
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
105
102
pybaz.Version(self._empty_merged_tag_2))
106
103
tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
113
110
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
115
112
self._bad_id_tag = 'demo@DONOTUSE/c--bad-id--0'
116
self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0',
118
self._bad_id_tag_bzr = revision_id(self._bad_id_tag + '--patch-1',
113
self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0')
114
self._bad_id_tag_bzr = revision_id(self._bad_id_tag + '--patch-1')
120
115
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
121
116
pybaz.Version(self._bad_id_tag))
122
117
tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
136
131
def make_import_symlink(self):
137
132
self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
138
133
self._import_symlink_bzr = revision_id(
139
self._import_symlink + '--base-0', None)
134
self._import_symlink + '--base-0')
140
135
os.mkdir(os.path.join(self._tmpdir, 'tree'))
141
136
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
142
137
self._import_symlink)
168
163
tree.import_(msg)
169
164
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
171
def make_utf8_log(self):
172
self._utf8 = 'demo@DONOTUSE/c--utf8--0'
173
os.mkdir(os.path.join(self._tmpdir, 'tree'))
174
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
176
msg = tree.log_message()
177
msg["summary"] = u"I am importing now\u1234".encode('utf-8')
179
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
181
166
def make_missing_ancestor(self):
182
167
self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
183
168
self._archive = make_archive('demo-gone@DONOTUSE',
184
169
str(self._archivegoneroot))
185
170
self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
186
171
self._missing_import_bzr = revision_id(self._missing_import
188
173
self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
189
174
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
191
176
os.mkdir(os.path.join(self._tmpdir, 'tree'))
192
177
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
193
178
self._missing_import)
207
192
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
208
193
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
210
pybaz.Version(self._missing_import), None)
195
pybaz.Version(self._missing_import))
211
196
# and make it inaccessible
212
197
pybaz.Archive('demo-gone@DONOTUSE').unregister()
214
199
def make_inbranch_continuation(self):
215
200
self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
216
201
self._inbranch_tag_base = self._inbranch_tag + '--base-0'
217
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
202
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base)
219
203
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
220
204
pybaz.Version(self._inbranch_tag))
221
205
self._inbranch_tag_head = self._inbranch_tag + '--patch-1'
222
self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head,
206
self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head)
224
207
pybaz.Revision(self._inbranch_tag_base).make_continuation(
225
208
pybaz.Version(self._inbranch_tag))
245
228
def tearDown(self):
246
229
ResourcedTestCase.tearDownResources(self)
247
230
TestCaseInTempDir.tearDown(self)
249
def test_import_utf8(self):
250
import_version('output', pybaz.Version(self._baz._utf8), None)
251
branch = Branch.open('output')
252
plain_revid = 'Arch-1:demo@DONOTUSE%c--utf8--0--base-0'
253
self.assertEqual([plain_revid], branch.revision_history())
254
self.assertEqual(u'I am importing now\ufffd\ufffd\ufffd',
255
branch.repository.get_revision(plain_revid).message)
256
import_version('output2', pybaz.Version(self._baz._utf8), 'utf-8')
257
branch2 = Branch.open('output2')
258
utf8_revid = 'Arch-1-utf-8:demo@DONOTUSE%c--utf8--0--base-0'
259
self.assertEqual([utf8_revid], branch2.revision_history())
260
self.assertEqual(u'I am importing now\u1234',
261
branch2.repository.get_revision(utf8_revid).message)
263
232
def test_import_empty(self):
264
import_version('output', pybaz.Version(self._baz._import), None)
233
import_version('output', pybaz.Version(self._baz._import))
265
234
# expected results:
266
235
# one commit, no files, revision identifier of
267
236
# 'demo@DONOTUSE_c--import--0--base-0'
271
240
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
272
241
rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
274
import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
243
import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
276
244
branch2 = Branch.open('output2')
277
245
repo2 = branch2.repository
278
246
self.assertEqual(branch.revision_history(), branch2.revision_history())
287
255
"Arch-1:demo@DONOTUSE%c--import--0--base-0")
289
257
def test_empty_tagged(self):
290
import_version('output', pybaz.Version(self._baz._empty_tag), None)
258
import_version('output', pybaz.Version(self._baz._empty_tag))
291
259
# expected results:
292
260
# two commits, no files, revision identifiers of
293
261
# 'demo@DONOTUSE_c--import--0--base-0' and
298
266
self._baz._empty_tag_bzr])
299
267
rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
301
import_version('output2', pybaz.Version(self._baz._empty_tag), None)
269
import_version('output2', pybaz.Version(self._baz._empty_tag))
302
270
branch2 = Branch.open('output2')
303
271
self.assertEqual(branch.revision_history(), branch2.revision_history())
304
272
rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
312
280
self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
314
282
def test_empty_merged_tagged(self):
315
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
283
import_version('output', pybaz.Version(self._baz._empty_merged_tag))
317
284
# expected results:
318
285
# two commits, no files, revision identifiers of
319
286
# 'demo@DONOTUSE_c--import--0--base-0' and
328
295
self._baz._empty_merged_tag_bzr_base,
329
296
self._baz._empty_merged_tag_bzr])
331
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
298
import_version('output2', pybaz.Version(self._baz._empty_merged_tag))
333
299
branch2 = Branch.open('output2')
334
300
repo2 = branch2.repository
335
301
# and import what we should be merged up against for checking with.
336
import_version('output3', pybaz.Version(self._baz._empty_tag), None)
302
import_version('output3', pybaz.Version(self._baz._empty_tag))
337
303
branch3 = Branch.open('output3')
339
305
self.assertEqual(branch.revision_history(), branch2.revision_history())
370
336
# self.assertEqual(branch.missing_revisions(branch3), [])
372
338
def test_merge_branch_with_merges(self):
373
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
339
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2))
375
340
# expected results:
376
341
# two commits, no files, revision identifiers of
377
342
# 'demo@DONOTUSE_c--import--0--base-0' and
386
351
self._baz._empty_merged_tag_2_bzr_base,
387
352
self._baz._empty_merged_tag_2_bzr])
389
import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
354
import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2))
391
355
branch2 = Branch.open('output2')
392
356
repo2 = branch2.repository
393
357
# and import what we should be merged up against for checking with.
394
import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
358
import_version('output3', pybaz.Version(self._baz._empty_merged_tag))
396
359
branch3 = Branch.open('output3')
398
361
self.assertEqual(branch.revision_history(), branch2.revision_history())
431
394
def test_import_symlink(self):
432
395
import_version('output', pybaz.Version(self._baz._import_symlink),
434
397
# expected results:
435
398
# two commits, no files, revision identifier of
436
399
# 'demo@DONOTUSE_c--import--0--base-0'
440
403
rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
442
405
import_version('output2', pybaz.Version(self._baz._import_symlink),
444
407
branch2 = Branch.open('output2')
445
408
self.assertEqual(branch.revision_history(), branch2.revision_history())
446
409
rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
462
425
# current bzr doesn't handle type changes
463
426
self.assertRaises(AssertionError, import_version, 'output3',
464
pybaz.Version(self._baz._import_symlink), None)
427
pybaz.Version(self._baz._import_symlink))
466
429
def test_missing_ancestor(self):
467
import_version('output', pybaz.Version(self._baz._missing_ancestor),
430
import_version('output', pybaz.Version(self._baz._missing_ancestor))
469
431
# expected results:
470
432
# one commits, no files, revision identifiers of
471
433
# 'demo@DONOTUSE_c--gone--0--base-0' and
475
437
[self._baz._missing_ancestor_bzr])
476
438
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
478
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
440
import_version('output2', pybaz.Version(self._baz._missing_ancestor))
480
441
branch2 = Branch.open('output2')
481
442
self.assertEqual(branch.revision_history(), branch2.revision_history())
482
443
rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
498
459
def test_missing_ancestor_reusing_history(self):
499
460
import_version('output', pybaz.Version(self._baz._missing_ancestor),
501
461
reuse_history_from=[self._baz._missing_import_imported])
502
462
# expected results:
503
463
# one commits, no files, revision identifiers of
510
470
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
512
472
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
514
473
reuse_history_from=[self._baz._missing_import_imported])
515
474
branch2 = Branch.open('output2')
516
475
self.assertEqual(branch.revision_history(), branch2.revision_history())
530
489
self.assertEqual(1, len(rev.parent_ids))
532
491
def test_bad_file_id(self):
533
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
492
import_version('output', pybaz.Version(self._baz._bad_id_tag))
534
493
# expected results:
535
494
# three commits, one files, revision identifiers of
536
495
# 'demo@DONOTUSE_c--import--0--base-0' ,
547
506
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
549
508
def test_appending_revisions_already_present(self):
550
import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
509
import_version('output', pybaz.Version(self._baz._bad_id_tag),
552
511
# expected results:
553
512
# three commits, one files, revision identifiers of
565
524
self.assertEqual(branch.revision_history(),
566
525
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
568
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
527
import_version('output', pybaz.Version(self._baz._bad_id_tag))
569
528
branch = Branch.open('output')
570
529
self.assertEqual(branch.revision_history(),
571
530
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
577
536
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
579
538
def test_appending_revisions_all_already_present(self):
580
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
539
import_version('output', pybaz.Version(self._baz._bad_id_tag))
581
540
# expected results:
582
541
# three commits, one files, revision identifiers of
583
542
# 'demo@DONOTUSE_c--import--0--base-0' ,
595
554
self.assertEqual(branch.revision_history(),
596
555
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
598
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
557
import_version('output', pybaz.Version(self._baz._bad_id_tag))
599
558
branch = Branch.open('output')
600
559
self.assertEqual(branch.revision_history(),
601
560
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
607
566
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
609
568
def test_inbranch_conversion(self):
610
import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
569
import_version('output', pybaz.Version(self._baz._inbranch_tag))
611
570
# expected results:
612
571
# three commits, no files, revision identifiers of
613
572
# 'demo@DONOTUSE_c--import--0--base-0' and
620
579
self._baz._inbranch_tag_base_bzr,
621
580
self._baz._inbranch_tag_head_bzr])
623
import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
582
import_version('output2', pybaz.Version(self._baz._inbranch_tag))
624
583
branch2 = Branch.open('output2')
626
585
self.assertEqual(branch.revision_history(), branch2.revision_history())
652
611
branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
653
import_version(path, pybaz.Version(self._baz._import), None)
612
import_version(path, pybaz.Version(self._baz._import))
654
613
# expected results:
655
614
# one commit, revision identifier of
656
615
# 'demo@DONOTUSE_c--import--0--base-0'
742
701
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
744
703
def test_cmd_exists(self):
745
from bzrlib.plugins.bzrtools import cmd_baz_import
704
from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
747
706
def test_empty_archive(self):
748
707
command = cmd_baz_import()
762
721
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
763
722
'c1', '0.2','branch')))
764
default_format = repository.RepositoryFormat.get_default_format()
765
if getattr(default_format, 'rich_root_data', False):
769
723
walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
770
self.assertEqual(num_files, walk_len)
724
self.assertEqual(20, walk_len)
772
726
def test_run_twice(self):
773
727
self.make_import('c--0')
785
739
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'),
793
def test_encoding_flag(self):
794
self.make_import('c--0')
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,
799
'output/c/+trunk')).revision_history())
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,
804
'output2/c/+trunk')).revision_history())
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,
809
'output3')).revision_history())
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,
814
'output4')).revision_history())