/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
1399.1.12 by Robert Collins
add new test script
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
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1399.1.12 by Robert Collins
add new test script
17
7122.6.1 by Jelmer Vernooij
merge Parth's work into Breezy
18
from io import BytesIO
6469.1.19 by Parth Malwankar
added merge test
19
import os
20
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
21
from .. import (
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
22
    conflicts,
23
    errors,
6469.1.19 by Parth Malwankar
added merge test
24
    trace,
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
25
    transport,
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
26
    workingtree,
6670.4.1 by Jelmer Vernooij
Update imports.
27
    )
28
from ..bzr import (
29
    bzrdir,
30
    workingtree as bzrworkingtree,
5816.5.1 by Jelmer Vernooij
Move WorkingTree3 to bzrlib.workingtree_3.
31
    workingtree_3,
5816.5.7 by Jelmer Vernooij
Fix more imports.
32
    workingtree_4,
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
33
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
34
from ..lock import write_locked
35
from ..lockdir import LockDir
36
from . import TestCase, TestCaseWithTransport, TestSkipped
6846.6.1 by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree.
37
from ..tree import (
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
38
    TreeEntry,
39
    TreeDirectory,
40
    TreeFile,
41
    TreeLink,
42
    )
1399.1.12 by Robert Collins
add new test script
43
7122.6.1 by Jelmer Vernooij
merge Parth's work into Breezy
44
from .features import SymlinkFeature
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
45
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
46
class TestTreeDirectory(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
47
48
    def test_kind_character(self):
49
        self.assertEqual(TreeDirectory().kind_character(), '/')
50
51
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
52
class TestTreeEntry(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
53
54
    def test_kind_character(self):
55
        self.assertEqual(TreeEntry().kind_character(), '???')
56
57
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
58
class TestTreeFile(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
59
60
    def test_kind_character(self):
61
        self.assertEqual(TreeFile().kind_character(), '')
62
63
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
64
class TestTreeLink(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
65
66
    def test_kind_character(self):
67
        self.assertEqual(TreeLink().kind_character(), '')
68
69
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
70
class TestDefaultFormat(TestCaseWithTransport):
71
72
    def test_get_set_default_format(self):
5662.3.3 by Jelmer Vernooij
add tests
73
        old_format = workingtree.format_registry.get_default()
5816.5.2 by Jelmer Vernooij
Fix comment - default wt format is 6.
74
        # default is 6
7143.15.2 by Jelmer Vernooij
Run autopep8.
75
        self.assertTrue(isinstance(
76
            old_format, workingtree_4.WorkingTreeFormat6))
5662.3.3 by Jelmer Vernooij
add tests
77
        workingtree.format_registry.set_default(SampleTreeFormat())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
78
        try:
79
            # the default branch format is used by the meta dir format
80
            # which is not the default bzrdir format at this point
81
            dir = bzrdir.BzrDirMetaFormat1().initialize('.')
82
            dir.create_repository()
83
            dir.create_branch()
84
            result = dir.create_workingtree()
85
            self.assertEqual(result, 'A tree')
86
        finally:
5662.3.3 by Jelmer Vernooij
add tests
87
            workingtree.format_registry.set_default(old_format)
88
        self.assertEqual(old_format, workingtree.format_registry.get_default())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
89
6349.2.4 by Jelmer Vernooij
Add test for WorkingTreeFormat.from_string.
90
    def test_from_string(self):
91
        self.assertIsInstance(
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
92
            SampleTreeFormat.from_string(b"Sample tree format."),
6349.2.4 by Jelmer Vernooij
Add test for WorkingTreeFormat.from_string.
93
            SampleTreeFormat)
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
94
        self.assertRaises(
95
            AssertionError, SampleTreeFormat.from_string,
96
            b"Different format string.")
6349.2.4 by Jelmer Vernooij
Add test for WorkingTreeFormat.from_string.
97
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
98
    def test_get_set_default_format_by_key(self):
99
        old_format = workingtree.format_registry.get_default()
5816.5.7 by Jelmer Vernooij
Fix more imports.
100
        # default is 6
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
101
        format = SampleTreeFormat()
102
        workingtree.format_registry.register(format)
103
        self.addCleanup(workingtree.format_registry.remove, format)
7143.15.2 by Jelmer Vernooij
Run autopep8.
104
        self.assertTrue(isinstance(
105
            old_format, workingtree_4.WorkingTreeFormat6))
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
106
        workingtree.format_registry.set_default_key(format.get_format_string())
107
        try:
108
            # the default branch format is used by the meta dir format
109
            # which is not the default bzrdir format at this point
110
            dir = bzrdir.BzrDirMetaFormat1().initialize('.')
111
            dir.create_repository()
112
            dir.create_branch()
113
            result = dir.create_workingtree()
114
            self.assertEqual(result, 'A tree')
115
        finally:
116
            workingtree.format_registry.set_default_key(
117
                old_format.get_format_string())
118
        self.assertEqual(old_format, workingtree.format_registry.get_default())
119
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
120
    def test_open(self):
121
        tree = self.make_branch_and_tree('.')
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
122
        open_direct = workingtree.WorkingTree.open('.')
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
123
        self.assertEqual(tree.basedir, open_direct.basedir)
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
124
        open_no_args = workingtree.WorkingTree.open()
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
125
        self.assertEqual(tree.basedir, open_no_args.basedir)
126
127
    def test_open_containing(self):
128
        tree = self.make_branch_and_tree('.')
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
129
        open_direct, relpath = workingtree.WorkingTree.open_containing('.')
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
130
        self.assertEqual(tree.basedir, open_direct.basedir)
131
        self.assertEqual('', relpath)
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
132
        open_no_args, relpath = workingtree.WorkingTree.open_containing()
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
133
        self.assertEqual(tree.basedir, open_no_args.basedir)
134
        self.assertEqual('', relpath)
7143.15.2 by Jelmer Vernooij
Run autopep8.
135
        open_subdir, relpath = workingtree.WorkingTree.open_containing(
136
            'subdir')
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
137
        self.assertEqual(tree.basedir, open_subdir.basedir)
138
        self.assertEqual('subdir', relpath)
139
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
140
6653.3.1 by Jelmer Vernooij
Move bzr-specific code to breezy.bzrworkingtree.
141
class SampleTreeFormat(bzrworkingtree.WorkingTreeFormatMetaDir):
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
142
    """A sample format
143
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
144
    this format is initializable, unsupported to aid in testing the
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
145
    open and open_downlevel routines.
146
    """
147
6349.2.4 by Jelmer Vernooij
Add test for WorkingTreeFormat.from_string.
148
    @classmethod
149
    def get_format_string(cls):
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
150
        """See WorkingTreeFormat.get_format_string()."""
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
151
        return b"Sample tree format."
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
152
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
153
    def initialize(self, a_controldir, revision_id=None, from_branch=None,
3136.1.5 by Aaron Bentley
Fix sample workingtree format
154
                   accelerator_tree=None, hardlink=False):
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
155
        """Sample branches cannot be created."""
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
156
        t = a_controldir.get_workingtree_transport(self)
1955.3.13 by John Arbash Meinel
Run the full test suite, and fix up any deprecation warnings.
157
        t.put_bytes('format', self.get_format_string())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
158
        return 'A tree'
159
160
    def is_supported(self):
161
        return False
162
163
    def open(self, transport, _found=False):
164
        return "opened tree."
165
166
5642.2.4 by Jelmer Vernooij
add tests.
167
class SampleExtraTreeFormat(workingtree.WorkingTreeFormat):
168
    """A sample format that does not support use in a metadir.
169
170
    """
171
172
    def get_format_string(self):
173
        # Not usable in a metadir, so no format string
174
        return None
175
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
176
    def initialize(self, a_controldir, revision_id=None, from_branch=None,
5642.2.4 by Jelmer Vernooij
add tests.
177
                   accelerator_tree=None, hardlink=False):
178
        raise NotImplementedError(self.initialize)
179
180
    def is_supported(self):
181
        return False
182
183
    def open(self, transport, _found=False):
184
        raise NotImplementedError(self.open)
185
186
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
187
class TestWorkingTreeFormat(TestCaseWithTransport):
188
    """Tests for the WorkingTreeFormat facility."""
189
5816.3.3 by Jelmer Vernooij
Add tariff test to make sure working tree isn't opened by 'bzr serve'
190
    def test_find_format_string(self):
191
        # is the right format object found for a working tree?
192
        branch = self.make_branch('branch')
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
193
        self.assertRaises(
194
            errors.NoWorkingTree,
195
            bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string,
196
            branch.controldir)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
197
        transport = branch.controldir.get_workingtree_transport(None)
5816.3.3 by Jelmer Vernooij
Add tariff test to make sure working tree isn't opened by 'bzr serve'
198
        transport.mkdir('.')
7045.4.23 by Jelmer Vernooij
Fix some help tests.
199
        transport.put_bytes("format", b"some format name")
5816.3.3 by Jelmer Vernooij
Add tariff test to make sure working tree isn't opened by 'bzr serve'
200
        # The format does not have to be known by Bazaar,
201
        # find_format_string just retrieves the name
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
202
        self.assertEqual(
203
            b"some format name",
204
            bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string(
205
                branch.controldir))
5816.3.3 by Jelmer Vernooij
Add tariff test to make sure working tree isn't opened by 'bzr serve'
206
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
207
    def test_find_format(self):
208
        # is the right format object found for a working tree?
209
        # create a branch with a few known format objects.
210
        self.build_tree(["foo/", "bar/"])
7143.15.2 by Jelmer Vernooij
Run autopep8.
211
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
212
        def check_format(format, url):
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
213
            dir = format._matchingcontroldir.initialize(url)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
214
            dir.create_repository()
215
            dir.create_branch()
216
            format.initialize(dir)
7143.15.2 by Jelmer Vernooij
Run autopep8.
217
            found_format = bzrworkingtree.WorkingTreeFormatMetaDir.find_format(
218
                dir)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
219
            self.assertIsInstance(found_format, format.__class__)
5816.5.1 by Jelmer Vernooij
Move WorkingTree3 to bzrlib.workingtree_3.
220
        check_format(workingtree_3.WorkingTreeFormat3(), "bar")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
221
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
222
    def test_find_format_no_tree(self):
223
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
224
        self.assertRaises(errors.NoWorkingTree,
6653.5.1 by Jelmer Vernooij
Fix some more tests.
225
                          bzrworkingtree.WorkingTreeFormatMetaDir.find_format,
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
226
                          dir)
227
228
    def test_find_format_unknown_format(self):
229
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
230
        dir.create_repository()
231
        dir.create_branch()
232
        SampleTreeFormat().initialize(dir)
233
        self.assertRaises(errors.UnknownFormatError,
6653.5.1 by Jelmer Vernooij
Fix some more tests.
234
                          bzrworkingtree.WorkingTreeFormatMetaDir.find_format,
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
235
                          dir)
236
6213.1.36 by Jelmer Vernooij
Add news entry, test for working tree features.
237
    def test_find_format_with_features(self):
238
        tree = self.make_branch_and_tree('.', format='2a')
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
239
        tree.update_feature_flags({b"name": b"necessity"})
6653.5.1 by Jelmer Vernooij
Fix some more tests.
240
        found_format = bzrworkingtree.WorkingTreeFormatMetaDir.find_format(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
241
            tree.controldir)
6213.1.36 by Jelmer Vernooij
Add news entry, test for working tree features.
242
        self.assertIsInstance(found_format, workingtree.WorkingTreeFormat)
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
243
        self.assertEqual(found_format.features.get(b"name"), b"necessity")
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
244
        self.assertRaises(
245
            bzrdir.MissingFeature, found_format.check_support_status, True)
246
        self.addCleanup(
247
            bzrworkingtree.WorkingTreeFormatMetaDir.unregister_feature,
248
            b"name")
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
249
        bzrworkingtree.WorkingTreeFormatMetaDir.register_feature(b"name")
6213.1.36 by Jelmer Vernooij
Add news entry, test for working tree features.
250
        found_format.check_support_status(True)
251
5662.3.3 by Jelmer Vernooij
add tests
252
5786.1.5 by John Arbash Meinel
Move the logic about InventoryDirectory => TreeReference into iter_entries
253
class TestWorkingTreeIterEntriesByDir_wSubtrees(TestCaseWithTransport):
254
255
    def make_simple_tree(self):
256
        tree = self.make_branch_and_tree('tree', format='development-subtree')
257
        self.build_tree(['tree/a/', 'tree/a/b/', 'tree/a/b/c'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
258
        tree.set_root_id(b'root-id')
259
        tree.add(['a', 'a/b', 'a/b/c'], [b'a-id', b'b-id', b'c-id'])
5786.1.5 by John Arbash Meinel
Move the logic about InventoryDirectory => TreeReference into iter_entries
260
        tree.commit('initial')
261
        return tree
262
263
    def test_just_directory(self):
264
        tree = self.make_simple_tree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
265
        self.assertEqual([('directory', b'root-id'),
266
                          ('directory', b'a-id'),
267
                          ('directory', b'b-id'),
268
                          ('file', b'c-id')],
5786.1.5 by John Arbash Meinel
Move the logic about InventoryDirectory => TreeReference into iter_entries
269
                         [(ie.kind, ie.file_id)
270
                          for path, ie in tree.iter_entries_by_dir()])
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
271
        self.make_branch_and_tree('tree/a/b')
6855.4.1 by Jelmer Vernooij
Yet more bees.
272
        self.assertEqual([('tree-reference', b'b-id')],
5786.1.5 by John Arbash Meinel
Move the logic about InventoryDirectory => TreeReference into iter_entries
273
                         [(ie.kind, ie.file_id)
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
274
                          for path, ie in tree.iter_entries_by_dir(
275
                              specific_files=['a/b'])])
5786.1.5 by John Arbash Meinel
Move the logic about InventoryDirectory => TreeReference into iter_entries
276
277
    def test_direct_subtree(self):
278
        tree = self.make_simple_tree()
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
279
        self.make_branch_and_tree('tree/a/b')
6855.4.1 by Jelmer Vernooij
Yet more bees.
280
        self.assertEqual([('directory', b'root-id'),
281
                          ('directory', b'a-id'),
282
                          ('tree-reference', b'b-id')],
5786.1.5 by John Arbash Meinel
Move the logic about InventoryDirectory => TreeReference into iter_entries
283
                         [(ie.kind, ie.file_id)
284
                          for path, ie in tree.iter_entries_by_dir()])
285
286
    def test_indirect_subtree(self):
287
        tree = self.make_simple_tree()
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
288
        self.make_branch_and_tree('tree/a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
289
        self.assertEqual([('directory', b'root-id'),
290
                          ('tree-reference', b'a-id')],
5786.1.5 by John Arbash Meinel
Move the logic about InventoryDirectory => TreeReference into iter_entries
291
                         [(ie.kind, ie.file_id)
292
                          for path, ie in tree.iter_entries_by_dir()])
293
294
5662.3.3 by Jelmer Vernooij
add tests
295
class TestWorkingTreeFormatRegistry(TestCase):
296
297
    def setUp(self):
298
        super(TestWorkingTreeFormatRegistry, self).setUp()
299
        self.registry = workingtree.WorkingTreeFormatRegistry()
300
301
    def test_register_unregister_format(self):
302
        format = SampleTreeFormat()
303
        self.registry.register(format)
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
304
        self.assertEqual(format, self.registry.get(b"Sample tree format."))
5662.3.3 by Jelmer Vernooij
add tests
305
        self.registry.remove(format)
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
306
        self.assertRaises(KeyError, self.registry.get, b"Sample tree format.")
5662.3.3 by Jelmer Vernooij
add tests
307
308
    def test_get_all(self):
309
        format = SampleTreeFormat()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
310
        self.assertEqual([], self.registry._get_all())
5662.3.3 by Jelmer Vernooij
add tests
311
        self.registry.register(format)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
312
        self.assertEqual([format], self.registry._get_all())
5662.3.3 by Jelmer Vernooij
add tests
313
314
    def test_register_extra(self):
5642.2.4 by Jelmer Vernooij
add tests.
315
        format = SampleExtraTreeFormat()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
316
        self.assertEqual([], self.registry._get_all())
5662.3.3 by Jelmer Vernooij
add tests
317
        self.registry.register_extra(format)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
318
        self.assertEqual([format], self.registry._get_all())
5662.3.3 by Jelmer Vernooij
add tests
319
320
    def test_register_extra_lazy(self):
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
321
        self.assertEqual([], self.registry._get_all())
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
322
        self.registry.register_extra_lazy("breezy.tests.test_workingtree",
7143.15.2 by Jelmer Vernooij
Run autopep8.
323
                                          "SampleExtraTreeFormat")
5662.3.3 by Jelmer Vernooij
add tests
324
        formats = self.registry._get_all()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
325
        self.assertEqual(1, len(formats))
5662.3.3 by Jelmer Vernooij
add tests
326
        self.assertIsInstance(formats[0], SampleExtraTreeFormat)
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
327
328
329
class TestWorkingTreeFormat3(TestCaseWithTransport):
330
    """Tests specific to WorkingTreeFormat3."""
331
332
    def test_disk_layout(self):
333
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
334
        control.create_repository()
335
        control.create_branch()
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
336
        workingtree_3.WorkingTreeFormat3().initialize(control)
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
337
        # we want:
338
        # format 'Bazaar-NG Working Tree format 3'
339
        # inventory = blank inventory
340
        # pending-merges = ''
341
        # stat-cache = ??
342
        # no inventory.basis yet
343
        t = control.get_workingtree_transport(None)
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
344
        self.assertEqualDiff(b'Bazaar-NG Working Tree format 3',
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
345
                             t.get('format').read())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
346
        self.assertEqualDiff(t.get('inventory').read(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
347
                             b'<inventory format="5">\n'
348
                             b'</inventory>\n',
1731.1.33 by Aaron Bentley
Revert no-special-root changes
349
                             )
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
350
        self.assertEqualDiff(b'### bzr hashcache v5\n',
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
351
                             t.get('stat-cache').read())
352
        self.assertFalse(t.has('inventory.basis'))
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
353
        # no last-revision file means 'None' or 'NULLREVISION'
354
        self.assertFalse(t.has('last-revision'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
355
        # TODO RBC 20060210 do a commit, check the inventory.basis is created
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
356
        # correctly and last-revision file becomes present.
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
357
358
    def test_uses_lockdir(self):
359
        """WorkingTreeFormat3 uses its own LockDir:
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
360
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
361
            - lock is a directory
362
            - when the WorkingTree is locked, LockDir can see that
363
        """
364
        t = self.get_transport()
365
        url = self.get_url()
366
        dir = bzrdir.BzrDirMetaFormat1().initialize(url)
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
367
        dir.create_repository()
368
        dir.create_branch()
1558.10.1 by Aaron Bentley
Handle lockdirs over NFS properly
369
        try:
5816.5.1 by Jelmer Vernooij
Move WorkingTree3 to bzrlib.workingtree_3.
370
            tree = workingtree_3.WorkingTreeFormat3().initialize(dir)
1558.10.1 by Aaron Bentley
Handle lockdirs over NFS properly
371
        except errors.NotLocalUrl:
372
            raise TestSkipped('Not a local URL')
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
373
        self.assertIsDirectory('.bzr', t)
374
        self.assertIsDirectory('.bzr/checkout', t)
375
        self.assertIsDirectory('.bzr/checkout/lock', t)
376
        our_lock = LockDir(t, '.bzr/checkout/lock')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
377
        self.assertEqual(our_lock.peek(), None)
6969.3.2 by Jelmer Vernooij
Use context managers for locking.
378
        with tree.lock_write():
379
            self.assertTrue(our_lock.peek())
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
380
        self.assertEqual(our_lock.peek(), None)
1534.10.6 by Aaron Bentley
Conflict serialization working for WorkingTree3
381
1815.2.2 by Jelmer Vernooij
Move missing_pending_merges test to WorkingTreeFormat3-specific tests.
382
    def test_missing_pending_merges(self):
383
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
384
        control.create_repository()
385
        control.create_branch()
5816.5.1 by Jelmer Vernooij
Move WorkingTree3 to bzrlib.workingtree_3.
386
        tree = workingtree_3.WorkingTreeFormat3().initialize(control)
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
387
        tree._transport.delete("pending-merges")
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
388
        self.assertEqual([], tree.get_parent_ids())
1815.2.2 by Jelmer Vernooij
Move missing_pending_merges test to WorkingTreeFormat3-specific tests.
389
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
390
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
391
class TestRevert(TestCaseWithTransport):
392
393
    def test_revert_conflicts_recursive(self):
394
        this_tree = self.make_branch_and_tree('this-tree')
395
        self.build_tree_contents([('this-tree/foo/',),
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
396
                                  ('this-tree/foo/bar', b'bar')])
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
397
        this_tree.add(['foo', 'foo/bar'])
398
        this_tree.commit('created foo/bar')
7143.15.2 by Jelmer Vernooij
Run autopep8.
399
        other_tree = this_tree.controldir.sprout(
400
            'other-tree').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
401
        self.build_tree_contents([('other-tree/foo/bar', b'baz')])
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
402
        other_tree.commit('changed bar')
6855.4.1 by Jelmer Vernooij
Yet more bees.
403
        self.build_tree_contents([('this-tree/foo/bar', b'qux')])
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
404
        this_tree.commit('changed qux')
405
        this_tree.merge_from_branch(other_tree.branch)
406
        self.assertEqual(1, len(this_tree.conflicts()))
407
        this_tree.revert(['foo'])
408
        self.assertEqual(0, len(this_tree.conflicts()))
409
410
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
411
class TestAutoResolve(TestCaseWithTransport):
412
413
    def test_auto_resolve(self):
414
        base = self.make_branch_and_tree('base')
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
415
        self.build_tree_contents([('base/hello', b'Hello')])
6855.4.1 by Jelmer Vernooij
Yet more bees.
416
        base.add('hello', b'hello_id')
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
417
        base.commit('Hello')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
418
        other = base.controldir.sprout('other').open_workingtree()
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
419
        self.build_tree_contents([('other/hello', b'hELLO')])
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
420
        other.commit('Case switch')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
421
        this = base.controldir.sprout('this').open_workingtree()
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
422
        self.assertPathExists('this/hello')
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
423
        self.build_tree_contents([('this/hello', b'Hello World')])
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
424
        this.commit('Add World')
425
        this.merge_from_branch(other.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
426
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
427
                         this.conflicts())
428
        this.auto_resolve()
6855.4.1 by Jelmer Vernooij
Yet more bees.
429
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
430
                         this.conflicts())
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
431
        self.build_tree_contents([('this/hello', b'<<<<<<<')])
432
        this.auto_resolve()
6855.4.1 by Jelmer Vernooij
Yet more bees.
433
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
434
                         this.conflicts())
435
        self.build_tree_contents([('this/hello', b'=======')])
436
        this.auto_resolve()
6855.4.1 by Jelmer Vernooij
Yet more bees.
437
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
438
                         this.conflicts())
439
        self.build_tree_contents([('this/hello', b'\n>>>>>>>')])
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
440
        remaining, resolved = this.auto_resolve()
6855.4.1 by Jelmer Vernooij
Yet more bees.
441
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
442
                         this.conflicts())
443
        self.assertEqual([], resolved)
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
444
        self.build_tree_contents([('this/hello', b'hELLO wORLD')])
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
445
        remaining, resolved = this.auto_resolve()
446
        self.assertEqual([], this.conflicts())
6855.4.1 by Jelmer Vernooij
Yet more bees.
447
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
448
                         resolved)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
449
        self.assertPathDoesNotExist('this/hello.BASE')
2120.7.3 by Aaron Bentley
Update resolve command to automatically mark conflicts as resolved
450
6469.1.19 by Parth Malwankar
added merge test
451
    def test_unsupported_symlink_auto_resolve(self):
452
        self.requireFeature(SymlinkFeature)
453
        base = self.make_branch_and_tree('base')
454
        self.build_tree_contents([('base/hello', 'Hello')])
7122.6.12 by Jelmer Vernooij
Fix more python3 tests.
455
        base.add('hello', b'hello_id')
6469.1.19 by Parth Malwankar
added merge test
456
        base.commit('commit 0')
7122.6.1 by Jelmer Vernooij
merge Parth's work into Breezy
457
        other = base.controldir.sprout('other').open_workingtree()
6469.1.19 by Parth Malwankar
added merge test
458
        self.build_tree_contents([('other/hello', 'Hello')])
459
        os.symlink('other/hello', 'other/foo')
7122.6.12 by Jelmer Vernooij
Fix more python3 tests.
460
        other.add('foo', b'foo_id')
6469.1.19 by Parth Malwankar
added merge test
461
        other.commit('commit symlink')
7122.6.1 by Jelmer Vernooij
merge Parth's work into Breezy
462
        this = base.controldir.sprout('this').open_workingtree()
6469.1.19 by Parth Malwankar
added merge test
463
        self.assertPathExists('this/hello')
464
        self.build_tree_contents([('this/hello', 'Hello')])
465
        this.commit('commit 2')
7122.6.1 by Jelmer Vernooij
merge Parth's work into Breezy
466
        log = BytesIO()
6469.1.19 by Parth Malwankar
added merge test
467
        trace.push_log_file(log)
468
        os_symlink = getattr(os, 'symlink', None)
469
        os.symlink = None
470
        try:
471
            this.merge_from_branch(other.branch)
472
        finally:
473
            if os_symlink:
474
                os.symlink = os_symlink
475
        self.assertContainsRe(
476
            log.getvalue(),
7122.6.6 by Jelmer Vernooij
Fix more tests.
477
            b'Unable to create symlink "foo" on this filesystem')
6469.1.19 by Parth Malwankar
added merge test
478
2120.7.3 by Aaron Bentley
Update resolve command to automatically mark conflicts as resolved
479
    def test_auto_resolve_dir(self):
480
        tree = self.make_branch_and_tree('tree')
481
        self.build_tree(['tree/hello/'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
482
        tree.add('hello', b'hello-id')
483
        file_conflict = conflicts.TextConflict('file', b'hello-id')
2120.7.3 by Aaron Bentley
Update resolve command to automatically mark conflicts as resolved
484
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
485
        tree.auto_resolve()
3140.1.4 by Aaron Bentley
Add WorkingTree.find_trees
486
487
6538.1.5 by Aaron Bentley
Implement WorkingTree.store_uncommitted.
488
class TestStoredUncommitted(TestCaseWithTransport):
489
490
    def store_uncommitted(self):
491
        tree = self.make_branch_and_tree('tree')
492
        tree.commit('get root in there')
6855.4.1 by Jelmer Vernooij
Yet more bees.
493
        self.build_tree_contents([('tree/file', b'content')])
494
        tree.add('file', b'file-id')
6538.1.5 by Aaron Bentley
Implement WorkingTree.store_uncommitted.
495
        tree.store_uncommitted()
496
        return tree
497
498
    def test_store_uncommitted(self):
499
        self.store_uncommitted()
500
        self.assertPathDoesNotExist('tree/file')
501
502
    def test_store_uncommitted_no_change(self):
503
        tree = self.make_branch_and_tree('tree')
504
        tree.commit('get root in there')
505
        tree.store_uncommitted()
6538.1.24 by Aaron Bentley
Eliminate get_stored_uncommitted from API.
506
        self.assertIs(None, tree.branch.get_unshelver(tree))
6538.1.10 by Aaron Bentley
Implement WorkingTree.get_uncommitted_data
507
6538.1.11 by Aaron Bentley
Switch to much simpler implementation of restore_uncommitted.
508
    def test_restore_uncommitted(self):
509
        with write_locked(self.store_uncommitted()) as tree:
510
            tree.restore_uncommitted()
511
            self.assertPathExists('tree/file')
6538.1.24 by Aaron Bentley
Eliminate get_stored_uncommitted from API.
512
            self.assertIs(None, tree.branch.get_unshelver(tree))
6538.1.11 by Aaron Bentley
Switch to much simpler implementation of restore_uncommitted.
513
514
    def test_restore_uncommitted_none(self):
515
        tree = self.make_branch_and_tree('tree')
516
        tree.restore_uncommitted()