~abentley/bzrtools/bzrtools.dev

147.1.1 by Robert Collins
start adding baz_import unit test cases
1
# Copyright (C) 2005 Canonical Limited
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
#
4
#    This program is free software; you can redistribute it and/or modify
5
#    it under the terms of the GNU General Public License as published by
6
#    the Free Software Foundation; either version 2 of the License, or
7
#    (at your option) any later version.
8
#
9
#    This program is distributed in the hope that it will be useful,
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#    GNU General Public License for more details.
13
#
14
#    You should have received a copy of the GNU General Public License
15
#    along with this program; if not, write to the Free Software
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
147.4.23 by Robert Collins
Update for integration changes.
18
from bzrlib.tests import TestCaseInTempDir, TestCase
434 by Aaron Bentley
Avoid spurious failure with RepositoryFormatKnit2 and later
19
from bzrlib import repository
147.4.23 by Robert Collins
Update for integration changes.
20
from bzrlib.osutils import has_symlinks
147.1.2 by Robert Collins
test empty import and tagged branches
21
try:
22
    import pybaz
23
except ImportError:
24
    pybaz = None
25
import os
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
26
from bzrlib.plugins.bzrtools import cmd_baz_import
27
from bzrlib.plugins.bzrtools.baz_import import (import_version,
514 by Aaron Bentley
Fix imports
28
                                                revision_id,
29
                                                make_archive,
30
                                                map_file_id)
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
31
import shutil
147.1.17 by Robert Collins
make feedback be callback based - really
32
from StringIO import StringIO
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
33
import tempfile
34
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
147.1.54 by Aaron Bentley
Got bzrtools almost working, except baz-import
35
                               ResourcedTestCase)
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
36
364.1.2 by Aaron Bentley
Patch from robert to allow import into empty branches
37
import bzrlib
38
from bzrlib.errors import NoSuchRevision
514 by Aaron Bentley
Fix imports
39
from bzrlib.plugins.bzrtools.fai import namespace_previous
147.1.29 by Robert Collins
update to latest bzr api
40
from bzrlib.branch import Branch
147.1.1 by Robert Collins
start adding baz_import unit test cases
41
42
def test_suite():
147.1.2 by Robert Collins
test empty import and tagged branches
43
    if pybaz is None:
147.1.54 by Aaron Bentley
Got bzrtools almost working, except baz-import
44
        from unittest import TestSuite
45
        return TestSuite()
147.1.1 by Robert Collins
start adding baz_import unit test cases
46
    return TestLoader().loadTestsFromName(__name__)
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
47
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
48
49
class BazTreeResource(TestResource):
50
51
    def cleanUp(self):
52
        os.environ['HOME'] = self._oldhome
53
        shutil.rmtree(self._tmpdir)
54
55
    def __init__(self):
56
        self._tmpdir = tempfile.mkdtemp()
57
        self._homedir = os.path.join(self._tmpdir, 'home')
147.1.2 by Robert Collins
test empty import and tagged branches
58
        self._oldhome = os.environ['HOME']
59
        os.mkdir(self._homedir)
60
        os.environ['HOME'] = self._homedir
147.1.20 by Robert Collins
handle missing ancestry
61
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
62
        self._archiveroot = os.path.join(self._tmpdir, 'archive')
147.1.60 by Aaron Bentley
Stopped using deprecated PyBaz functionality
63
        self._archive = make_archive('demo@DONOTUSE', str(self._archiveroot))
147.1.2 by Robert Collins
test empty import and tagged branches
64
        pybaz.set_my_id("Test User<test@example.org>")
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
65
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
66
        self.make_empty_import()
462 by Aaron Bentley
Get encoding working
67
        self.make_utf8_log()
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
68
147.1.2 by Robert Collins
test empty import and tagged branches
69
        self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
460 by Aaron Bentley
Add encoding parameter everywhere
70
        self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0', None)
147.1.2 by Robert Collins
test empty import and tagged branches
71
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
72
            pybaz.Version(self._empty_tag))
73
74
        self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
75
        self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
460 by Aaron Bentley
Add encoding parameter everywhere
76
                                                 + '--base-0', None)
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
77
        self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
460 by Aaron Bentley
Add encoding parameter everywhere
78
                                                 + '--patch-1', None)
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
79
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
80
            pybaz.Version(self._empty_merged_tag))
81
        tree = pybaz.Revision(self._empty_merged_tag + '--base-0').get(
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
82
            os.path.join(self._tmpdir, 'tree'))
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
83
        tree.star_merge(self._empty_tag,
84
                        pybaz.Version('demo@DONOTUSE/c--import--0'))
85
        msg = tree.log_message()
86
        msg["summary"]="did a merge, yarh"
87
        tree.commit(msg)
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
88
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
89
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
90
        # tree, two commits, includes merge of other branch
91
        self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
92
        self._empty_merged_tag_2_bzr_base = revision_id(
460 by Aaron Bentley
Add encoding parameter everywhere
93
            self._empty_merged_tag_2 + '--base-0', None)
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
94
        self._empty_merged_tag_2_bzr = revision_id(
460 by Aaron Bentley
Add encoding parameter everywhere
95
            self._empty_merged_tag_2 + '--patch-1', None)
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
96
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
97
            pybaz.Version(self._empty_merged_tag_2))
98
        tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
99
            os.path.join(self._tmpdir, 'tree'))
