~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_baz_import.py

  • Committer: Aaron Bentley
  • Date: 2005-10-28 03:01:02 UTC
  • mfrom: (147.4.13)
  • mto: (147.4.24 trunk)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: aaron.bentley@utoronto.ca-20051028030102-eead1e484007de74
Merged lifeless

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    along with this program; if not, write to the Free Software
16
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
from bzrlib.tests import TestCaseInTempDir, TestCase
19
 
from bzrlib.osutils import has_symlinks
 
18
from bzrlib.selftest import TestCaseInTempDir, TestCase
 
19
from bzrlib.selftest.blackbox import has_symlinks
20
20
try:
21
21
    import pybaz
22
22
except ImportError:
23
23
    pybaz = None
24
24
import os
25
 
try:
26
 
    from bzrtools.baz_import import (import_version, revision_id,
27
 
                                     cmd_baz_import, make_archive, map_file_id)
28
 
except ImportError:
29
 
    from bzrlib.plugins.bzrtools.baz_import import (import_version, 
30
 
                                                    revision_id,
31
 
                                                    cmd_baz_import,
32
 
                                                    make_archive,
33
 
                                                    map_file_id)
 
25
from bzrlib.plugins.bzrtools.baz_import import (import_version, revision_id, 
 
26
                                                cmd_baz_import)
 
27
from bzrlib.errors import NoSuchRevision
34
28
import shutil
35
29
from StringIO import StringIO
36
30
import tempfile
37
31
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
38
 
                               ResourcedTestCase)
39
 
    
40
 
import bzrlib
41
 
from bzrlib.errors import NoSuchRevision
42
 
try:
43
 
    from bzrtools.fai import namespace_previous
44
 
except ImportError:
45
 
    from bzrlib.plugins.bzrtools.fai import namespace_previous
 
32
                           ResourcedTestCase)
 
33
from bzrlib.plugins.bzrtools.fai import namespace_previous
46
34
from bzrlib.branch import Branch
47
35
 
48
36
def test_suite():
49
37
    if pybaz is None:
50
 
        from unittest import TestSuite
51
 
        return TestSuite()
 
38
        return OptimisingTestSuite()
52
39
    return TestLoader().loadTestsFromName(__name__)
53
40
 
54
41
 
66
53
        os.environ['HOME'] = self._homedir
67
54
 
68
55
        self._archiveroot = os.path.join(self._tmpdir, 'archive')
69
 
        self._archive = make_archive('demo@DONOTUSE', str(self._archiveroot))
 
56
        self._archive = pybaz.make_archive('demo@DONOTUSE', str(self._archiveroot))
70
57
        pybaz.set_my_id("Test User<test@example.org>")
71
58
 
72
59
        self.make_empty_import()
94
81
        
95
82
        # tree, two commits, includes merge of other branch
96
83
        self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
97
 
        self._empty_merged_tag_2_bzr_base = revision_id(
98
 
            self._empty_merged_tag_2 + '--base-0')
99
 
        self._empty_merged_tag_2_bzr = revision_id(
100
 
            self._empty_merged_tag_2 + '--patch-1')
 
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')
101
86
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
102
87
            pybaz.Version(self._empty_merged_tag_2))
103
88
        tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
117
102
        tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
118
103
            os.path.join(self._tmpdir, 'tree'))
119
104
        from bzrlib.plugins.bzrtools.baz_import import add_file
120
 
        add_file(os.path.join(self._tmpdir,'tree/path'), 'text', 
121
 
                 'this_id/needs%escaping')
 
105
        add_file(os.path.join(self._tmpdir,'tree/path'), 'text', 'this_id/needs%escaping')
122
106
        msg = tree.log_message()
123
107
        msg["summary"] = "commit something which needs escaping."
124
108
        tree.commit(msg)
126
110
 
127
111
        self.make_import_symlink()
128
112
        self.make_missing_ancestor()
129
 
        self.make_inbranch_continuation()
130
113
 
