~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_baz_import.py

  • Committer: Aaron Bentley
  • Date: 2007-05-18 09:20:47 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20070518092047-c25wfogkpw1c8yj1
Tags: release-0.17.0
Update version number to 0.17.0

Show diffs side-by-side

added added

removed removed

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