100
        tree.star_merge(self._empty_merged_tag,
101
                        pybaz.Version('demo@DONOTUSE/c--import--0'))
102
        msg = tree.log_message()
103
        msg["summary"] = "merge in a merged tree."
104
        tree.commit(msg)
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
105
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
106
147.4.1 by Robert Collins
test escaping of file ids is working
107
        self._bad_id_tag = 'demo@DONOTUSE/c--bad-id--0'
460 by Aaron Bentley
Add encoding parameter everywhere
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)
147.4.1 by Robert Collins
test escaping of file ids is working
112
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
113
            pybaz.Version(self._bad_id_tag))
114
        tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
115
            os.path.join(self._tmpdir, 'tree'))
116
        from bzrlib.plugins.bzrtools.baz_import import add_file
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
117
        add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
118
                 'this_id/needs%escaping')
147.4.1 by Robert Collins
test escaping of file ids is working
119
        msg = tree.log_message()
120
        msg["summary"] = "commit something which needs escaping."
121
        tree.commit(msg)
122
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
123
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
124
        self.make_import_symlink()
147.1.20 by Robert Collins
handle missing ancestry
125
        self.make_missing_ancestor()
147.4.26 by Robert Collins
Test in-branch continuations.
126
        self.make_inbranch_continuation()
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
127
128
    def make_import_symlink(self):
129
        self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
130
        self._import_symlink_bzr = revision_id(
460 by Aaron Bentley
Add encoding parameter everywhere
131
            self._import_symlink + '--base-0', None)
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
132
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
133
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
134
                               self._import_symlink)
389 by Aaron Bentley
Add test that type changes are not supported in bzr
135
        link_path = os.path.join(self._tmpdir, 'tree', 'alink')
136
        os.symlink('missing-file-name', link_path)
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
137
        tree.add_tag('alink')
138
        id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
139
        id_file.write('symlink_tag\n')
140
        id_file.close()
141
        msg = tree.log_message()
142
        msg["summary"] = "Import with a symlink"
143
        tree.import_(msg)
389 by Aaron Bentley
Add test that type changes are not supported in bzr
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)
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
151
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
152
153
    def make_empty_import(self):
154
        self._import = 'demo@DONOTUSE/c--import--0'
155
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
156
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
157
                               self._import)
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
158
        msg = tree.log_message()
159
        msg["summary"] = "I am importing now"
160
        tree.import_(msg)
161
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
147.1.2 by Robert Collins
test empty import and tagged branches
162
462 by Aaron Bentley
Get encoding working
163
    def make_utf8_log(self):
164
        self._utf8 = 'demo@DONOTUSE/c--utf8--0'
165
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
166
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
462 by Aaron Bentley
Get encoding working
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
147.1.20 by Robert Collins
handle missing ancestry
173
    def make_missing_ancestor(self):
174
        self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
147.1.60 by Aaron Bentley
Stopped using deprecated PyBaz functionality
175
        self._archive = make_archive('demo-gone@DONOTUSE',
176
                                     str(self._archivegoneroot))
147.1.20 by Robert Collins
handle missing ancestry
177
        self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
178
        self._missing_import_bzr = revision_id(self._missing_import
460 by Aaron Bentley
Add encoding parameter everywhere
179
                                                 + '--base-0', None)
147.1.20 by Robert Collins
handle missing ancestry
180
        self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
181
        self._missing_ancestor_bzr = revision_id(self._missing_ancestor
460 by Aaron Bentley
Add encoding parameter everywhere
182
                                                 + '--base-0', None)
147.1.20 by Robert Collins
handle missing ancestry
183
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
184
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
147.1.20 by Robert Collins
handle missing ancestry
185
                               self._missing_import)
186
        msg = tree.log_message()
187
        msg["summary"] = "I am importing now"
188
        tree.import_(msg)
189
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
190
        # tag into the kept archive
191
        pybaz.Revision(self._missing_import + '--base-0').make_continuation(
192
            pybaz.Version(self._missing_ancestor))
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
193
194
        # make an import for testing history-reuse logic.
195
        # note the use of a namespace layout here.
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
196
        self._missing_import_imported = os.path.join(self._tmpdir,
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
197
                                                     'archivegone-bzr')
198
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr'))
199
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
200
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
201
                                    'c', 'import'),
460 by Aaron Bentley
Add encoding parameter everywhere
202
                       pybaz.Version(self._missing_import), None)
147.1.20 by Robert Collins
handle missing ancestry
203
        # and make it inaccessible
204
        pybaz.Archive('demo-gone@DONOTUSE').unregister()
205
147.4.26 by Robert Collins
Test in-branch continuations.
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'
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
209
        self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
460 by Aaron Bentley
Add encoding parameter everywhere
210
                                                  None)
147.4.26 by Robert Collins
Test in-branch continuations.
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'
460 by Aaron Bentley
Add encoding parameter everywhere
214
        self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head,
215
                                                  None)
147.4.26 by Robert Collins
Test in-branch continuations.
216
        pybaz.Revision(self._inbranch_tag_base).make_continuation(
217
            pybaz.Version(self._inbranch_tag))
218
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
219
    @classmethod
220
    def _makeResource(self):
221
        return BazTreeResource()
222
223
    @classmethod
224
    def _cleanResource(self, resource):
225
        resource.cleanUp()