131
114
    def make_import_symlink(self):
132
115
        self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
133
 
        self._import_symlink_bzr = revision_id(
134
 
            self._import_symlink + '--base-0')
 
116
        self._import_symlink_bzr = revision_id(self._import_symlink + '--base-0')
135
117
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
136
118
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
137
119
                               self._import_symlink)
138
 
        link_path = os.path.join(self._tmpdir, 'tree', 'alink')
139
 
        os.symlink('missing-file-name', link_path)
 
120
        os.symlink('missing-file-name',
 
121
                   os.path.join(self._tmpdir, 'tree', 'alink'))
140
122
        tree.add_tag('alink')
141
123
        id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
142
124
        id_file.write('symlink_tag\n')
144
126
        msg = tree.log_message()
145
127
        msg["summary"] = "Import with a symlink"
146
128
        tree.import_(msg)
147
 
        os.unlink(link_path)
148
 
        f = file(link_path, 'w')
149
 
        f.write('Not a symlink no more!')
150
 
        f.close()
151
 
        msg = tree.log_message()
152
 
        msg["summary"] = "Turn a symlink into a file"
153
 
        tree.commit(msg)
154
129
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
155
130
 
156
131
    def make_empty_import(self):
157
132
        self._import = 'demo@DONOTUSE/c--import--0'
158
133
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
159
 
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
160
 
                               self._import)
 
134
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), self._import)
161
135
        msg = tree.log_message()
162
136
        msg["summary"] = "I am importing now"
163
137
        tree.import_(msg)
165
139
 
166
140
    def make_missing_ancestor(self):
167
141
        self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
168
 
        self._archive = make_archive('demo-gone@DONOTUSE',
169
 
                                     str(self._archivegoneroot))
 
142
        self._archive = pybaz.make_archive('demo-gone@DONOTUSE',
 
143
                                           str(self._archivegoneroot))
170
144
        self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
171
145
        self._missing_import_bzr = revision_id(self._missing_import 
172
146
                                                 + '--base-0')
185
159
            pybaz.Version(self._missing_ancestor))
186
160
 
187
161
        # make an import for testing history-reuse logic.
 
162
        def collect(text):
 
163
            pass
188
164
        # note the use of a namespace layout here.
189
165
        self._missing_import_imported = os.path.join(self._tmpdir, 
190
166
                                                     'archivegone-bzr')
192
168
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
193
169
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr', 
194
170
                                    'c', 'import'),
195
 
                       pybaz.Version(self._missing_import))
 
171
                       pybaz.Version(self._missing_import),
 
172
                       collect)
196
173
        # and make it inaccessible
197
174
        pybaz.Archive('demo-gone@DONOTUSE').unregister()
198
175
 
199
 
    def make_inbranch_continuation(self):
200
 
        self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
201
 
        self._inbranch_tag_base = self._inbranch_tag + '--base-0'
202
 
        self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base)
203
 
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
204
 
            pybaz.Version(self._inbranch_tag))
205
 
        self._inbranch_tag_head = self._inbranch_tag + '--patch-1'
206
 
        self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head)
207
 
        pybaz.Revision(self._inbranch_tag_base).make_continuation(
208
 
            pybaz.Version(self._inbranch_tag))
209
 
 
210
176
    @classmethod
211
177
    def _makeResource(self):
212
178
        return BazTreeResource()
224
190
        TestCaseInTempDir.setUp(self)
225
191
        ResourcedTestCase.setUpResources(self)
226
192
        os.environ['HOME'] = self._baz._homedir
 
193
        self.output = StringIO()
227
194
 
228
195
    def tearDown(self):
229
196
        ResourcedTestCase.tearDownResources(self)
230
197
        TestCaseInTempDir.tearDown(self)
231
198
 
 
199
    def collect(self, text):
 
200
        self.output.write(text)
 
201
        self.output.write("\n")
 
202
 
232
203
    def test_import_empty(self):
233
 
        import_version('output', pybaz.Version(self._baz._import))
 
