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
19
20
from bzrlib.osutils import has_symlinks
22
23
except ImportError:
25
from bzrlib.plugins.bzrtools.baz_import import (import_version, revision_id,
27
from bzrlib.errors import NoSuchRevision
26
from bzrlib.plugins.bzrtools import cmd_baz_import
27
from bzrlib.plugins.bzrtools.baz_import import (import_version,
29
32
from StringIO import StringIO
31
34
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
38
from bzrlib.errors import NoSuchRevision
33
39
from bzrlib.plugins.bzrtools.fai import namespace_previous
34
40
from bzrlib.branch import Branch
38
return OptimisingTestSuite()
44
from unittest import TestSuite
39
46
return TestLoader().loadTestsFromName(__name__)
53
60
os.environ['HOME'] = self._homedir
55
62
self._archiveroot = os.path.join(self._tmpdir, 'archive')
56
self._archive = pybaz.make_archive('demo@DONOTUSE', str(self._archiveroot))
63
self._archive = make_archive('demo@DONOTUSE', str(self._archiveroot))
57
64
pybaz.set_my_id("Test User<test@example.org>")
59
66
self.make_empty_import()
61
69
self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
62
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
70
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0', None)
63
71
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
64
72
pybaz.Version(self._empty_tag))
66
74
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
67
75
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
69
77
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
71
79
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
72
80
pybaz.Version(self._empty_merged_tag))
73
81
tree = pybaz.Revision(self._empty_merged_tag + '--base-0').get(
82
90
# tree, two commits, includes merge of other branch
83
91
self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
84
self._empty_merged_tag_2_bzr_base = revision_id(self._empty_merged_tag_2 + '--base-0')
85
self._empty_merged_tag_2_bzr = revision_id(self._empty_merged_tag_2 + '--patch-1')
92
self._empty_merged_tag_2_bzr_base = revision_id(
93
self._empty_merged_tag_2 + '--base-0', None)
94
self._empty_merged_tag_2_bzr = revision_id(
95
self._empty_merged_tag_2 + '--patch-1', None)
86
96
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
87
97
pybaz.Version(self._empty_merged_tag_2))
88
98
tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
95
105
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
97
107
self._bad_id_tag = 'demo@DONOTUSE/c--bad-id--0'
98
self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0')
99
self._bad_id_tag_bzr = revision_id(self._bad_id_tag + '--patch-1')
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',
100
112
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
101
113
pybaz.Version(self._bad_id_tag))
102
114
tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
103
115
os.path.join(self._tmpdir, 'tree'))
104
116
from bzrlib.plugins.bzrtools.baz_import import add_file
105
add_file(os.path.join(self._tmpdir,'tree/path'), 'text', 'this_id/needs%escaping')
117
add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
118
'this_id/needs%escaping')
106
119
msg = tree.log_message()
107
120
msg["summary"] = "commit something which needs escaping."
111
124
self.make_import_symlink()
112
125
self.make_missing_ancestor()
126
self.make_inbranch_continuation()
114
128
def make_import_symlink(self):
115
129
self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
116
self._import_symlink_bzr = revision_id(self._import_symlink + '--base-0')
130
self._import_symlink_bzr = revision_id(
131
self._import_symlink + '--base-0', None)
117
132
os.mkdir(os.path.join(self._tmpdir, 'tree'))
118
133
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
119
134
self._import_symlink)
120
os.symlink('missing-file-name',
121
os.path.join(self._tmpdir, 'tree', 'alink'))
135
link_path = os.path.join(self._tmpdir, 'tree', 'alink')
136
os.symlink('missing-file-name', link_path)
122
137
tree.add_tag('alink')
123
138
id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
124
139
id_file.write('symlink_tag\n')
126
141
msg = tree.log_message()
127
142
msg["summary"] = "Import with a symlink"
128
143
tree.import_(msg)
145
f = file(link_path, 'w')
146
f.write('Not a symlink no more!')
148
msg = tree.log_message()
149
msg["summary"] = "Turn a symlink into a file"
129
151
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
131
153
def make_empty_import(self):
132
154
self._import = 'demo@DONOTUSE/c--import--0'
133
155
os.mkdir(os.path.join(self._tmpdir, 'tree'))
134
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), self._import)
156
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
135
158
msg = tree.log_message()
136
159
msg["summary"] = "I am importing now"
137
160
tree.import_(msg)
138
161
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'))
140
173
def make_missing_ancestor(self):
141
174
self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
142
self._archive = pybaz.make_archive('demo-gone@DONOTUSE',
143
str(self._archivegoneroot))
175
self._archive = make_archive('demo-gone@DONOTUSE',
176
str(self._archivegoneroot))
144
177
self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
145
178
self._missing_import_bzr = revision_id(self._missing_import
147
180
self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
148
181
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
150
183
os.mkdir(os.path.join(self._tmpdir, 'tree'))
151
184
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
152
185
self._missing_import)
168
199
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
169
200
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
171
pybaz.Version(self._missing_import),
202
pybaz.Version(self._missing_import), None)
173
203
# and make it inaccessible
174
204
pybaz.Archive('demo-gone@DONOTUSE').unregister()
206
def make_inbranch_continuation(self):
207
self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
208
self._inbranch_tag_base = self._inbranch_tag + '--base-0'
209
self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
211
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
212
pybaz.Version(self._inbranch_tag))
213
self._inbranch_tag_head = self._inbranch_tag + '--patch-1'
214
self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head,
216
pybaz.Revision(self._inbranch_tag_base).make_continuation(
217
pybaz.Version(self._inbranch_tag))
177
220
def _makeResource(self):
178
221
return BazTreeResource()
190
233
TestCaseInTempDir.setUp(self)
191
234
ResourcedTestCase.setUpResources(self)
192
235
os.environ['HOME'] = self._baz._homedir
193
self.output = StringIO()
195
237
def tearDown(self):
196
238
ResourcedTestCase.tearDownResources(self)
197
239
TestCaseInTempDir.tearDown(self)
199
def collect(self, text):
200
self.output.write(text)
201
self.output.write("\n")
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)
203
255
def test_import_empty(self):
204
import_version('output', pybaz.Version(self._baz._import), self.collect)
256
import_version('output', pybaz.Version(self._baz._import), None)
205
257
# expected results:
206
# one commit, no files, revision identifier of 'demo@DONOTUSE_c--import--0--base-0'
258
# one commit, no files, revision identifier of
259
# 'demo@DONOTUSE_c--import--0--base-0'
207
260
branch = Branch.open('output')
261
repo = branch.repository
208
262
self.assertEqual(branch.revision_history(),
209
263
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
210
rev = branch.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
264
rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
212
266
import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
214
268
branch2 = Branch.open('output2')
269
repo2 = branch2.repository
215
270
self.assertEqual(branch.revision_history(), branch2.revision_history())
216
rev2 = branch2.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
271
rev2 = repo2.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
217
272
# they must be the same
218
273
self.assertEqual(rev, rev2)
234
288
self.assertEqual(branch.revision_history(),
235
289
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
236
290
self._baz._empty_tag_bzr])
237
rev = branch.get_revision(self._baz._empty_tag_bzr)
291
rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
239
import_version('output2', pybaz.Version(self._baz._empty_tag),
293
import_version('output2', pybaz.Version(self._baz._empty_tag), None)
241
294
branch2 = Branch.open('output2')
242
295
self.assertEqual(branch.revision_history(), branch2.revision_history())
243
rev2 = branch2.get_revision(self._baz._empty_tag_bzr)
296
rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
244
297
# they must be the same
245
298
self.assertEqual(rev, rev2)
247
300
# and we should get some expected values:
248
301
self.assertEqual(rev.committer, "Test User<test@example.org>")
249
self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
302
self.assertEqual(rev.message,
303
"tag of demo@DONOTUSE/c--import--0--base-0")
250
304
self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
252
306
def test_empty_merged_tagged(self):
253
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
307
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
255
309
# expected results:
256
310
# two commits, no files, revision identifiers of
257
311
# 'demo@DONOTUSE_c--import--0--base-0' and
260
314
# and a merged revision from the latter of
261
315
# self._baz._empty_tag_bzr
262
316
branch = Branch.open('output')
317
repo = branch.repository
263
318
self.assertEqual(branch.revision_history(),
264
319
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
265
320
self._baz._empty_merged_tag_bzr_base,
266
321
self._baz._empty_merged_tag_bzr])
268
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
323
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
270
325
branch2 = Branch.open('output2')
326
repo2 = branch2.repository
271
327
# and import what we should be merged up against for checking with.
272
import_version('output3', pybaz.Version(self._baz._empty_tag),
328
import_version('output3', pybaz.Version(self._baz._empty_tag), None)
274
329
branch3 = Branch.open('output3')
276
331
self.assertEqual(branch.revision_history(), branch2.revision_history())
277
self.assertNotEqual(branch.revision_history(), branch3.revision_history())
332
self.assertNotEqual(branch.revision_history(),
333
branch3.revision_history())
278
334
# check revisions in the history.
279
rev = branch.get_revision(self._baz._empty_merged_tag_bzr_base)
280
rev2 = branch2.get_revision(self._baz._empty_merged_tag_bzr_base)
335
rev = repo.get_revision(self._baz._empty_merged_tag_bzr_base)
336
rev2 = repo2.get_revision(self._baz._empty_merged_tag_bzr_base)
281
337
# they must be the same
282
338
self.assertEqual(rev, rev2)
283
339
# and we should get some expected values:
284
340
self.assertEqual(rev.committer, "Test User<test@example.org>")
285
self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
341
self.assertEqual(rev.message,
342
"tag of demo@DONOTUSE/c--import--0--base-0")
286
343
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
287
344
self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
290
347
# check next revisions in the history.
291
rev = branch.get_revision(self._baz._empty_merged_tag_bzr)
292
rev2 = branch2.get_revision(self._baz._empty_merged_tag_bzr)
348
rev = repo.get_revision(self._baz._empty_merged_tag_bzr)
349
rev2 = repo2.get_revision(self._baz._empty_merged_tag_bzr)
293
350
# they must be the same
294
351
self.assertEqual(rev, rev2)
295
352
# and we should get some expected values:
315
372
# and a merged revision from the latter of
316
373
# self._baz._empty_merged_tag_bzr
317
374
branch = Branch.open('output')
375
repo = branch.repository
318
376
self.assertEqual(branch.revision_history(),
319
377
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
320
378
self._baz._empty_merged_tag_2_bzr_base,
321
379
self._baz._empty_merged_tag_2_bzr])
323
381
import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
325
383
branch2 = Branch.open('output2')
384
repo2 = branch2.repository
326
385
# and import what we should be merged up against for checking with.
327
386
import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
329
388
branch3 = Branch.open('output3')
331
390
self.assertEqual(branch.revision_history(), branch2.revision_history())
332
self.assertNotEqual(branch.revision_history(), branch3.revision_history())
391
self.assertNotEqual(branch.revision_history(),
392
branch3.revision_history())
333
393
# check revisions in the history.
334
rev = branch.get_revision(self._baz._empty_merged_tag_2_bzr_base)
335
rev2 = branch2.get_revision(self._baz._empty_merged_tag_2_bzr_base)
394
rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr_base)
395
rev2 = repo2.get_revision(self._baz._empty_merged_tag_2_bzr_base)
336
396
# they must be the same
337
397
self.assertEqual(rev, rev2)
338
398
# and we should get some expected values:
339
399
self.assertEqual(rev.committer, "Test User<test@example.org>")
340
self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
341
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_2_bzr_base)
400
self.assertEqual(rev.message,
401
"tag of demo@DONOTUSE/c--import--0--base-0")
402
self.assertEqual(rev.revision_id,
403
self._baz._empty_merged_tag_2_bzr_base)
343
405
# check next revisions in the history.
344
rev = branch.get_revision(self._baz._empty_merged_tag_2_bzr)
345
rev2 = branch2.get_revision(self._baz._empty_merged_tag_2_bzr)
406
rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr)
407
rev2 = repo2.get_revision(self._baz._empty_merged_tag_2_bzr)
346
408
# they must be the same
347
409
self.assertEqual(rev, rev2)
348
410
# and we should get some expected values:
359
421
# self.assertEqual(branch.missing_revisions(branch3), [])
361
423
def test_import_symlink(self):
362
import_version('output', pybaz.Version(self._baz._import_symlink),
424
import_version('output', pybaz.Version(self._baz._import_symlink),
364
426
# expected results:
365
# one commit, no files, revision identifier of 'demo@DONOTUSE_c--import--0--base-0'
427
# two commits, no files, revision identifier of
428
# 'demo@DONOTUSE_c--import--0--base-0'
366
429
branch = Branch.open('output')
367
430
self.assertEqual(branch.revision_history(),
368
431
[self._baz._import_symlink_bzr])
369
rev = branch.get_revision(self._baz._import_symlink_bzr)
432
rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
371
434
import_version('output2', pybaz.Version(self._baz._import_symlink),
373
436
branch2 = Branch.open('output2')
374
437
self.assertEqual(branch.revision_history(), branch2.revision_history())
375
rev2 = branch2.get_revision(self._baz._import_symlink_bzr)
438
rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
376
439
# they must be the same
377
440
self.assertEqual(rev, rev2)
382
445
self.assertEqual(rev.revision_id, self._baz._import_symlink_bzr)
384
447
# and we want the symlink alink with target 'missing-file-name'
385
inv = branch.get_inventory(rev.revision_id)
448
inv = branch.repository.get_inventory(rev.revision_id)
386
449
self.assertEqual(inv.path2id('alink'), 'x_symlink_tag')
387
450
entry = inv['x_symlink_tag']
388
451
self.assertEqual(entry.kind, 'symlink')
389
452
self.assertEqual(entry.symlink_target, 'missing-file-name')
454
# Test kind change for import
455
import_version('output3', pybaz.Version(self._baz._import_symlink),
391
458
def test_missing_ancestor(self):
392
459
import_version('output', pybaz.Version(self._baz._missing_ancestor),
394
461
# expected results:
395
462
# one commits, no files, revision identifiers of
396
463
# 'demo@DONOTUSE_c--gone--0--base-0' and
398
465
branch = Branch.open('output')
399
466
self.assertEqual(branch.revision_history(),
400
467
[self._baz._missing_ancestor_bzr])
401
rev = branch.get_revision(self._baz._missing_ancestor_bzr)
468
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
403
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
470
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
405
472
branch2 = Branch.open('output2')
406
473
self.assertEqual(branch.revision_history(), branch2.revision_history())
407
rev2 = branch2.get_revision(self._baz._missing_ancestor_bzr)
474
rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
408
475
# they must be the same
409
476
self.assertEqual(rev, rev2)
411
478
# and we should get some expected values:
412
479
self.assertEqual(rev.committer, "Test User<test@example.org>")
413
self.assertEqual(rev.message, "tag of demo-gone@DONOTUSE/c--import--0--base-0")
480
self.assertEqual(rev.message,
481
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
414
482
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
415
483
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
416
484
self.assertEqual(1, len(rev.parent_ids))
418
486
# must NOT be able to get the merged evision
419
self.assertRaises(NoSuchRevision, branch.get_revision,
487
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
420
488
self._baz._missing_import_bzr)
422
490
def test_missing_ancestor_reusing_history(self):
423
491
import_version('output', pybaz.Version(self._baz._missing_ancestor),
425
493
reuse_history_from=[self._baz._missing_import_imported])
426
494
# expected results:
427
495
# one commits, no files, revision identifiers of
431
499
self.assertEqual(branch.revision_history(),
432
500
[self._baz._missing_import_bzr,
433
501
self._baz._missing_ancestor_bzr])
434
rev = branch.get_revision(self._baz._missing_ancestor_bzr)
502
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
436
504
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
438
506
reuse_history_from=[self._baz._missing_import_imported])
439
507
branch2 = Branch.open('output2')
440
508
self.assertEqual(branch.revision_history(), branch2.revision_history())
441
rev2 = branch2.get_revision(self._baz._missing_ancestor_bzr)
509
rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
442
510
# they must be the same
443
511
self.assertEqual(rev, rev2)
445
513
# must be able to get the missing base revision
446
branch.get_revision(self._baz._missing_import_bzr)
514
branch.repository.get_revision(self._baz._missing_import_bzr)
448
516
# and we should get some expected values:
449
517
self.assertEqual(rev.committer, "Test User<test@example.org>")
450
self.assertEqual(rev.message, "tag of demo-gone@DONOTUSE/c--import--0--base-0")
518
self.assertEqual(rev.message,
519
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
451
520
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
452
521
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
453
522
self.assertEqual(1, len(rev.parent_ids))
455
524
def test_bad_file_id(self):
456
import_version('output', pybaz.Version(self._baz._bad_id_tag),
525
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
458
526
# expected results:
459
527
# three commits, one files, revision identifiers of
460
528
# 'demo@DONOTUSE_c--import--0--base-0' ,
465
533
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
466
534
self._baz._bad_id_tag_bzr_base,
467
535
self._baz._bad_id_tag_bzr])
468
rev = branch.get_revision(self._baz._bad_id_tag_bzr)
469
inv = branch.get_inventory(self._baz._bad_id_tag_bzr)
536
rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
537
inv = branch.repository.get_inventory(self._baz._bad_id_tag_bzr)
470
538
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
471
539
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
473
541
def test_appending_revisions_already_present(self):
474
import_version('output', pybaz.Version(self._baz._bad_id_tag),
475
self.collect, max_count=2)
542
import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
476
544
# expected results:
477
545
# three commits, one files, revision identifiers of
478
546
# 'demo@DONOTUSE_c--import--0--base-0' ,
489
557
self.assertEqual(branch.revision_history(),
490
558
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
492
import_version('output', pybaz.Version(self._baz._bad_id_tag),
560
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
494
561
branch = Branch.open('output')
495
562
self.assertEqual(branch.revision_history(),
496
563
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
497
564
self._baz._bad_id_tag_bzr_base,
498
565
self._baz._bad_id_tag_bzr])
499
rev = branch.get_revision(self._baz._bad_id_tag_bzr)
500
inv = branch.get_inventory(self._baz._bad_id_tag_bzr)
566
rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
567
inv = branch.repository.get_inventory(self._baz._bad_id_tag_bzr)
501
568
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
502
569
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
504
571
def test_appending_revisions_all_already_present(self):
505
import_version('output', pybaz.Version(self._baz._bad_id_tag),
572
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
507
573
# expected results:
508
574
# three commits, one files, revision identifiers of
509
575
# 'demo@DONOTUSE_c--import--0--base-0' ,
521
587
self.assertEqual(branch.revision_history(),
522
588
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
524
import_version('output', pybaz.Version(self._baz._bad_id_tag),
590
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
526
591
branch = Branch.open('output')
527
592
self.assertEqual(branch.revision_history(),
528
593
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
529
594
self._baz._bad_id_tag_bzr_base,
530
595
self._baz._bad_id_tag_bzr])
531
rev = branch.get_revision(self._baz._bad_id_tag_bzr)
532
inv = branch.get_inventory(self._baz._bad_id_tag_bzr)
596
rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
597
inv = branch.repository.get_inventory(self._baz._bad_id_tag_bzr)
533
598
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
534
599
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
601
def test_inbranch_conversion(self):
602
import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
604
# three commits, no files, revision identifiers of
605
# 'demo@DONOTUSE_c--import--0--base-0' and
606
# self._baz._inbranch_tag_base_bzr
607
# self._baz._inbranch_tag_head_bzr
609
branch = Branch.open('output')
610
self.assertEqual(branch.revision_history(),
611
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
612
self._baz._inbranch_tag_base_bzr,
613
self._baz._inbranch_tag_head_bzr])
615
import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
616
branch2 = Branch.open('output2')
618
self.assertEqual(branch.revision_history(), branch2.revision_history())
619
# check revisions in the history.
620
rev = branch.repository.get_revision(self._baz._inbranch_tag_base_bzr)
621
rev2 = branch2.repository.get_revision(self._baz._inbranch_tag_base_bzr)
622
# they must be the same
623
self.assertEqual(rev, rev2)
624
# and we should get some expected values:
625
self.assertEqual(rev.committer, "Test User<test@example.org>")
626
self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
627
self.assertEqual(rev.revision_id, self._baz._inbranch_tag_base_bzr)
629
# check next revisions in the history.
630
rev = branch.repository.get_revision(self._baz._inbranch_tag_head_bzr)
631
rev2 = branch2.repository.get_revision(self._baz._inbranch_tag_head_bzr)
632
# they must be the same
633
self.assertEqual(rev, rev2)
634
# and we should get some expected values:
635
self.assertEqual(rev.committer, "Test User<test@example.org>")
636
self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--inbranch-tag--0--base-0")
637
self.assertEqual(rev.revision_id, self._baz._inbranch_tag_head_bzr)
638
self.assertEqual(rev.parent_ids,
639
[self._baz._inbranch_tag_base_bzr])
641
def test_no_commits_same_as_missing(self):
644
branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
645
import_version(path, pybaz.Version(self._baz._import), None)
647
# one commit, revision identifier of
648
# 'demo@DONOTUSE_c--import--0--base-0'
649
self.assertEqual(branch.revision_history(),
650
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
537
653
class TestNamespacePrevious(TestCase):
611
726
def make_import(self, namespace):
612
727
self._import = 'demo@DONOTUSE/%s' % namespace
613
728
os.mkdir(os.path.join(self._tmpdir, 'tree'))
614
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), self._import)
729
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
615
731
msg = tree.log_message()
616
732
msg["summary"] = "I am importing now"
617
733
tree.import_(msg)
618
734
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
620
736
def test_cmd_exists(self):
621
from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
737
from bzrlib.plugins.bzrtools import cmd_baz_import
623
739
def test_empty_archive(self):
624
740
command = cmd_baz_import()
625
741
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
626
742
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
628
len(list(os.walk(os.path.join(self._tmpdir,'output')))))
743
walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
744
self.assertEqual(7, walk_len)
630
746
def test_two_branches(self):
631
747
self.make_import('c--0')
633
749
command = cmd_baz_import()
634
750
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
635
751
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
636
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 'c','+trunk')))
637
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 'c1', '0.2','branch')))
639
len(list(os.walk(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',
755
'c1', '0.2','branch')))
756
default_format = repository.RepositoryFormat.get_default_format()
757
if getattr(default_format, 'rich_root_data', False):
761
walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
762
self.assertEqual(num_files, walk_len)
641
764
def test_run_twice(self):
642
765
self.make_import('c--0')
653
776
self.make_import('c--0')
654
777
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())