226
227
147.1.12 by Robert Collins
create the output directory
228
class TestImportBranch(TestCaseInTempDir):
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
229
230
    _resources = [("_baz", BazTreeResource)]
231
232
    def setUp(self):
233
        TestCaseInTempDir.setUp(self)
234
        ResourcedTestCase.setUpResources(self)
147.1.36 by Robert Collins
updates for bzr api changes
235
        os.environ['HOME'] = self._baz._homedir
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
236
147.1.2 by Robert Collins
test empty import and tagged branches
237
    def tearDown(self):
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
238
        ResourcedTestCase.tearDownResources(self)
239
        TestCaseInTempDir.tearDown(self)
462 by Aaron Bentley
Get encoding working
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
147.1.2 by Robert Collins
test empty import and tagged branches
255
    def test_import_empty(self):
460 by Aaron Bentley
Add encoding parameter everywhere
256
        import_version('output', pybaz.Version(self._baz._import), None)
147.1.2 by Robert Collins
test empty import and tagged branches
257
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
258
        # one commit, no files, revision identifier of
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
259
        # 'demo@DONOTUSE_c--import--0--base-0'
147.1.29 by Robert Collins
update to latest bzr api
260
        branch = Branch.open('output')
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
261
        repo = branch.repository
147.1.2 by Robert Collins
test empty import and tagged branches
262
        self.assertEqual(branch.revision_history(),
263
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
264
        rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
147.1.2 by Robert Collins
test empty import and tagged branches
265
        # and again.
460 by Aaron Bentley
Add encoding parameter everywhere
266
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
267
                       None)
147.1.29 by Robert Collins
update to latest bzr api
268
        branch2 = Branch.open('output2')
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
269
        repo2 = branch2.repository
147.1.2 by Robert Collins
test empty import and tagged branches
270
        self.assertEqual(branch.revision_history(), branch2.revision_history())
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
271
        rev2 = repo2.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
147.1.2 by Robert Collins
test empty import and tagged branches
272
        # they must be the same
273
        self.assertEqual(rev, rev2)
274
275
        # and we should get some expected values:
276
        self.assertEqual(rev.committer, "Test User<test@example.org>")
277
        self.assertEqual(rev.message, "I am importing now")
278
        self.assertEqual(rev.revision_id,
279
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
280
281
    def test_empty_tagged(self):
460 by Aaron Bentley
Add encoding parameter everywhere
282
        import_version('output', pybaz.Version(self._baz._empty_tag), None)
147.1.2 by Robert Collins
test empty import and tagged branches
283
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
284
        # two commits, no files, revision identifiers of
147.1.2 by Robert Collins
test empty import and tagged branches
285
        # 'demo@DONOTUSE_c--import--0--base-0' and
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
286
        # self._baz._empty_tag_bzr
147.1.29 by Robert Collins
update to latest bzr api
287
        branch = Branch.open('output')
147.1.2 by Robert Collins
test empty import and tagged branches
288
        self.assertEqual(branch.revision_history(),
289
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
290
                          self._baz._empty_tag_bzr])
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
291
        rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
147.1.2 by Robert Collins
test empty import and tagged branches
292
        # and again.
460 by Aaron Bentley
Add encoding parameter everywhere
293
        import_version('output2', pybaz.Version(self._baz._empty_tag), None)
147.1.29 by Robert Collins
update to latest bzr api
294
        branch2 = Branch.open('output2')
147.1.2 by Robert Collins
test empty import and tagged branches
295
        self.assertEqual(branch.revision_history(), branch2.revision_history())
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
296
        rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
147.1.2 by Robert Collins
test empty import and tagged branches
297
        # they must be the same
298
        self.assertEqual(rev, rev2)
299
300
        # and we should get some expected values:
301
        self.assertEqual(rev.committer, "Test User<test@example.org>")
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
302
        self.assertEqual(rev.message,
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
303
                         "tag of demo@DONOTUSE/c--import--0--base-0")
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
304
        self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
147.1.2 by Robert Collins
test empty import and tagged branches
305
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
306
    def test_empty_merged_tagged(self):
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
307
        import_version('output', pybaz.Version(self._baz._empty_merged_tag),
460 by Aaron Bentley
Add encoding parameter everywhere
308
                       None)
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
309
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
310
        # two commits, no files, revision identifiers of
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
311
        # 'demo@DONOTUSE_c--import--0--base-0' and
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
312
        # self._baz._empty_merged_tag_bzr_base
313
        # self._baz._empty_merged_tag_bzr
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
314
        # and a merged revision from the latter of
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
315
        # self._baz._empty_tag_bzr
147.1.29 by Robert Collins
update to latest bzr api
316
        branch = Branch.open('output')
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
317
        repo = branch.repository
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
318
        self.assertEqual(branch.revision_history(),
319
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
320
                          self._baz._empty_merged_tag_bzr_base,
321
                          self._baz._empty_merged_tag_bzr])
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
322
        # and again.
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
323
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
460 by Aaron Bentley
Add encoding parameter everywhere
324
                       None)
147.1.29 by Robert Collins
update to latest bzr api
325
        branch2 = Branch.open('output2')
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
326
        repo2 = branch2.repository
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
327
        # and import what we should be merged up against for checking with.
460 by Aaron Bentley
Add encoding parameter everywhere
328
        import_version('output3', pybaz.Version(self._baz._empty_tag), None)