204
        import_version('output', pybaz.Version(self._baz._import), self.collect)
234
205
        # expected results:
235
 
        # one commit, no files, revision identifier of 
236
 
        # 'demo@DONOTUSE_c--import--0--base-0'
 
206
        # one commit, no files, revision identifier of 'demo@DONOTUSE_c--import--0--base-0'
237
207
        branch = Branch.open('output')
238
 
        repo = branch.repository
239
208
        self.assertEqual(branch.revision_history(),
240
209
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
241
 
        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')
242
211
        # and again.
243
 
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
 
212
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
 
213
                       self.collect)
244
214
        branch2 = Branch.open('output2')
245
 
        repo2 = branch2.repository
246
215
        self.assertEqual(branch.revision_history(), branch2.revision_history())
247
 
        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')
248
217
        # they must be the same
249
218
        self.assertEqual(rev, rev2)
250
219
 
255
224
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
256
225
 
257
226
    def test_empty_tagged(self):
258
 
        import_version('output', pybaz.Version(self._baz._empty_tag))
 
227
        import_version('output', pybaz.Version(self._baz._empty_tag),
 
228
                       self.collect)
259
229
        # expected results:
260
230
        # two commits, no files, revision identifiers of 
261
231
        # 'demo@DONOTUSE_c--import--0--base-0' and
264
234
        self.assertEqual(branch.revision_history(),
265
235
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
266
236
                          self._baz._empty_tag_bzr])
267
 
        rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
 
237
        rev = branch.get_revision(self._baz._empty_tag_bzr)
268
238
        # and again.
269
 
        import_version('output2', pybaz.Version(self._baz._empty_tag))
 
239
        import_version('output2', pybaz.Version(self._baz._empty_tag),
 
240
                       self.collect)
270
241
        branch2 = Branch.open('output2')
271
242
        self.assertEqual(branch.revision_history(), branch2.revision_history())
272
 
        rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
 
243
        rev2 = branch2.get_revision(self._baz._empty_tag_bzr)
273
244
        # they must be the same
274
245
        self.assertEqual(rev, rev2)
275
246
 
276
247
        # and we should get some expected values:
277
248
        self.assertEqual(rev.committer, "Test User<test@example.org>")
278
 
        self.assertEqual(rev.message, 
279
 
                         "tag of demo@DONOTUSE/c--import--0--base-0")
 
249
        self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
280
250
        self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
281
251
 
282
252
    def test_empty_merged_tagged(self):
283
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag))
 
253
        import_version('output', pybaz.Version(self._baz._empty_merged_tag),
 
254
                       self.collect)
284
255
        # expected results:
285
256
        # two commits, no files, revision identifiers of 
286
257
        # 'demo@DONOTUSE_c--import--0--base-0' and
289
260
        # and a merged revision from the latter of
290
261
        # self._baz._empty_tag_bzr
291
262
        branch = Branch.open('output')
292
 
        repo = branch.repository
293
263
        self.assertEqual(branch.revision_history(),
294
264
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
295
265
                          self._baz._empty_merged_tag_bzr_base,
296
266
                          self._baz._empty_merged_tag_bzr])
297
267
        # and again.
298
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag))
 
268
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
 
269
                       self.collect)
299
270
        branch2 = Branch.open('output2')
300
 
        repo2 = branch2.repository
301
271
        # and import what we should be merged up against for checking with.
302
 
        import_version('output3', pybaz.Version(self._baz._empty_tag))
 
272
        import_version('output3', pybaz.Version(self._baz._empty_tag),
 
273
                       self.collect)
303
274
        branch3 = Branch.open('output3')
304
275
        
305
276
        self.assertEqual(branch.revision_history(), branch2.revision_history())
306
 
        self.assertNotEqual(branch.revision_history(), 
307
 
                            branch3.revision_history())
 
277
        self.assertNotEqual(branch.revision_history(), branch3.revision_history())
