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
23
22
except ImportError:
26
from bzrlib.plugins.bzrtools import cmd_baz_import
27
from bzrlib.plugins.bzrtools.baz_import import (import_version,
26
from bzrtools.baz_import import (import_version, revision_id,
27
cmd_baz_import, make_archive, map_file_id)
29
from bzrlib.plugins.bzrtools.baz_import import (import_version,
32
35
from StringIO import StringIO
38
41
from bzrlib.errors import NoSuchRevision
39
from bzrlib.plugins.bzrtools.fai import namespace_previous
43
from bzrtools.fai import namespace_previous
45
from bzrlib.plugins.bzrtools.fai import namespace_previous
40
46
from bzrlib.branch import Branch
64
70
pybaz.set_my_id("Test User<test@example.org>")
66
72
self.make_empty_import()
69
74
self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
70
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0', None)
75
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
71
76
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
72
77
pybaz.Version(self._empty_tag))
74
79
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
75
80
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
77
82
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
79
84
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
80
85
pybaz.Version(self._empty_merged_tag))
81
86
tree = pybaz.Revision(self._empty_merged_tag + '--base-0').get(
90
95
# tree, two commits, includes merge of other branch
91
96
self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
92
97
self._empty_merged_tag_2_bzr_base = revision_id(
93
self._empty_merged_tag_2 + '--base-0', None)
98
self._empty_merged_tag_2 + '--base-0')
94
99
self._empty_merged_tag_2_bzr = revision_id(
95
self._empty_merged_tag_2 + '--patch-1', None)
100
self._empty_merged_tag_2 + '--patch-1')
96
101
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
97
102
pybaz.Version(self._empty_merged_tag_2))
98
103
tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
105
110
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
107
112
self._bad_id_tag = 'demo@DONOTUSE/c--bad-id--0'
108
self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0',
110
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')
112
115
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
113
116
pybaz.Version(self._bad_id_tag))
114
117
tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
128
131
def make_import_symlink(self):
129
132
self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
130
133
self._import_symlink_bzr = revision_id(
131
self._import_symlink + '--base-0', None)
134
self._import_symlink + '--base-0')
132
135
os.mkdir(os.path.join(self._tmpdir, 'tree'))
133
136
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
134
137
self._import_symlink)
160
163
tree.import_(msg)
161
164
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
163
def make_utf8_log(self):
164
self._utf8 = 'demo@DONOTUSE/c--utf8--0'
165
os.mkdir(os.path.join(self._tmpdir, 'tree'))
166
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
168
msg = tree.log_message()
169
msg["summary"] = u"I am importing now\u1234".encode('utf-8')
171
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
173
166
def make_missing_ancestor(self):
174
167
self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
175
168
self._archive = make_archive('demo-gone@DONOTUSE',
176
169
str(self._archivegoneroot))
177
170
self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
178
171
self._missing_import_bzr = revision_id(self._missing_import
180
173
self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
181
174
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
183
176
os.mkdir(os.path.join(self._tmpdir, 'tree'))
184
177
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
185
178
self._missing_import)
199
192
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
200
193
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
202
pybaz.Version(self._missing_import), None)
195
pybaz.Version(self._missing_import))
203
196
# and make it inaccessible
204
197
pybaz.Archive('demo-gone@DONOTUSE').unregister()
206
199
def make_inbranch_continuation(self):
207
200
self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
208
201
self._inbranch_tag_base = self._inbranch_tag + '--base-0'
209
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
202
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base)
211
203
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
212
204
pybaz.Version(self._inbranch_tag))
213
205
self._inbranch_tag_head = self._inbranch_tag + '--patch-1'
214
self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head,
206
self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head)
216
207
pybaz.Revision(self._inbranch_tag_base).make_continuation(
217
208
pybaz.Version(self._inbranch_tag))
237
228
def tearDown(self):
238
229
ResourcedTestCase.tearDownResources(self)
239
230
TestCaseInTempDir.tearDown(self)
241
def test_import_utf8(self):
242
import_version('output', pybaz.Version(self._baz._utf8), None)
243
branch = Branch.open('output')
244
plain_revid = 'Arch-1:demo@DONOTUSE%c--utf8--0--base-0'
245
self.assertEqual([plain_revid], branch.revision_history())
246
self.assertEqual(u'I am importing now\ufffd\ufffd\ufffd',
247
branch.repository.get_revision(plain_revid).message)
248
import_version('output2', pybaz.Version(self._baz._utf8), 'utf-8')
249
branch2 = Branch.open('output2')
250
utf8_revid = 'Arch-1-utf-8:demo@DONOTUSE%c--utf8--0--base-0'
251
self.assertEqual([utf8_revid], branch2.revision_history())
252
self.assertEqual(u'I am importing now\u1234',
253
branch2.repository.get_revision(utf8_revid).message)
255
232
def test_import_empty(self):
256
import_version('output', pybaz.Version(self._baz._import), None)
233
import_version('output', pybaz.Version(self._baz._import))
257
234
# expected results:
258
235
# one commit, no files, revision identifier of
259
236
# 'demo@DONOTUSE_c--import--0--base-0'
263
240
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
264
241
rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
266
import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
243
import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
268
244
branch2 = Branch.open('output2')
269
245
repo2 = branch2.repository
270
246
self.assertEqual(branch.revision_history(), branch2.revision_history())
279
255
"Arch-1:demo@DONOTUSE%c--import--0--base-0")
281
257
def test_empty_tagged(self):
282
import_version('output', pybaz.Version(self._baz._empty_tag), None)
258
import_version('output', pybaz.Version(self._baz._empty_tag))
283
259
# expected results:
284
260
# two commits, no files, revision identifiers of
285
261
# 'demo@DONOTUSE_c--import--0--base-0' and
290
266
self._baz._empty_tag_bzr])
291
267
rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
293
import_version('output2', pybaz.Version(self._baz._empty_tag), None)
269
import_version('output2', pybaz.Version(self._baz._empty_tag))
294
270
branch2 = Branch.open('output2')
295
271
self.assertEqual(branch.revision_history(), branch2.revision_history())
296
272
rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
304
280
self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
306
282
def test_empty_merged_tagged(self):
307
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
283
import_version('output', pybaz.Version(self._baz._empty_merged_tag))
309
284
# expected results:
310
285
# two commits, no files, revision identifiers of
311
286
# 'demo@DONOTUSE_c--import--0--base-0' and
320
295
self._baz._empty_merged_tag_bzr_base,
321
296
self._baz._empty_merged_tag_bzr])
323
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
298
import_version('output2', pybaz.Version(self._baz._empty_merged_tag))
325
299
branch2 = Branch.open('output2')
326
300
repo2 = branch2.repository
327
301
# and import what we should be merged up against for checking with.
328
import_version('output3', pybaz.Version(self._baz._empty_tag), None)
302
import_version('output3', pybaz.Version(self._baz._empty_tag))
329
303
branch3 = Branch.open('output3')
331
305
self.assertEqual(branch.revision_history(), branch2.revision_history())
362
336
# self.assertEqual(branch.missing_revisions(branch3), [])
364
338
def test_merge_branch_with_merges(self):
365
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
339
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2))
367
340
# expected results:
368
341
# two commits, no files, revision identifiers of
369
342
# 'demo@DONOTUSE_c--import--0--base-0' and
378
351
self._baz._empty_merged_tag_2_bzr_base,
379
352
self._baz._empty_merged_tag_2_bzr])
381
import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
354
import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2))
383
355
branch2 = Branch.open('output2')
384
356
repo2 = branch2.repository
385
357
# and import what we should be merged up against for checking with.
386
import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
358
import_version('output3', pybaz.Version(self._baz._empty_merged_tag))
388
359
branch3 = Branch.open('output3')
390
361
self.assertEqual(branch.revision_history(), branch2.revision_history())
423
394
def test_import_symlink(self):
424
395
import_version('output', pybaz.Version(self._baz._import_symlink),
426
397
# expected results:
427
398
# two commits, no files, revision identifier of
428
399
# 'demo@DONOTUSE_c--import--0--base-0'
432
403
rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
434
405
import_version('output2', pybaz.Version(self._baz._import_symlink),
436
407
branch2 = Branch.open('output2')
437
408
self.assertEqual(branch.revision_history(), branch2.revision_history())
438
409
rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
451
422
self.assertEqual(entry.kind, 'symlink')
452
423
self.assertEqual(entry.symlink_target, 'missing-file-name')
454
# Test kind change for import
455
import_version('output3', pybaz.Version(self._baz._import_symlink),
425
# current bzr doesn't handle type changes
426
self.assertRaises(AssertionError, import_version, 'output3',
427
pybaz.Version(self._baz._import_symlink))
458
429
def test_missing_ancestor(self):
459
import_version('output', pybaz.Version(self._baz._missing_ancestor),
430
import_version('output', pybaz.Version(self._baz._missing_ancestor))
461
431
# expected results:
462
432
# one commits, no files, revision identifiers of
463
433
# 'demo@DONOTUSE_c--gone--0--base-0' and
467
437
[self._baz._missing_ancestor_bzr])
468
438
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
470
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
440
import_version('output2', pybaz.Version(self._baz._missing_ancestor))
472
441
branch2 = Branch.open('output2')
473
442
self.assertEqual(branch.revision_history(), branch2.revision_history())
474
443
rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
490
459
def test_missing_ancestor_reusing_history(self):
491
460
import_version('output', pybaz.Version(self._baz._missing_ancestor),
493
461
reuse_history_from=[self._baz._missing_import_imported])
494
462
# expected results:
495
463
# one commits, no files, revision identifiers of
502
470
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
504
472
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
506
473
reuse_history_from=[self._baz._missing_import_imported])
507
474
branch2 = Branch.open('output2')
508
475
self.assertEqual(branch.revision_history(), branch2.revision_history())
522
489
self.assertEqual(1, len(rev.parent_ids))
524
491
def test_bad_file_id(self):
525
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
492
import_version('output', pybaz.Version(self._baz._bad_id_tag))
526
493
# expected results:
527
494
# three commits, one files, revision identifiers of
528
495
# 'demo@DONOTUSE_c--import--0--base-0' ,
539
506
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
541
508
def test_appending_revisions_already_present(self):
542
import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
509
import_version('output', pybaz.Version(self._baz._bad_id_tag),
544
511
# expected results:
545
512
# three commits, one files, revision identifiers of
557
524
self.assertEqual(branch.revision_history(),
558
525
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
560
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
527
import_version('output', pybaz.Version(self._baz._bad_id_tag))
561
528
branch = Branch.open('output')
562
529
self.assertEqual(branch.revision_history(),
563
530
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
569
536
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
571
538
def test_appending_revisions_all_already_present(self):
572
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
539
import_version('output', pybaz.Version(self._baz._bad_id_tag))
573
540
# expected results:
574
541
# three commits, one files, revision identifiers of
575
542
# 'demo@DONOTUSE_c--import--0--base-0' ,
587
554
self.assertEqual(branch.revision_history(),
588
555
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
590
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
557
import_version('output', pybaz.Version(self._baz._bad_id_tag))
591
558
branch = Branch.open('output')
592
559
self.assertEqual(branch.revision_history(),
593
560
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
599
566
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
601
568
def test_inbranch_conversion(self):
602
import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
569
import_version('output', pybaz.Version(self._baz._inbranch_tag))
603
570
# expected results:
604
571
# three commits, no files, revision identifiers of
605
572
# 'demo@DONOTUSE_c--import--0--base-0' and
612
579
self._baz._inbranch_tag_base_bzr,
613
580
self._baz._inbranch_tag_head_bzr])
615
import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
582
import_version('output2', pybaz.Version(self._baz._inbranch_tag))
616
583
branch2 = Branch.open('output2')
618
585
self.assertEqual(branch.revision_history(), branch2.revision_history())
644
611
branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
645
import_version(path, pybaz.Version(self._baz._import), None)
612
import_version(path, pybaz.Version(self._baz._import))
646
613
# expected results:
647
614
# one commit, revision identifier of
648
615
# 'demo@DONOTUSE_c--import--0--base-0'
734
701
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
736
703
def test_cmd_exists(self):
737
from bzrlib.plugins.bzrtools import cmd_baz_import
704
from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
739
706
def test_empty_archive(self):
740
707
command = cmd_baz_import()
754
721
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
755
722
'c1', '0.2','branch')))
756
default_format = repository.RepositoryFormat.get_default_format()
757
if getattr(default_format, 'rich_root_data', False):
761
723
walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
762
self.assertEqual(num_files, walk_len)
724
self.assertEqual(20, walk_len)
764
726
def test_run_twice(self):
765
727
self.make_import('c--0')
777
739
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
780
def test_does_not_need_reuse_history(self):
781
self.make_import('c--0')
782
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
785
def test_encoding_flag(self):
786
self.make_import('c--0')
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,
791
'output/c/+trunk')).revision_history())
792
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output2'),
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,
796
'output2/c/+trunk')).revision_history())
797
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir, 'output3'),
798
'demo@DONOTUSE/c--0')
799
self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
800
Branch.open(os.path.join(self._tmpdir,
801
'output3')).revision_history())
802
self.run_bzr('baz-import-branch', os.path.join(self._tmpdir,
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,
806
'output4')).revision_history())