147.1.29 by Robert Collins
update to latest bzr api
329
        branch3 = Branch.open('output3')
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
330
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
331
        self.assertEqual(branch.revision_history(), branch2.revision_history())
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
332
        self.assertNotEqual(branch.revision_history(),
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
333
                            branch3.revision_history())
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
334
        # check revisions in the history.
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
335
        rev = repo.get_revision(self._baz._empty_merged_tag_bzr_base)
336
        rev2 = repo2.get_revision(self._baz._empty_merged_tag_bzr_base)
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
337
        # they must be the same
338
        self.assertEqual(rev, rev2)
339
        # and we should get some expected values:
340
        self.assertEqual(rev.committer, "Test User<test@example.org>")
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
341
        self.assertEqual(rev.message,
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
342
                         "tag of demo@DONOTUSE/c--import--0--base-0")
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
343
        self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
344
        self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
345
                         rev.parent_ids)
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
346
347
        # check next revisions in the history.
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
348
        rev = repo.get_revision(self._baz._empty_merged_tag_bzr)
349
        rev2 = repo2.get_revision(self._baz._empty_merged_tag_bzr)
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
350
        # they must be the same
351
        self.assertEqual(rev, rev2)
352
        # and we should get some expected values:
353
        self.assertEqual(rev.committer, "Test User<test@example.org>")
354
        self.assertEqual(rev.message, "did a merge, yarh")
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
355
        self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr)
147.1.31 by Robert Collins
update to weave api
356
        self.assertEqual(rev.parent_ids[0],
147.1.4 by Robert Collins
start using testresources to coordinate import tests, saves 10 seconds
357
                         self._baz._empty_merged_tag_bzr_base)
147.1.31 by Robert Collins
update to weave api
358
        self.assertEqual(rev.parent_ids[1], self._baz._empty_tag_bzr)
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
359
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
360
        # this tree should have nothing missing from that tree.
147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
361
        # FIXME there is no code for this right now.
362
        # self.assertEqual(branch.missing_revisions(branch3), [])
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
363
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
364
    def test_merge_branch_with_merges(self):
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
365
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
460 by Aaron Bentley
Add encoding parameter everywhere
366
                       None)
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
367
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
368
        # two commits, no files, revision identifiers of
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
369
        # 'demo@DONOTUSE_c--import--0--base-0' and
370
        # self._baz._empty_merged_tag_2_bzr_base
371
        # self._baz._empty_merged_tag_2_bzr
372
        # and a merged revision from the latter of
373
        # self._baz._empty_merged_tag_bzr
147.1.29 by Robert Collins
update to latest bzr api
374
        branch = Branch.open('output')
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
375
        repo = branch.repository
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
376
        self.assertEqual(branch.revision_history(),
377
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
378
                          self._baz._empty_merged_tag_2_bzr_base,
379
                          self._baz._empty_merged_tag_2_bzr])
380
        # and again.
460 by Aaron Bentley
Add encoding parameter everywhere
381
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
382
                       None)
147.1.29 by Robert Collins
update to latest bzr api
383
        branch2 = Branch.open('output2')
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
384
        repo2 = branch2.repository
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
385
        # and import what we should be merged up against for checking with.
460 by Aaron Bentley
Add encoding parameter everywhere
386
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
387
                       None)
147.1.29 by Robert Collins
update to latest bzr api
388
        branch3 = Branch.open('output3')
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
389
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
390
        self.assertEqual(branch.revision_history(), branch2.revision_history())
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
391
        self.assertNotEqual(branch.revision_history(),
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
392
                            branch3.revision_history())
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
393
        # check revisions in the history.
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
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)
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
396
        # they must be the same
397
        self.assertEqual(rev, rev2)
398
        # and we should get some expected values:
399
        self.assertEqual(rev.committer, "Test User<test@example.org>")
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
400
        self.assertEqual(rev.message,
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
401
                         "tag of demo@DONOTUSE/c--import--0--base-0")
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
402
        self.assertEqual(rev.revision_id,
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
403
                         self._baz._empty_merged_tag_2_bzr_base)
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
404
405
        # check next revisions in the history.
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
406
        rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr)
407
        rev2 = repo2.get_revision(self._baz._empty_merged_tag_2_bzr)
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
408
        # they must be the same
409
        self.assertEqual(rev, rev2)
410
        # and we should get some expected values:
411
        self.assertEqual(rev.committer, "Test User<test@example.org>")
412
        self.assertEqual(rev.message, "merge in a merged tree.")
413
        self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_2_bzr)
147.1.31 by Robert Collins
update to weave api
414
        self.assertEqual(rev.parent_ids[0],
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
415
                         self._baz._empty_merged_tag_2_bzr_base)
147.1.31 by Robert Collins
update to weave api
416
        self.assertEqual(rev.parent_ids[1],
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
417
                         self._baz._empty_merged_tag_bzr)
418
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
419
        # this tree should have nothing missing from that tree.
147.1.5 by Robert Collins
test and implement direct merge support of 2-in-a-row patches
420
        # FIXME there is no code for this right now.
421
        # self.assertEqual(branch.missing_revisions(branch3), [])
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
422
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
423
    def test_import_symlink(self):
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
424
        import_version('output', pybaz.Version(self._baz._import_symlink),
460 by Aaron Bentley
Add encoding parameter everywhere
425
                       None, max_count=1)
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
426
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
427
        # two commits, no files, revision identifier of
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
428
        # 'demo@DONOTUSE_c--import--0--base-0'
