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
34
39
from bzrlib.plugins.bzrtools.fai import namespace_previous
35
40
from bzrlib.branch import Branch
55
60
os.environ['HOME'] = self._homedir
57
62
self._archiveroot = os.path.join(self._tmpdir, 'archive')
58
self._archive = pybaz.make_archive('demo@DONOTUSE', str(self._archiveroot))
63
self._archive = make_archive('demo@DONOTUSE', str(self._archiveroot))
59
64
pybaz.set_my_id("Test User<test@example.org>")
61
66
self.make_empty_import()
63
69
self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
64
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
70
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0', None)
65
71
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
66
72
pybaz.Version(self._empty_tag))
68
74
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
69
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
71
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
75
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
77
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
73
79
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
74
80
pybaz.Version(self._empty_merged_tag))
75
81
tree = pybaz.Revision(self._empty_merged_tag + '--base-0').get(
80
86
msg["summary"]="did a merge, yarh"
82
88
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
84
90
# tree, two commits, includes merge of other branch
85
91
self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
86
self._empty_merged_tag_2_bzr_base = revision_id(self._empty_merged_tag_2 + '--base-0')
87
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)
88
96
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
89
97
pybaz.Version(self._empty_merged_tag_2))
90
98
tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
97
105
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
99
107
self._bad_id_tag = 'demo@DONOTUSE/c--bad-id--0'
100
self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0')
101
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',
102
112
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
103
113
pybaz.Version(self._bad_id_tag))
104
114
tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
105
115
os.path.join(self._tmpdir, 'tree'))
106
116
from bzrlib.plugins.bzrtools.baz_import import add_file
107
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')
108
119
msg = tree.log_message()
109
120
msg["summary"] = "commit something which needs escaping."
113
124
self.make_import_symlink()
114
125
self.make_missing_ancestor()
126
self.make_inbranch_continuation()
116
128
def make_import_symlink(self):
117
129
self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
118
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)
119
132
os.mkdir(os.path.join(self._tmpdir, 'tree'))
120
133
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
121
134
self._import_symlink)
122
os.symlink('missing-file-name',
123
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)
124
137
tree.add_tag('alink')
125
138
id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
126
139
id_file.write('symlink_tag\n')
128
141
msg = tree.log_message()
129
142
msg["summary"] = "Import with a symlink"
130
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"
131
151
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
133
153
def make_empty_import(self):
134
154
self._import = 'demo@DONOTUSE/c--import--0'
135
155
os.mkdir(os.path.join(self._tmpdir, 'tree'))
136
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), self._import)
156
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
137
158
msg = tree.log_message()
138
159
msg["summary"] = "I am importing now"
139
160
tree.import_(msg)
140
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'))
142
173
def make_missing_ancestor(self):
143
174
self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
144
self._archive = pybaz.make_archive('demo-gone@DONOTUSE',
145
str(self._archivegoneroot))
175
self._archive = make_archive('demo-gone@DONOTUSE',
176
str(self._archivegoneroot))
146
177
self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
147
self._missing_import_bzr = revision_id(self._missing_import
178
self._missing_import_bzr = revision_id(self._missing_import
149
180
self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
150
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
181
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
152
183
os.mkdir(os.path.join(self._tmpdir, 'tree'))
153
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
184
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
154
185
self._missing_import)
155
186
msg = tree.log_message()
156
187
msg["summary"] = "I am importing now"
161
192
pybaz.Version(self._missing_ancestor))
163
194
# make an import for testing history-reuse logic.
166
195
# note the use of a namespace layout here.
167
self._missing_import_imported = os.path.join(self._tmpdir,
196
self._missing_import_imported = os.path.join(self._tmpdir,
168
197
'archivegone-bzr')
169
198
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr'))
170
199
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
171
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
200
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
173
pybaz.Version(self._missing_import),
202
pybaz.Version(self._missing_import), None)
175
203
# and make it inaccessible
176
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))
179
220
def _makeResource(self):
180
221
return BazTreeResource()
192
233
TestCaseInTempDir.setUp(self)
193
234
ResourcedTestCase.setUpResources(self)
194
235
os.environ['HOME'] = self._baz._homedir
195
self.output = StringIO()
197
237
def tearDown(self):
198
238
ResourcedTestCase.tearDownResources(self)
199
239
TestCaseInTempDir.tearDown(self)
201
def collect(self, text):
202
self.output.write(text)
203
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)
205
255
def test_import_empty(self):
206
import_version('output', pybaz.Version(self._baz._import), self.collect)
256
import_version('output', pybaz.Version(self._baz._import), None)
207
257
# expected results:
208
# 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'
209
260
branch = Branch.open('output')
261
repo = branch.repository
210
262
self.assertEqual(branch.revision_history(),
211
263
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
212
rev = branch.repository.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')
214
266
import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
216
268
branch2 = Branch.open('output2')
269
repo2 = branch2.repository
217
270
self.assertEqual(branch.revision_history(), branch2.revision_history())
218
rev2 = branch2.repository.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')
219
272
# they must be the same
220
273
self.assertEqual(rev, rev2)
226
279
"Arch-1:demo@DONOTUSE%c--import--0--base-0")
228
281
def test_empty_tagged(self):
229
import_version('output', pybaz.Version(self._baz._empty_tag),
282
import_version('output', pybaz.Version(self._baz._empty_tag), None)
231
283
# expected results:
232
# two commits, no files, revision identifiers of
284
# two commits, no files, revision identifiers of
233
285
# 'demo@DONOTUSE_c--import--0--base-0' and
234
286
# self._baz._empty_tag_bzr
235
287
branch = Branch.open('output')
249
300
# and we should get some expected values:
250
301
self.assertEqual(rev.committer, "Test User<test@example.org>")
251
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")
252
304
self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
254
306
def test_empty_merged_tagged(self):
255
307
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
257
309
# expected results:
258
# two commits, no files, revision identifiers of
310
# two commits, no files, revision identifiers of
259
311
# 'demo@DONOTUSE_c--import--0--base-0' and
260
312
# self._baz._empty_merged_tag_bzr_base
261
313
# self._baz._empty_merged_tag_bzr
262
314
# and a merged revision from the latter of
263
315
# self._baz._empty_tag_bzr
264
316
branch = Branch.open('output')
317
repo = branch.repository
265
318
self.assertEqual(branch.revision_history(),
266
319
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
267
320
self._baz._empty_merged_tag_bzr_base,
268
321
self._baz._empty_merged_tag_bzr])
270
323
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
272
325
branch2 = Branch.open('output2')
326
repo2 = branch2.repository
273
327
# and import what we should be merged up against for checking with.
274
import_version('output3', pybaz.Version(self._baz._empty_tag),
328
import_version('output3', pybaz.Version(self._baz._empty_tag), None)
276
329
branch3 = Branch.open('output3')
278
331
self.assertEqual(branch.revision_history(), branch2.revision_history())
279
self.assertNotEqual(branch.revision_history(), branch3.revision_history())
332
self.assertNotEqual(branch.revision_history(),
333
branch3.revision_history())
280
334
# check revisions in the history.
281
rev = branch.repository.get_revision(self._baz._empty_merged_tag_bzr_base)
282
rev2 = branch2.repository.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)
283
337
# they must be the same
284
338
self.assertEqual(rev, rev2)
285
339
# and we should get some expected values:
286
340
self.assertEqual(rev.committer, "Test User<test@example.org>")
287
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")
288
343
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
289
344
self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
292
347
# check next revisions in the history.
293
rev = branch.repository.get_revision(self._baz._empty_merged_tag_bzr)
294
rev2 = branch2.repository.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)
295
350
# they must be the same
296
351
self.assertEqual(rev, rev2)
297
352
# and we should get some expected values:
302
357
self._baz._empty_merged_tag_bzr_base)
303
358
self.assertEqual(rev.parent_ids[1], self._baz._empty_tag_bzr)
305
# this tree should have nothing missing from that tree.
360
# this tree should have nothing missing from that tree.
306
361
# FIXME there is no code for this right now.
307
362
# self.assertEqual(branch.missing_revisions(branch3), [])
309
364
def test_merge_branch_with_merges(self):
310
365
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
312
367
# expected results:
313
# two commits, no files, revision identifiers of
368
# two commits, no files, revision identifiers of
314
369
# 'demo@DONOTUSE_c--import--0--base-0' and
315
370
# self._baz._empty_merged_tag_2_bzr_base
316
371
# self._baz._empty_merged_tag_2_bzr
317
372
# and a merged revision from the latter of
318
373
# self._baz._empty_merged_tag_bzr
319
374
branch = Branch.open('output')
375
repo = branch.repository
320
376
self.assertEqual(branch.revision_history(),
321
377
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
322
378
self._baz._empty_merged_tag_2_bzr_base,
323
379
self._baz._empty_merged_tag_2_bzr])
325
381
import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
327
383
branch2 = Branch.open('output2')
384
repo2 = branch2.repository
328
385
# and import what we should be merged up against for checking with.
329
386
import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
331
388
branch3 = Branch.open('output3')
333
390
self.assertEqual(branch.revision_history(), branch2.revision_history())
334
self.assertNotEqual(branch.revision_history(), branch3.revision_history())
391
self.assertNotEqual(branch.revision_history(),
392
branch3.revision_history())
335
393
# check revisions in the history.
336
rev = branch.repository.get_revision(self._baz._empty_merged_tag_2_bzr_base)
337
rev2 = branch2.repository.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)
338
396
# they must be the same
339
397
self.assertEqual(rev, rev2)
340
398
# and we should get some expected values:
341
399
self.assertEqual(rev.committer, "Test User<test@example.org>")
342
self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
343
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)
345
405
# check next revisions in the history.
346
rev = branch.repository.get_revision(self._baz._empty_merged_tag_2_bzr)
347
rev2 = branch2.repository.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)
348
408
# they must be the same
349
409
self.assertEqual(rev, rev2)
350
410
# and we should get some expected values:
356
416
self.assertEqual(rev.parent_ids[1],
357
417
self._baz._empty_merged_tag_bzr)
359
# this tree should have nothing missing from that tree.
419
# this tree should have nothing missing from that tree.
360
420
# FIXME there is no code for this right now.
361
421
# self.assertEqual(branch.missing_revisions(branch3), [])
363
423
def test_import_symlink(self):
364
424
import_version('output', pybaz.Version(self._baz._import_symlink),
366
426
# expected results:
367
# 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'
368
429
branch = Branch.open('output')
369
430
self.assertEqual(branch.revision_history(),
370
431
[self._baz._import_symlink_bzr])
371
432
rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
373
434
import_version('output2', pybaz.Version(self._baz._import_symlink),
375
436
branch2 = Branch.open('output2')
376
437
self.assertEqual(branch.revision_history(), branch2.revision_history())
377
438
rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
390
451
self.assertEqual(entry.kind, 'symlink')
391
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),
393
458
def test_missing_ancestor(self):
394
459
import_version('output', pybaz.Version(self._baz._missing_ancestor),
396
461
# expected results:
397
# one commits, no files, revision identifiers of
462
# one commits, no files, revision identifiers of
398
463
# 'demo@DONOTUSE_c--gone--0--base-0' and
399
464
# a merge of demo-gone@DONOTUSE%c--import--0
400
465
branch = Branch.open('output')
413
478
# and we should get some expected values:
414
479
self.assertEqual(rev.committer, "Test User<test@example.org>")
415
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")
416
482
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
417
483
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
418
484
self.assertEqual(1, len(rev.parent_ids))
420
486
# must NOT be able to get the merged evision
421
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
487
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
422
488
self._baz._missing_import_bzr)
424
490
def test_missing_ancestor_reusing_history(self):
425
491
import_version('output', pybaz.Version(self._baz._missing_ancestor),
427
493
reuse_history_from=[self._baz._missing_import_imported])
428
494
# expected results:
429
# one commits, no files, revision identifiers of
430
# 'demo-gone@DONOTUSE%c--import--0--base-0' and
495
# one commits, no files, revision identifiers of
496
# 'demo-gone@DONOTUSE%c--import--0--base-0' and
431
497
# 'demo@DONOTUSE%c--gone--0--base-0'
432
498
branch = Branch.open('output')
433
499
self.assertEqual(branch.revision_history(),
450
516
# and we should get some expected values:
451
517
self.assertEqual(rev.committer, "Test User<test@example.org>")
452
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")
453
520
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
454
521
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
455
522
self.assertEqual(1, len(rev.parent_ids))
457
524
def test_bad_file_id(self):
458
import_version('output', pybaz.Version(self._baz._bad_id_tag),
525
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
460
526
# expected results:
461
# three commits, one files, revision identifiers of
527
# three commits, one files, revision identifiers of
462
528
# 'demo@DONOTUSE_c--import--0--base-0' ,
463
529
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
464
530
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
473
539
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
475
541
def test_appending_revisions_already_present(self):
476
import_version('output', pybaz.Version(self._baz._bad_id_tag),
477
self.collect, max_count=2)
542
import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
478
544
# expected results:
479
# three commits, one files, revision identifiers of
545
# three commits, one files, revision identifiers of
480
546
# 'demo@DONOTUSE_c--import--0--base-0' ,
481
547
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
482
548
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
504
569
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
506
571
def test_appending_revisions_all_already_present(self):
507
import_version('output', pybaz.Version(self._baz._bad_id_tag),
572
import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
509
573
# expected results:
510
# three commits, one files, revision identifiers of
574
# three commits, one files, revision identifiers of
511
575
# 'demo@DONOTUSE_c--import--0--base-0' ,
512
576
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
513
577
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
535
598
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
536
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'])
539
653
class TestNamespacePrevious(TestCase):
613
726
def make_import(self, namespace):
614
727
self._import = 'demo@DONOTUSE/%s' % namespace
615
728
os.mkdir(os.path.join(self._tmpdir, 'tree'))
616
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), self._import)
729
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
617
731
msg = tree.log_message()
618
732
msg["summary"] = "I am importing now"
619
733
tree.import_(msg)
620
734
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
622
736
def test_cmd_exists(self):
623
from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
737
from bzrlib.plugins.bzrtools import cmd_baz_import
625
739
def test_empty_archive(self):
626
740
command = cmd_baz_import()
627
741
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
628
742
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
630
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)
632
746
def test_two_branches(self):
633
747
self.make_import('c--0')
635
749
command = cmd_baz_import()
636
750
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
637
751
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
638
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 'c','+trunk')))
639
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 'c1', '0.2','branch')))
641
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)
643
764
def test_run_twice(self):
644
765
self.make_import('c--0')
645
766
command = cmd_baz_import()
646
767
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
647
768
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
649
770
def test_accepts_reuse_history(self):
650
771
self.make_import('c--0')
651
772
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
652
773
'demo@DONOTUSE', '.', '.')
654
def test_does_not_need_reuse_history(self):
655
self.make_import('c--0')
656
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
775
def test_does_not_need_reuse_history(self):
776
self.make_import('c--0')
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())