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