147.1.29 by Robert Collins
update to latest bzr api
429
        branch = Branch.open('output')
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
430
        self.assertEqual(branch.revision_history(),
431
                         [self._baz._import_symlink_bzr])
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
432
        rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
433
        # and again.
389 by Aaron Bentley
Add test that type changes are not supported in bzr
434
        import_version('output2', pybaz.Version(self._baz._import_symlink),
460 by Aaron Bentley
Add encoding parameter everywhere
435
                       None, max_count=1)
147.1.29 by Robert Collins
update to latest bzr api
436
        branch2 = Branch.open('output2')
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
437
        self.assertEqual(branch.revision_history(), branch2.revision_history())
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
438
        rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
439
        # they must be the same
440
        self.assertEqual(rev, rev2)
441
442
        # and we should get some expected values:
443
        self.assertEqual(rev.committer, "Test User<test@example.org>")
444
        self.assertEqual(rev.message, "Import with a symlink")
445
        self.assertEqual(rev.revision_id, self._baz._import_symlink_bzr)
446
447
        # and we want the symlink alink with target 'missing-file-name'
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
448
        inv = branch.repository.get_inventory(rev.revision_id)
147.1.6 by Robert Collins
import symlinks (needs symlink enabled bzr)
449
        self.assertEqual(inv.path2id('alink'), 'x_symlink_tag')
450
        entry = inv['x_symlink_tag']
451
        self.assertEqual(entry.kind, 'symlink')
452
        self.assertEqual(entry.symlink_target, 'missing-file-name')
147.1.7 by Robert Collins
handle inaccessible sibling archives somewhat - note version-0 is still not handled
453
509 by Aaron Bentley
Update test suite to reflect kind change support
454
        # Test kind change for import
455
        import_version('output3', pybaz.Version(self._baz._import_symlink),
456
                       None)
389 by Aaron Bentley
Add test that type changes are not supported in bzr
457
147.1.20 by Robert Collins
handle missing ancestry
458
    def test_missing_ancestor(self):
460 by Aaron Bentley
Add encoding parameter everywhere
459
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
460
                       None)
147.1.20 by Robert Collins
handle missing ancestry
461
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
462
        # one commits, no files, revision identifiers of
147.1.20 by Robert Collins
handle missing ancestry
463
        # 'demo@DONOTUSE_c--gone--0--base-0' and
464
        # a merge of demo-gone@DONOTUSE%c--import--0
147.1.29 by Robert Collins
update to latest bzr api
465
        branch = Branch.open('output')
147.1.20 by Robert Collins
handle missing ancestry
466
        self.assertEqual(branch.revision_history(),
467
                         [self._baz._missing_ancestor_bzr])
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
468
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
147.1.20 by Robert Collins
handle missing ancestry
469
        # and again.
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
470
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
460 by Aaron Bentley
Add encoding parameter everywhere
471
                       None)
147.1.29 by Robert Collins
update to latest bzr api
472
        branch2 = Branch.open('output2')
147.1.20 by Robert Collins
handle missing ancestry
473
        self.assertEqual(branch.revision_history(), branch2.revision_history())
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
474
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
147.1.20 by Robert Collins
handle missing ancestry
475
        # they must be the same
476
        self.assertEqual(rev, rev2)
477
478
        # and we should get some expected values:
479
        self.assertEqual(rev.committer, "Test User<test@example.org>")
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
480
        self.assertEqual(rev.message,
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
481
                         "tag of demo-gone@DONOTUSE/c--import--0--base-0")
147.1.20 by Robert Collins
handle missing ancestry
482
        self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
147.1.31 by Robert Collins
update to weave api
483
        self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
484
        self.assertEqual(1, len(rev.parent_ids))
147.1.20 by Robert Collins
handle missing ancestry
485
486
        # must NOT be able to get the merged evision
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
487
        self.assertRaises(NoSuchRevision, branch.repository.get_revision,
147.1.20 by Robert Collins
handle missing ancestry
488
                          self._baz._missing_import_bzr)
489
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
490
    def test_missing_ancestor_reusing_history(self):
491
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
460 by Aaron Bentley
Add encoding parameter everywhere
492
                       None,
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
493
                       reuse_history_from=[self._baz._missing_import_imported])
494
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
495
        # one commits, no files, revision identifiers of
496
        # 'demo-gone@DONOTUSE%c--import--0--base-0' and
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
497
        # 'demo@DONOTUSE%c--gone--0--base-0'
498
        branch = Branch.open('output')
499
        self.assertEqual(branch.revision_history(),
500
                         [self._baz._missing_import_bzr,
501
                          self._baz._missing_ancestor_bzr])
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
502
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
503
        # and again.
504
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
460 by Aaron Bentley
Add encoding parameter everywhere
505
                       None,
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
506
                       reuse_history_from=[self._baz._missing_import_imported])
507
        branch2 = Branch.open('output2')
508
        self.assertEqual(branch.revision_history(), branch2.revision_history())
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
509
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
510
        # they must be the same
511
        self.assertEqual(rev, rev2)
512
513
        # must be able to get the missing base revision
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
514
        branch.repository.get_revision(self._baz._missing_import_bzr)
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
515
516
        # and we should get some expected values:
517
        self.assertEqual(rev.committer, "Test User<test@example.org>")
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
518
        self.assertEqual(rev.message,
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
519
                         "tag of demo-gone@DONOTUSE/c--import--0--base-0")
147.4.6 by Robert Collins
Fix continuation direct_merges output, and allow reusing history in a version import
520
        self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
521
        self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
522
        self.assertEqual(1, len(rev.parent_ids))
523
147.4.1 by Robert Collins
test escaping of file ids is working
524
    def test_bad_file_id(self):
460 by Aaron Bentley
Add encoding parameter everywhere
525
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
147.4.1 by Robert Collins
test escaping of file ids is working
526
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
527
        # three commits, one files, revision identifiers of
147.4.1 by Robert Collins
test escaping of file ids is working
528
        # 'demo@DONOTUSE_c--import--0--base-0' ,
529
        # 'demo@DONOTUSE/c--bad-id--0--base-0' ,
530
        # ''demo@DONOTUSE/c--bad-id--0--patch-1'
531
        branch = Branch.open('output')
532
        self.assertEqual(branch.revision_history(),
533
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
534
                          self._baz._bad_id_tag_bzr_base,
535
                          self._baz._bad_id_tag_bzr])
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
536
        rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
537
        inv = branch.repository.get_inventory(self._baz._bad_id_tag_bzr)
147.4.1 by Robert Collins
test escaping of file ids is working
538
        self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
539
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
540
147.4.5 by Robert Collins
When an import finds a revision it needs already in the branch, just append it to the revision history
541
    def test_appending_revisions_already_present(self):
460 by Aaron Bentley
Add encoding parameter everywhere
542
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
364.1.2 by Aaron Bentley
Patch from robert to allow import into empty branches
543
                       max_count=2)
147.4.5 by Robert Collins
When an import finds a revision it needs already in the branch, just append it to the revision history
544
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
545
        # three commits, one files, revision identifiers of
147.4.5 by Robert Collins
When an import finds a revision it needs already in the branch, just append it to the revision history
546
        # 'demo@DONOTUSE_c--import--0--base-0' ,
547
        # 'demo@DONOTUSE/c--bad-id--0--base-0' ,
548
        # ''demo@DONOTUSE/c--bad-id--0--patch-1'
549
        branch = Branch.open('output')
550
        self.assertEqual(branch.revision_history(),
551
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
552
                          self._baz._bad_id_tag_bzr_base])
553
        branch.set_revision_history(
554
            ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
555
        del branch
556
        branch = Branch.open('output')
557
        self.assertEqual(branch.revision_history(),
558
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
559
        del branch
460 by Aaron Bentley
Add encoding parameter everywhere
560
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
147.4.5 by Robert Collins
When an import finds a revision it needs already in the branch, just append it to the revision history
561
        branch = Branch.open('output')
562
        self.assertEqual(branch.revision_history(),
563
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
564
                          self._baz._bad_id_tag_bzr_base,
565
                          self._baz._bad_id_tag_bzr])
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
566
        rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
567
        inv = branch.repository.get_inventory(self._baz._bad_id_tag_bzr)
147.4.5 by Robert Collins
When an import finds a revision it needs already in the branch, just append it to the revision history
568
        self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
569
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
570
571
    def test_appending_revisions_all_already_present(self):
460 by Aaron Bentley
Add encoding parameter everywhere
572
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
147.4.5 by Robert Collins
When an import finds a revision it needs already in the branch, just append it to the revision history
573
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
574
        # three commits, one files, revision identifiers of
147.4.5 by Robert Collins
When an import finds a revision it needs already in the branch, just append it to the revision history
575
        # 'demo@DONOTUSE_c--import--0--base-0' ,
576
        # 'demo@DONOTUSE/c--bad-id--0--base-0' ,
577
        # ''demo@DONOTUSE/c--bad-id--0--patch-1'
578
        branch = Branch.open('output')
579
        self.assertEqual(branch.revision_history(),
580
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
581
                          self._baz._bad_id_tag_bzr_base,
582
                          self._baz._bad_id_tag_bzr])