308
278
        # check revisions in the history.
309
 
        rev = repo.get_revision(self._baz._empty_merged_tag_bzr_base)
310
 
        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)
311
281
        # they must be the same
312
282
        self.assertEqual(rev, rev2)
313
283
        # and we should get some expected values:
314
284
        self.assertEqual(rev.committer, "Test User<test@example.org>")
315
 
        self.assertEqual(rev.message, 
316
 
                         "tag of demo@DONOTUSE/c--import--0--base-0")
 
285
        self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
317
286
        self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
318
287
        self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
319
288
                         rev.parent_ids)
320
289
 
321
290
        # check next revisions in the history.
322
 
        rev = repo.get_revision(self._baz._empty_merged_tag_bzr)
323
 
        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)
324
293
        # they must be the same
325
294
        self.assertEqual(rev, rev2)
326
295
        # and we should get some expected values:
336
305
        # self.assertEqual(branch.missing_revisions(branch3), [])
337
306
        
338
307
    def test_merge_branch_with_merges(self):
339
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2))
 
308
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
 
309
                       self.collect)
340
310
        # expected results:
341
311
        # two commits, no files, revision identifiers of 
342
312
        # 'demo@DONOTUSE_c--import--0--base-0' and
345
315
        # and a merged revision from the latter of
346
316
        # self._baz._empty_merged_tag_bzr
347
317
        branch = Branch.open('output')
348
 
        repo = branch.repository
349
318
        self.assertEqual(branch.revision_history(),
350
319
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
351
320
                          self._baz._empty_merged_tag_2_bzr_base,
352
321
                          self._baz._empty_merged_tag_2_bzr])
353
322
        # and again.
354
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2))
 
323
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
 
324
                       self.collect)
355
325
        branch2 = Branch.open('output2')
356
 
        repo2 = branch2.repository
357
326
        # and import what we should be merged up against for checking with.
358
 
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag))
 
327
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
 
328
                       self.collect)
359
329
        branch3 = Branch.open('output3')
360
330
        
361
331
        self.assertEqual(branch.revision_history(), branch2.revision_history())
362
 
        self.assertNotEqual(branch.revision_history(), 
363
 
                            branch3.revision_history())
 
332
        self.assertNotEqual(branch.revision_history(), branch3.revision_history())
364
333
        # check revisions in the history.
365
 
        rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr_base)
366
 
        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)
367
336
        # they must be the same
368
337
        self.assertEqual(rev, rev2)
369
338
        # and we should get some expected values:
370
339
        self.assertEqual(rev.committer, "Test User<test@example.org>")
371
 
        self.assertEqual(rev.message, 
372
 
                         "tag of demo@DONOTUSE/c--import--0--base-0")
373
 
        self.assertEqual(rev.revision_id, 
374
 
                         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)
375
342
 
376
343
        # check next revisions in the history.
377
 
        rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr)
378
 
        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)
379
346
        # they must be the same
380
347
        self.assertEqual(rev, rev2)
381
348
        # and we should get some expected values:
392
359
        # self.assertEqual(branch.missing_revisions(branch3), [])
393
360
        
394
361
    def test_import_symlink(self):
395
 
        import_version('output', pybaz.Version(self._baz._import_symlink), 
396
 
                       max_count=1)
 
362
        import_version('output', pybaz.Version(self._baz._import_symlink),
 
363
                       self.collect)
397
364
        # expected results:
398
 
        # two commits, no files, revision identifier of 
399
 
        # 'demo@DONOTUSE_c--import--0--base-0'
 
365
        # one commit, no files, revision identifier of 'demo@DONOTUSE_c--import--0--base-0'
400
366
        branch = Branch.open('output')
401
367
        self.assertEqual(branch.revision_history(),
402
368
                         [self._baz._import_symlink_bzr])
403
 
        rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
 
369
        rev = branch.get_revision(self._baz._import_symlink_bzr)
404
370
        # and again.
