~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_baz_import.py

  • Committer: Aaron Bentley
  • Date: 2005-12-03 23:53:59 UTC
  • mto: (147.4.30 trunk)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: aaron.bentley@utoronto.ca-20051203235359-5134805afd538781
Recorded Robey's bug

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