583
        branch.set_revision_history(
584
            ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
585
        del branch
586
        branch = Branch.open('output')
587
        self.assertEqual(branch.revision_history(),
588
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
589
        del branch
460 by Aaron Bentley
Add encoding parameter everywhere
590
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
147.4.5 by Robert Collins
When an import finds a revision it needs already in the branch, just append it to the revision history
591
        branch = Branch.open('output')
592
        self.assertEqual(branch.revision_history(),
593
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
594
                          self._baz._bad_id_tag_bzr_base,
595
                          self._baz._bad_id_tag_bzr])
147.1.55 by Aaron Bentley
Got imports working, via a big hammer
596
        rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
597
        inv = branch.repository.get_inventory(self._baz._bad_id_tag_bzr)
147.4.5 by Robert Collins
When an import finds a revision it needs already in the branch, just append it to the revision history
598
        self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
599
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
600
147.4.26 by Robert Collins
Test in-branch continuations.
601
    def test_inbranch_conversion(self):
460 by Aaron Bentley
Add encoding parameter everywhere
602
        import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
147.4.26 by Robert Collins
Test in-branch continuations.
603
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
604
        # three commits, no files, revision identifiers of
147.4.26 by Robert Collins
Test in-branch continuations.
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.
460 by Aaron Bentley
Add encoding parameter everywhere
615
        import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
147.4.26 by Robert Collins
Test in-branch continuations.
616
        branch2 = Branch.open('output2')
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
617
147.4.26 by Robert Collins
Test in-branch continuations.
618
        self.assertEqual(branch.revision_history(), branch2.revision_history())
619
        # check revisions in the history.
147.4.28 by Robert Collins
merge in storage api support.
620
        rev = branch.repository.get_revision(self._baz._inbranch_tag_base_bzr)
621
        rev2 = branch2.repository.get_revision(self._baz._inbranch_tag_base_bzr)
147.4.26 by Robert Collins
Test in-branch continuations.
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.
147.4.28 by Robert Collins
merge in storage api support.
630
        rev = branch.repository.get_revision(self._baz._inbranch_tag_head_bzr)
631
        rev2 = branch2.repository.get_revision(self._baz._inbranch_tag_head_bzr)
147.4.26 by Robert Collins
Test in-branch continuations.
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
364.1.2 by Aaron Bentley
Patch from robert to allow import into empty branches
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)
460 by Aaron Bentley
Add encoding parameter everywhere
645
        import_version(path, pybaz.Version(self._baz._import), None)
364.1.2 by Aaron Bentley
Patch from robert to allow import into empty branches
646
        # expected results:
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
647
        # one commit, revision identifier of
364.1.2 by Aaron Bentley
Patch from robert to allow import into empty branches
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
147.1.7 by Robert Collins
handle inaccessible sibling archives somewhat - note version-0 is still not handled
652
653
class TestNamespacePrevious(TestCase):
654
655
    def setUp(self):
656
        TestCase.setUp(self)
657
        self.version = pybaz.Version('foo@example.com/c--b--0')
658
659
    def test_base0_none(self):
660
        self.assertEqual(namespace_previous(self.version['base-0']), None)
661
662
    def test_patch1_base0(self):
663
        self.assertEqual(namespace_previous(self.version['patch-1']),
664
                         self.version['base-0'])
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
665
147.1.7 by Robert Collins
handle inaccessible sibling archives somewhat - note version-0 is still not handled
666
    def test_patch3000_patch2999(self):
667
        self.assertEqual(namespace_previous(self.version['patch-3000']),
668
                         self.version['patch-2999'])
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
669
147.1.7 by Robert Collins
handle inaccessible sibling archives somewhat - note version-0 is still not handled
670
    def test_version0_raises(self):
671
        self.assertRaises(RuntimeError, namespace_previous,
672
                          self.version['version-0'])
673
674
    def test_version1_version0(self):
147.1.29 by Robert Collins
update to latest bzr api
675
        self.assertEqual(namespace_previous(self.version['versionfix-1']),
147.1.7 by Robert Collins
handle inaccessible sibling archives somewhat - note version-0 is still not handled
676
                         self.version['version-0'])
147.1.8 by Robert Collins
handle version-xxx and base-0 correctly in namespace_previous
677
678
    def test_version3000_patch2999(self):
147.1.29 by Robert Collins
update to latest bzr api
679
        self.assertEqual(namespace_previous(self.version['versionfix-3000']),
680
                         self.version['versionfix-2999'])
147.1.11 by Robert Collins
move baz-import to baz-import-branch
681
364.1.2 by Aaron Bentley
Patch from robert to allow import into empty branches
682
147.1.13 by Robert Collins
create the output directory
683
class TestNamespaceMapping(TestCase):
684
685
    def test_namespace_mapping_branch(self):
147.1.37 by Robert Collins
get all tests passing again, and disable importing the body of continuation log messages
686
        from bzrlib.plugins.bzrtools.baz_import import map_namespace
147.1.13 by Robert Collins
create the output directory
687
        branch = pybaz.Branch('foo@example.com/c--b')
147.1.14 by Robert Collins
implement a namespace mapper
688
        self.assertRaises(pybaz.errors.NamespaceError, map_namespace, branch)
147.1.13 by Robert Collins
create the output directory
689
        self.assertEqual('c/b', map_namespace(branch['0']))
690
        self.assertEqual('c/0.1/b', map_namespace(branch['0.1']))
691
692
    def test_namespace_mapping_no_branch(self):
147.1.37 by Robert Collins
get all tests passing again, and disable importing the body of continuation log messages
693
        from bzrlib.plugins.bzrtools.baz_import import map_namespace
147.1.13 by Robert Collins
create the output directory
694
        category = pybaz.Category('foo@example.com/c')
147.1.14 by Robert Collins
implement a namespace mapper
695
        self.assertRaises(pybaz.errors.NamespaceError, map_namespace, category)
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
696
        self.assertEqual('c/+trunk',
147.1.14 by Robert Collins
implement a namespace mapper
697
                         map_namespace(pybaz.Version("%s--0" % category)))
698
        self.assertEqual('c/0.1/+trunk',
699
                         map_namespace(pybaz.Version('%s--0.1' % category)))
147.1.13 by Robert Collins
create the output directory
700
147.1.12 by Robert Collins
create the output directory
701
147.4.1 by Robert Collins
test escaping of file ids is working
702
class TestFileIdMapping(TestCase):
703
704
    def test_slash(self):
705
        self.assertEqual('c%2fc', map_file_id('c/c'))