405
371
        import_version('output2', pybaz.Version(self._baz._import_symlink),
406
 
                       max_count=1)
 
372
                       self.collect)
407
373
        branch2 = Branch.open('output2')
408
374
        self.assertEqual(branch.revision_history(), branch2.revision_history())
409
 
        rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
 
375
        rev2 = branch2.get_revision(self._baz._import_symlink_bzr)
410
376
        # they must be the same
411
377
        self.assertEqual(rev, rev2)
412
378
 
416
382
        self.assertEqual(rev.revision_id, self._baz._import_symlink_bzr)
417
383
 
418
384
        # and we want the symlink alink with target 'missing-file-name'
419
 
        inv = branch.repository.get_inventory(rev.revision_id)
 
385
        inv = branch.get_inventory(rev.revision_id)
420
386
        self.assertEqual(inv.path2id('alink'), 'x_symlink_tag')
421
387
        entry = inv['x_symlink_tag']
422
388
        self.assertEqual(entry.kind, 'symlink')
423
389
        self.assertEqual(entry.symlink_target, 'missing-file-name')
424
390
 
425
 
        # current bzr doesn't handle type changes
426
 
        self.assertRaises(AssertionError, import_version, 'output3',
427
 
                          pybaz.Version(self._baz._import_symlink))
428
 
 
429
391
    def test_missing_ancestor(self):
430
 
        import_version('output', pybaz.Version(self._baz._missing_ancestor))
 
392
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
 
393
                       self.collect)
431
394
        # expected results:
432
395
        # one commits, no files, revision identifiers of 
433
396
        # 'demo@DONOTUSE_c--gone--0--base-0' and
435
398
        branch = Branch.open('output')
436
399
        self.assertEqual(branch.revision_history(),
437
400
                         [self._baz._missing_ancestor_bzr])
438
 
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
 
401
        rev = branch.get_revision(self._baz._missing_ancestor_bzr)
439
402
        # and again.
440
 
        import_version('output2', pybaz.Version(self._baz._missing_ancestor))
 
403
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
 
404
                       self.collect)
441
405
        branch2 = Branch.open('output2')
442
406
        self.assertEqual(branch.revision_history(), branch2.revision_history())
443
 
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
 
407
        rev2 = branch2.get_revision(self._baz._missing_ancestor_bzr)
444
408
        # they must be the same
445
409
        self.assertEqual(rev, rev2)
446
410
 
447
411
        # and we should get some expected values:
448
412
        self.assertEqual(rev.committer, "Test User<test@example.org>")
449
 
        self.assertEqual(rev.message, 
450
 
                         "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")
451
414
        self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
452
415
        self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
453
416
        self.assertEqual(1, len(rev.parent_ids))
454
417
 
455
418
        # must NOT be able to get the merged evision
456
 
        self.assertRaises(NoSuchRevision, branch.repository.get_revision, 
 
419
        self.assertRaises(NoSuchRevision, branch.get_revision, 
457
420
                          self._baz._missing_import_bzr)
458
421
 
459
422
    def test_missing_ancestor_reusing_history(self):
460
423
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
 
424
                       self.collect,
461
425
                       reuse_history_from=[self._baz._missing_import_imported])
462
426
        # expected results:
463
427
        # one commits, no files, revision identifiers of 
467
431
        self.assertEqual(branch.revision_history(),
468
432
                         [self._baz._missing_import_bzr,
469
433
                          self._baz._missing_ancestor_bzr])
470
 
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
 
434
        rev = branch.get_revision(self._baz._missing_ancestor_bzr)
471
435
        # and again.
472
436
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
 
437
                       self.collect,
473
438
                       reuse_history_from=[self._baz._missing_import_imported])
474
439
        branch2 = Branch.open('output2')
475
440
        self.assertEqual(branch.revision_history(), branch2.revision_history())
476
 
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
 
441
        rev2 = branch2.get_revision(self._baz._missing_ancestor_bzr)
477
442
        # they must be the same
478
443
        self.assertEqual(rev, rev2)