706
        self.assertEqual('c%25c', map_file_id('c%c'))
707
708
147.1.11 by Robert Collins
move baz-import to baz-import-branch
709
class TestImport(TestCaseInTempDir):
710
147.1.15 by Robert Collins
archive at a time imports
711
    def setUp(self):
712
        TestCaseInTempDir.setUp(self)
713
        self._oldhome = os.environ['HOME']
714
        self._tmpdir = tempfile.mkdtemp()
715
        self._homedir = os.path.join(self._tmpdir, 'home')
716
        os.mkdir(self._homedir)
717
        os.environ['HOME'] = self._homedir
718
        self._archiveroot = os.path.join(self._tmpdir, 'archive')
147.1.60 by Aaron Bentley
Stopped using deprecated PyBaz functionality
719
        self._archive = make_archive('demo@DONOTUSE', str(self._archiveroot))
147.1.15 by Robert Collins
archive at a time imports
720
721
    def tearDown(self):
722
        os.environ['HOME'] = self._oldhome
723
        shutil.rmtree(self._tmpdir)
724
        TestCaseInTempDir.tearDown(self)
725
726
    def make_import(self, namespace):
727
        self._import = 'demo@DONOTUSE/%s' % namespace
728
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
729
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
730
                               self._import)
147.1.15 by Robert Collins
archive at a time imports
731
        msg = tree.log_message()
732
        msg["summary"] = "I am importing now"
733
        tree.import_(msg)
734
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
735
147.1.11 by Robert Collins
move baz-import to baz-import-branch
736
    def test_cmd_exists(self):
430 by Aaron Bentley
Avoid loading PyBaz unless running baz-import
737
        from bzrlib.plugins.bzrtools import cmd_baz_import
147.1.12 by Robert Collins
create the output directory
738
739
    def test_empty_archive(self):
147.1.15 by Robert Collins
archive at a time imports
740
        command = cmd_baz_import()
741
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
742
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
743
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
594 by Aaron Bentley
Remove switch test
744
        self.assertEqual(9, walk_len)
147.1.12 by Robert Collins
create the output directory
745
147.1.15 by Robert Collins
archive at a time imports
746
    def test_two_branches(self):
747
        self.make_import('c--0')
748
        self.make_import('c1--branch--0.2')
749
        command = cmd_baz_import()
750
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
751
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
752
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
753
                                       'c','+trunk')))
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
754
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
755
                                                    'c1', '0.2','branch')))
435 by Aaron Bentley
Smarter fix
756
        default_format = repository.RepositoryFormat.get_default_format()
147.1.57 by Aaron Bentley
Cleaned up baz_import and tests
757
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
594 by Aaron Bentley
Remove switch test
758
        self.assertEqual(22, walk_len)
147.1.18 by Robert Collins
baz-import twice should work
759
760
    def test_run_twice(self):
761
        self.make_import('c--0')
762
        command = cmd_baz_import()
763
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
764
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
765
147.4.8 by Robert Collins
Enable reuse of history on archive imports, just append the history locations to the command line
766
    def test_accepts_reuse_history(self):
767
        self.make_import('c--0')
552 by Aaron Bentley
Fix deprecation warnings
768
        self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output'),
769
                      'demo@DONOTUSE', '.', '.'])
770
771
    def test_does_not_need_reuse_history(self):
772
        self.make_import('c--0')
773
        self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output'),
774
                      'demo@DONOTUSE'])
775
776
    def test_does_not_need_reuse_history(self):
777
        self.make_import('c--0')
778
        self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output'),
779
                      'demo@DONOTUSE'])
463 by Aaron Bentley
Get encoding flag under test
780
781
    def test_encoding_flag(self):
782
        self.make_import('c--0')
552 by Aaron Bentley
Fix deprecation warnings
783
        self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output'),
784
                      'demo@DONOTUSE'])
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
785
        self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
786
                         Branch.open(os.path.join(self._tmpdir,
463 by Aaron Bentley
Get encoding flag under test
787
                                     'output/c/+trunk')).revision_history())
552 by Aaron Bentley
Fix deprecation warnings
788
        self.run_bzr(['baz-import', os.path.join(self._tmpdir, 'output2'),
789
                      'demo@DONOTUSE', '--encoding', 'utf-8'])
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
790
        self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
791
                         Branch.open(os.path.join(self._tmpdir,
463 by Aaron Bentley
Get encoding flag under test
792
                                     'output2/c/+trunk')).revision_history())
552 by Aaron Bentley
Fix deprecation warnings
793
        self.run_bzr(['baz-import-branch', os.path.join(self._tmpdir,
794
                      'output3'), 'demo@DONOTUSE/c--0'])
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
795
        self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'],
796
                         Branch.open(os.path.join(self._tmpdir,
463 by Aaron Bentley
Get encoding flag under test
797
                                     'output3')).revision_history())
552 by Aaron Bentley
Fix deprecation warnings
798
        self.run_bzr(['baz-import-branch', os.path.join(self._tmpdir,
799
                      'output4'), 'demo@DONOTUSE/c--0', '--encoding', 'utf-8'])
531.2.2 by Charlie Shepherd
Remove all trailing whitespace
800
        self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'],
801
                         Branch.open(os.path.join(self._tmpdir,
463 by Aaron Bentley
Get encoding flag under test
802
                                     'output4')).revision_history())