479
444
 
480
445
        # must be able to get the missing base revision
481
 
        branch.repository.get_revision(self._baz._missing_import_bzr)
 
446
        branch.get_revision(self._baz._missing_import_bzr)
482
447
 
483
448
        # and we should get some expected values:
484
449
        self.assertEqual(rev.committer, "Test User<test@example.org>")
485
 
        self.assertEqual(rev.message, 
486
 
                         "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")
487
451
        self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
488
452
        self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
489
453
        self.assertEqual(1, len(rev.parent_ids))
490
454
 
491
455
    def test_bad_file_id(self):
492
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
 
456
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
457
                       self.collect)
493
458
        # expected results:
494
459
        # three commits, one files, revision identifiers of 
495
460
        # 'demo@DONOTUSE_c--import--0--base-0' ,
500
465
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
501
466
                          self._baz._bad_id_tag_bzr_base,
502
467
                          self._baz._bad_id_tag_bzr])
503
 
        rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
504
 
        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)
505
470
        self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
506
471
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
507
472
 
508
473
    def test_appending_revisions_already_present(self):
509
474
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
510
 
                       max_count=2)
 
475
                       self.collect, max_count=2)
511
476
        # expected results:
512
477
        # three commits, one files, revision identifiers of 
513
478
        # 'demo@DONOTUSE_c--import--0--base-0' ,
524
489
        self.assertEqual(branch.revision_history(),
525
490
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
526
491
        del branch
527
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
 
492
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
493
                       self.collect)
528
494
        branch = Branch.open('output')
529
495
        self.assertEqual(branch.revision_history(),
530
496
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
531
497
                          self._baz._bad_id_tag_bzr_base,
532
498
                          self._baz._bad_id_tag_bzr])
533
 
        rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
534
 
        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)
535
501
        self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
536
502
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
537
503
 
538
504
    def test_appending_revisions_all_already_present(self):
539
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
 
505
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
506
                       self.collect)
540
507
        # expected results:
541
508
        # three commits, one files, revision identifiers of 
542
509
        # 'demo@DONOTUSE_c--import--0--base-0' ,
554
521
        self.assertEqual(branch.revision_history(),
555
522
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
556
523
        del branch
557
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
 
524
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
525
                       self.collect)
558
526
        branch = Branch.open('output')
559
527
        self.assertEqual(branch.revision_history(),
560
528
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
561
529
                          self._baz._bad_id_tag_bzr_base,
562
530
                          self._baz._bad_id_tag_bzr])
563
 
        rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
564
 
        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)
565
533
        self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
566
534
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
567
535
 
568
 
    def test_inbranch_conversion(self):
569
 
        import_version('output', pybaz.Version(self._baz._inbranch_tag))
570
 
        # expected results:
571
 
        # three commits, no files, revision identifiers of 
572
 
        # 'demo@DONOTUSE_c--import--0--base-0' and
573
 
        # self._baz._inbranch_tag_base_bzr
574
 
        # self._baz._inbranch_tag_head_bzr
575
 
        # with no merges.
576
 
        branch = Branch.open('output')
577
 
        self.assertEqual(branch.revision_history(),
578
 
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
579
 
                          self._baz._inbranch_tag_base_bzr,
580
 
                          self._baz._inbranch_tag_head_bzr])
581
 
        # and again.
582
 
        import_version('output2', pybaz.Version(self._baz._inbranch_tag))
583
 
        branch2 = Branch.open('output2')
584
 
        
585
 
        self.assertEqual(branch.revision_history(), branch2.revision_history())
586
 
        # check revisions in the history.
587
 
        rev = branch.repository.get_revision(self._baz._inbranch_tag_base_bzr)
588
 
        rev2 = branch2.repository.get_revision(self._baz._inbranch_tag_base_bzr)
589
 
        # they must be the same
590
 
        self.assertEqual(rev, rev2)
591
 
        # and we should get some expected values:
592
 
        self.assertEqual(rev.committer, "Test User<test@example.org>")
593
 
        self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
594
 
        self.assertEqual(rev.revision_id, self._baz._inbranch_tag_base_bzr)
595
 
 
596
 
        # check next revisions in the history.
597
 
        rev = branch.repository.get_revision(self._baz._inbranch_tag_head_bzr)
598
 
        rev2 = branch2.repository.get_revision(self._baz._inbranch_tag_head_bzr)
599
 
        # they must be the same
600
 
        self.assertEqual(rev, rev2)
601
 
        # and we should get some expected values:
602
 
        self.assertEqual(rev.committer, "Test User<test@example.org>")
603
 
        self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--inbranch-tag--0--base-0")
604
 
        self.assertEqual(rev.revision_id, self._baz._inbranch_tag_head_bzr)
605
 
        self.assertEqual(rev.parent_ids,
606
 
                         [self._baz._inbranch_tag_base_bzr])
607
 
 
608
 
    def test_no_commits_same_as_missing(self):
609
 
        path = 'output'
610
 
        os.mkdir(path)
611
 
        branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
612
 
        import_version(path, pybaz.Version(self._baz._import))
613
 
        # expected results:
614
 
        # one commit, revision identifier of 
615
 
        # 'demo@DONOTUSE_c--import--0--base-0'
616
 
        self.assertEqual(branch.revision_history(),
617
 
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
618
 
 
619
536
 
620
537
class TestNamespacePrevious(TestCase):
621
538
 
646
563
        self.assertEqual(namespace_previous(self.version['versionfix-3000']),
647
564
                         self.version['versionfix-2999'])
648
565
 
649
 
 
650
566
class TestNamespaceMapping(TestCase):
651
567
 
652
568
    def test_namespace_mapping_branch(self):
669
585
class TestFileIdMapping(TestCase):
670
586
 
671
587
    def test_slash(self):
 
588
        from bzrlib.plugins.bzrtools.baz_import import map_file_id
672
589
        self.assertEqual('c%2fc', map_file_id('c/c'))
673
590
        self.assertEqual('c%25c', map_file_id('c%c'))
674
591
 
683
600
        os.mkdir(self._homedir)
684
601
        os.environ['HOME'] = self._homedir
685
602
        self._archiveroot = os.path.join(self._tmpdir, 'archive')
686
 
        self._archive = make_archive('demo@DONOTUSE', str(self._archiveroot))
 
603
        self._archive = pybaz.make_archive('demo@DONOTUSE', 
 
604
                                           str(self._archiveroot))
687
605
 
688
606
    def tearDown(self):
689
607
        os.environ['HOME'] = self._oldhome
693
611
    def make_import(self, namespace):
694
612
        self._import = 'demo@DONOTUSE/%s' % namespace
695
613
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
696
 
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
697
 
                               self._import)
 
614
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), self._import)
698
615
        msg = tree.log_message()
699
616
        msg["summary"] = "I am importing now"
700
617
        tree.import_(msg)
707
624
        command = cmd_baz_import()
708
625
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
709
626
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
710
 
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
711
 
        self.assertEqual(7, walk_len)
 
627
        self.assertEqual(1, 
 
628
                        len(list(os.walk(os.path.join(self._tmpdir,'output')))))
712
629
 
713
630
    def test_two_branches(self):
714
631
        self.make_import('c--0')
716
633
        command = cmd_baz_import()
717
634
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
718
635
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
719
 
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
720
 
                                       'c','+trunk')))
721
 
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
722
 
                                                    'c1', '0.2','branch')))
723
 
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
724
 
        self.assertEqual(20, 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')))
 
638
        self.assertEqual(14,
 
639
                        len(list(os.walk(os.path.join(self._tmpdir,'output')))))
725
640
 
726
641
    def test_run_twice(self):
727
642
        self.make_import('c--0')
738
653
        self.make_import('c--0')
739
654
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
740
655
                     'demo@DONOTUSE')
741