/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) 2006-2012, 2016 Canonical Ltd
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
2
# Authors:  Robert Collins <robert.collins@canonical.com>
2255.13.4 by Martin Pool
merge
3
#           and others
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
18
3136.1.10 by Aaron Bentley
Clean error if filesystem does not support hard-links
19
import errno
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
20
import os
21
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from ... import (
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
23
    branch,
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
24
    config,
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
25
    controldir,
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
26
    errors,
27
    osutils,
6241.3.1 by Jelmer Vernooij
Support WorkingTree.clone() having its revision argument set to the NULL revision.
28
    revision as _mod_revision,
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
29
    tests,
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
30
    trace,
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
31
    urlutils,
5582.4.3 by Jelmer Vernooij
remove more unused imports, avoid relying on a specific set of working tree formats that support references.
32
    )
6670.4.15 by Jelmer Vernooij
Fix per workingtree tests.
33
from...bzr import (
34
    bzrdir,
35
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
36
from ...errors import (
5582.4.3 by Jelmer Vernooij
remove more unused imports, avoid relying on a specific set of working tree formats that support references.
37
    UnsupportedOperation,
38
    PathsNotVersionedError,
39
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
40
from ...bzr.inventory import Inventory
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
41
from ...mutabletree import MutableTree
42
from ...osutils import pathjoin, getcwd, has_symlinks
43
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
44
    BytesIO,
45
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
46
from .. import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
47
    features,
48
    TestSkipped,
49
    TestNotApplicable,
50
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
51
from .  import TestCaseWithWorkingTree
6670.4.3 by Jelmer Vernooij
Fix more imports.
52
from ...bzr.workingtree import (
6653.5.1 by Jelmer Vernooij
Fix some more tests.
53
    InventoryWorkingTree,
54
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
55
from ...workingtree import (
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
56
    SettingFileIdUnsupported,
5582.4.3 by Jelmer Vernooij
remove more unused imports, avoid relying on a specific set of working tree formats that support references.
57
    TreeDirectory,
58
    TreeFile,
59
    TreeLink,
60
    WorkingTree,
61
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
62
from ...conflicts import ConflictList, TextConflict, ContentsConflict
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
63
1711.7.19 by John Arbash Meinel
file:// urls look slightly different on win32
64
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
65
class TestWorkingTree(TestCaseWithWorkingTree):
66
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
67
    def requireBranchReference(self):
68
        test_branch = self.make_branch('test-branch')
69
        try:
70
            # if there is a working tree now, this is not supported.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
71
            test_branch.controldir.open_workingtree()
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
72
            raise TestNotApplicable("only on trees that can be separate"
73
                " from their branch.")
74
        except (errors.NoWorkingTree, errors.NotLocalUrl):
75
            pass
76
5516.1.1 by Vincent Ladeuil
TestCaseWithWorkingTree.make_branch_builder respects its relpath parameter.
77
    def test_branch_builder(self):
78
        # Just a smoke test that we get a branch at the specified relpath
79
        builder = self.make_branch_builder('foobar')
6437.70.9 by John Arbash Meinel
branch_builder builds in the branch/repository location, not in the wt location.
80
        br = branch.Branch.open(self.get_url('foobar'))
5516.1.1 by Vincent Ladeuil
TestCaseWithWorkingTree.make_branch_builder respects its relpath parameter.
81
1732.1.8 by John Arbash Meinel
Adding a test for list_files
82
    def test_list_files(self):
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
83
        tree = self.make_branch_and_tree('.')
1732.1.8 by John Arbash Meinel
Adding a test for list_files
84
        self.build_tree(['dir/', 'file'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
85
        if has_symlinks():
86
            os.symlink('target', 'symlink')
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
87
        tree.lock_read()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
88
        files = list(tree.list_files())
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
89
        tree.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
90
        self.assertEqual(files[0], ('dir', '?', 'directory', None, TreeDirectory()))
91
        self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile()))
92
        if has_symlinks():
93
            self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
94
1732.1.8 by John Arbash Meinel
Adding a test for list_files
95
    def test_list_files_sorted(self):
96
        tree = self.make_branch_and_tree('.')
1836.1.18 by John Arbash Meinel
Cleaned up the last failing tests. All tests pass again.
97
        self.build_tree(['dir/', 'file', 'dir/file', 'dir/b',
98
                         'dir/subdir/', 'a', 'dir/subfile',
99
                         'zz_dir/', 'zz_dir/subfile'])
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
100
        tree.lock_read()
1836.1.18 by John Arbash Meinel
Cleaned up the last failing tests. All tests pass again.
101
        files = [(path, kind) for (path, v, kind, file_id, entry)
102
                               in tree.list_files()]
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
103
        tree.unlock()
1732.1.8 by John Arbash Meinel
Adding a test for list_files
104
        self.assertEqual([
105
            ('a', 'file'),
106
            ('dir', 'directory'),
107
            ('file', 'file'),
1732.1.25 by John Arbash Meinel
Fix list_files test, we don't need to check if children are empty if we fall off the loop.
108
            ('zz_dir', 'directory'),
1732.1.8 by John Arbash Meinel
Adding a test for list_files
109
            ], files)
110
1732.1.25 by John Arbash Meinel
Fix list_files test, we don't need to check if children are empty if we fall off the loop.
111
        tree.add(['dir', 'zz_dir'])
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
112
        tree.lock_read()
1836.1.18 by John Arbash Meinel
Cleaned up the last failing tests. All tests pass again.
113
        files = [(path, kind) for (path, v, kind, file_id, entry)
114
                               in tree.list_files()]
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
115
        tree.unlock()
1732.1.8 by John Arbash Meinel
Adding a test for list_files
116
        self.assertEqual([
117
            ('a', 'file'),
118
            ('dir', 'directory'),
119
            ('dir/b', 'file'),
120
            ('dir/file', 'file'),
121
            ('dir/subdir', 'directory'),
122
            ('dir/subfile', 'file'),
123
            ('file', 'file'),
1732.1.22 by John Arbash Meinel
Bug in list_files if the last entry in a directory is another directory
124
            ('zz_dir', 'directory'),
125
            ('zz_dir/subfile', 'file'),
1732.1.8 by John Arbash Meinel
Adding a test for list_files
126
            ], files)
127
1551.10.29 by Aaron Bentley
Fix tree.list_files when file kind changes
128
    def test_list_files_kind_change(self):
129
        tree = self.make_branch_and_tree('tree')
130
        self.build_tree(['tree/filename'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
131
        tree.add('filename')
1551.10.29 by Aaron Bentley
Fix tree.list_files when file kind changes
132
        os.unlink('tree/filename')
133
        self.build_tree(['tree/filename/'])
134
        tree.lock_read()
135
        self.addCleanup(tree.unlock)
136
        result = list(tree.list_files())
137
        self.assertEqual(1, len(result))
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
138
        self.assertEqual(
139
                ('filename', 'V', 'directory', tree.path2id('filename')),
140
                result[0][:4])
1551.10.29 by Aaron Bentley
Fix tree.list_files when file kind changes
141
6449.4.5 by Jelmer Vernooij
Review feedback from vila.
142
    def test_get_config_stack(self):
6449.4.1 by Jelmer Vernooij
Add convenience method WorkingTree.get_config_stack().
143
        # Smoke test that all working trees succeed getting a config
144
        wt = self.make_branch_and_tree('.')
6449.4.3 by Jelmer Vernooij
Use WorkingTree.get_config_stack.
145
        conf = wt.get_config_stack()
6449.4.6 by Jelmer Vernooij
Fix typo.
146
        self.assertIsInstance(conf, config.Stack)
6449.4.1 by Jelmer Vernooij
Add convenience method WorkingTree.get_config_stack().
147
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
148
    def test_open_containing(self):
6437.70.7 by John Arbash Meinel
one more test that wanted to have a branch reference
149
        local_wt = self.make_branch_and_tree('.')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
150
        local_url = local_wt.controldir.root_transport.base
6437.70.7 by John Arbash Meinel
one more test that wanted to have a branch reference
151
        local_base = urlutils.local_path_from_url(local_url)
152
        del local_wt
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
153
154
        # Empty opens '.'
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
155
        wt, relpath = WorkingTree.open_containing()
156
        self.assertEqual('', relpath)
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
157
        self.assertEqual(wt.basedir + '/', local_base)
158
159
        # '.' opens this dir
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
160
        wt, relpath = WorkingTree.open_containing(u'.')
161
        self.assertEqual('', relpath)
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
162
        self.assertEqual(wt.basedir + '/', local_base)
163
164
        # './foo' finds '.' and a relpath of 'foo'
165
        wt, relpath = WorkingTree.open_containing('./foo')
166
        self.assertEqual('foo', relpath)
167
        self.assertEqual(wt.basedir + '/', local_base)
168
169
        # abspath(foo) finds '.' and relpath of 'foo'
170
        wt, relpath = WorkingTree.open_containing('./foo')
171
        wt, relpath = WorkingTree.open_containing(getcwd() + '/foo')
172
        self.assertEqual('foo', relpath)
173
        self.assertEqual(wt.basedir + '/', local_base)
174
175
        # can even be a url: finds '.' and relpath of 'foo'
176
        wt, relpath = WorkingTree.open_containing('./foo')
177
        wt, relpath = WorkingTree.open_containing(
178
                    urlutils.local_path_to_url(getcwd() + '/foo'))
179
        self.assertEqual('foo', relpath)
180
        self.assertEqual(wt.basedir + '/', local_base)
181
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
182
    def test_basic_relpath(self):
183
        # for comprehensive relpath tests, see whitebox.py.
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
184
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
185
        self.assertEqual('child',
186
                         tree.relpath(pathjoin(getcwd(), 'child')))
187
188
    def test_lock_locks_branch(self):
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
189
        tree = self.make_branch_and_tree('.')
6437.70.8 by John Arbash Meinel
trivially implement peek_lock_mode.
190
        self.assertEqual(None, tree.branch.peek_lock_mode())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
191
        tree.lock_read()
192
        self.assertEqual('r', tree.branch.peek_lock_mode())
193
        tree.unlock()
194
        self.assertEqual(None, tree.branch.peek_lock_mode())
195
        tree.lock_write()
196
        self.assertEqual('w', tree.branch.peek_lock_mode())
197
        tree.unlock()
198
        self.assertEqual(None, tree.branch.peek_lock_mode())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
199
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
200
    def test_revert(self):
201
        """Test selected-file revert"""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
202
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
203
204
        self.build_tree(['hello.txt'])
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
205
        with file('hello.txt', 'w') as f: f.write('initial hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
206
1551.7.17 by Aaron Bentley
Switch to PathsNotVersioned, accept extra_trees
207
        self.assertRaises(PathsNotVersionedError,
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
208
                          tree.revert, ['hello.txt'])
209
        tree.add(['hello.txt'])
210
        tree.commit('create initial hello.txt')
211
212
        self.check_file_contents('hello.txt', 'initial hello')
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
213
        with file('hello.txt', 'w') as f: f.write('new hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
214
        self.check_file_contents('hello.txt', 'new hello')
215
216
        # revert file modified since last revision
217
        tree.revert(['hello.txt'])
218
        self.check_file_contents('hello.txt', 'initial hello')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
219
        self.check_file_contents('hello.txt.~1~', 'new hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
220
221
        # reverting again does not clobber the backup
222
        tree.revert(['hello.txt'])
223
        self.check_file_contents('hello.txt', 'initial hello')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
224
        self.check_file_contents('hello.txt.~1~', 'new hello')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
225
1534.10.28 by Aaron Bentley
Use numbered backup files
226
        # backup files are numbered
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
227
        with file('hello.txt', 'w') as f: f.write('new hello2')
1534.10.28 by Aaron Bentley
Use numbered backup files
228
        tree.revert(['hello.txt'])
229
        self.check_file_contents('hello.txt', 'initial hello')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
230
        self.check_file_contents('hello.txt.~1~', 'new hello')
231
        self.check_file_contents('hello.txt.~2~', 'new hello2')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
232
1558.12.7 by Aaron Bentley
Fixed revert with missing files
233
    def test_revert_missing(self):
234
        # Revert a file that has been deleted since last commit
235
        tree = self.make_branch_and_tree('.')
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
236
        with file('hello.txt', 'w') as f: f.write('initial hello')
1558.12.7 by Aaron Bentley
Fixed revert with missing files
237
        tree.add('hello.txt')
238
        tree.commit('added hello.txt')
239
        os.unlink('hello.txt')
240
        tree.remove('hello.txt')
241
        tree.revert(['hello.txt'])
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
242
        self.assertPathExists('hello.txt')
1558.12.7 by Aaron Bentley
Fixed revert with missing files
243
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
244
    def test_versioned_files_not_unknown(self):
245
        tree = self.make_branch_and_tree('.')
1831.1.1 by Martin Pool
[merge] remove default ignore list & update
246
        self.build_tree(['hello.txt'])
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
247
        tree.add('hello.txt')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
248
        self.assertEqual(list(tree.unknowns()),
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
249
                          [])
1831.1.1 by Martin Pool
[merge] remove default ignore list & update
250
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
251
    def test_unknowns(self):
252
        tree = self.make_branch_and_tree('.')
253
        self.build_tree(['hello.txt',
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
254
                         'hello.txt.~1~'])
1765.1.1 by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add.
255
        self.build_tree_contents([('.bzrignore', '*.~*\n')])
256
        tree.add('.bzrignore')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
257
        self.assertEqual(list(tree.unknowns()),
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
258
                          ['hello.txt'])
259
260
    def test_initialize(self):
261
        # initialize should create a working tree and branch in an existing dir
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
262
        t = self.make_branch_and_tree('.')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
263
        b = branch.Branch.open('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
264
        self.assertEqual(t.branch.base, b.base)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
265
        t2 = WorkingTree.open('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
266
        self.assertEqual(t.basedir, t2.basedir)
267
        self.assertEqual(b.base, t2.branch.base)
268
        # TODO maybe we should check the branch format? not sure if its
269
        # appropriate here.
270
271
    def test_rename_dirs(self):
272
        """Test renaming directories and the files within them."""
273
        wt = self.make_branch_and_tree('.')
274
        b = wt.branch
275
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
276
        wt.add(['dir', 'dir/sub', 'dir/sub/file'])
277
278
        wt.commit('create initial state')
279
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
280
        revid = b.last_revision()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
281
        self.log('first revision_id is {%s}' % revid)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
282
5807.1.5 by Jelmer Vernooij
Fix more things to use tree objects.
283
        tree = b.repository.revision_tree(revid)
284
        self.log('contents of tree: %r' % list(tree.iter_entries_by_dir()))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
285
5807.1.5 by Jelmer Vernooij
Fix more things to use tree objects.
286
        self.check_tree_shape(tree, ['dir/', 'dir/sub/', 'dir/sub/file'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
287
        wt.rename_one('dir', 'newdir')
288
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
289
        wt.lock_read()
5807.1.5 by Jelmer Vernooij
Fix more things to use tree objects.
290
        self.check_tree_shape(wt,
2545.3.2 by James Westby
Add a test for check_inventory_shape.
291
                                   ['newdir/', 'newdir/sub/', 'newdir/sub/file'])
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
292
        wt.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
293
        wt.rename_one('newdir/sub', 'newdir/newsub')
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
294
        wt.lock_read()
5807.1.5 by Jelmer Vernooij
Fix more things to use tree objects.
295
        self.check_tree_shape(wt, ['newdir/', 'newdir/newsub/',
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
296
                                    'newdir/newsub/file'])
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
297
        wt.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
298
299
    def test_add_in_unversioned(self):
300
        """Try to add a file in an unversioned directory.
301
302
        "bzr add" adds the parent as necessary, but simple working tree add
303
        doesn't do that.
304
        """
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
305
        from breezy.errors import NotVersionedError
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
306
        wt = self.make_branch_and_tree('.')
307
        self.build_tree(['foo/',
308
                         'foo/hello'])
6072.1.2 by Jelmer Vernooij
Fix versioned directories tests.
309
        if not wt._format.supports_versioned_directories:
6072.1.1 by Jelmer Vernooij
Various fixes for tests of foreign plugins.
310
            wt.add('foo/hello')
311
        else:
312
            self.assertRaises(NotVersionedError,
313
                              wt.add,
314
                              'foo/hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
315
316
    def test_add_missing(self):
317
        # adding a msising file -> NoSuchFile
318
        wt = self.make_branch_and_tree('.')
319
        self.assertRaises(errors.NoSuchFile, wt.add, 'fpp')
320
321
    def test_remove_verbose(self):
322
        #FIXME the remove api should not print or otherwise depend on the
323
        # text UI - RBC 20060124
324
        wt = self.make_branch_and_tree('.')
325
        self.build_tree(['hello'])
326
        wt.add(['hello'])
327
        wt.commit(message='add hello')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
328
        stdout = BytesIO()
329
        stderr = BytesIO()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
330
        self.assertEqual(None, self.apply_redirected(None, stdout, stderr,
331
                                                     wt.remove,
332
                                                     ['hello'],
333
                                                     verbose=True))
334
        self.assertEqual('?       hello\n', stdout.getvalue())
335
        self.assertEqual('', stderr.getvalue())
336
337
    def test_clone_trivial(self):
338
        wt = self.make_branch_and_tree('source')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
339
        cloned_dir = wt.controldir.clone('target')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
340
        cloned = cloned_dir.open_workingtree()
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
341
        self.assertEqual(cloned.get_parent_ids(), wt.get_parent_ids())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
342
6241.3.1 by Jelmer Vernooij
Support WorkingTree.clone() having its revision argument set to the NULL revision.
343
    def test_clone_empty(self):
344
        wt = self.make_branch_and_tree('source')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
345
        cloned_dir = wt.controldir.clone('target', revision_id=_mod_revision.NULL_REVISION)
6241.3.1 by Jelmer Vernooij
Support WorkingTree.clone() having its revision argument set to the NULL revision.
346
        cloned = cloned_dir.open_workingtree()
347
        self.assertEqual(cloned.get_parent_ids(), wt.get_parent_ids())
348
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
349
    def test_last_revision(self):
350
        wt = self.make_branch_and_tree('source')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
351
        self.assertEqual([], wt.get_parent_ids())
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
352
        a = wt.commit('A', allow_pointless=True)
2249.5.7 by John Arbash Meinel
Make sure WorkingTree revision_ids are also returned as utf8 strings
353
        parent_ids = wt.get_parent_ids()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
354
        self.assertEqual([a], parent_ids)
2249.5.7 by John Arbash Meinel
Make sure WorkingTree revision_ids are also returned as utf8 strings
355
        for parent_id in parent_ids:
356
            self.assertIsInstance(parent_id, str)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
357
358
    def test_set_last_revision(self):
359
        wt = self.make_branch_and_tree('source')
1908.1.1 by Robert Collins
Relax WorkingTree.set_last-revision to allow any revision to be set.
360
        # set last-revision to one not in the history
361
        wt.set_last_revision('A')
362
        # set it back to None for an empty tree.
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
363
        wt.set_last_revision('null:')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
364
        a = wt.commit('A', allow_pointless=True)
6747.2.2 by Jelmer Vernooij
Fix tests.
365
        self.assertEqual([a], wt.get_parent_ids())
6498.3.4 by Jelmer Vernooij
Remove more .set_revision_history / .revision_history references.
366
        # null: is aways in the branch
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
367
        wt.set_last_revision('null:')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
368
        self.assertEqual([], wt.get_parent_ids())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
369
        # and now we can set it to 'A'
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
370
        # because some formats mutate the branch to set it on the tree
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
371
        # we need to alter the branch to let this pass.
6498.3.4 by Jelmer Vernooij
Remove more .set_revision_history / .revision_history references.
372
        if getattr(wt.branch, "_set_revision_history", None) is None:
2230.3.27 by Aaron Bentley
Skip arbitrary revision-history test for Branch6
373
            raise TestSkipped("Branch format does not permit arbitrary"
374
                              " history")
6747.2.2 by Jelmer Vernooij
Fix tests.
375
        wt.branch._set_revision_history([a, 'B'])
376
        wt.set_last_revision(a)
377
        self.assertEqual([a], wt.get_parent_ids())
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
378
        self.assertRaises(errors.ReservedId, wt.set_last_revision, 'A:')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
379
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
380
    def test_set_last_revision_different_to_branch(self):
381
        # working tree formats from the meta-dir format and newer support
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
382
        # setting the last revision on a tree independently of that on the
383
        # branch. Its concievable that some future formats may want to
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
384
        # couple them again (i.e. because its really a smart server and
385
        # the working tree will always match the branch). So we test
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
386
        # that formats where initialising a branch does not initialise a
387
        # tree - and thus have separable entities - support skewing the
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
388
        # two things.
6437.70.7 by John Arbash Meinel
one more test that wanted to have a branch reference
389
        self.requireBranchReference()
390
        wt = self.make_branch_and_tree('tree')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
391
        a = wt.commit('A', allow_pointless=True)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
392
        wt.set_last_revision(None)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
393
        self.assertEqual([], wt.get_parent_ids())
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
394
        self.assertEqual(a, wt.branch.last_revision())
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
395
        # and now we can set it back to 'A'
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
396
        wt.set_last_revision(a)
397
        self.assertEqual([a], wt.get_parent_ids())
398
        self.assertEqual(a, wt.branch.last_revision())
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
399
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
400
    def test_clone_and_commit_preserves_last_revision(self):
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
401
        """Doing a commit into a clone tree does not affect the source."""
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
402
        wt = self.make_branch_and_tree('source')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
403
        cloned_dir = wt.controldir.clone('target')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
404
        wt.commit('A', allow_pointless=True)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
405
        self.assertNotEqual(cloned_dir.open_workingtree().get_parent_ids(),
406
                            wt.get_parent_ids())
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
407
408
    def test_clone_preserves_content(self):
409
        wt = self.make_branch_and_tree('source')
2255.2.51 by John Arbash Meinel
simple rewrap for 79 char lines
410
        self.build_tree(['added', 'deleted', 'notadded'],
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
411
                        transport=wt.controldir.transport.clone('..'))
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
412
        wt.add('deleted', 'deleted')
413
        wt.commit('add deleted')
414
        wt.remove('deleted')
415
        wt.add('added', 'added')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
416
        cloned_dir = wt.controldir.clone('target')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
417
        cloned = cloned_dir.open_workingtree()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
418
        cloned_transport = cloned.controldir.transport.clone('..')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
419
        self.assertFalse(cloned_transport.has('deleted'))
420
        self.assertTrue(cloned_transport.has('added'))
421
        self.assertFalse(cloned_transport.has('notadded'))
422
        self.assertEqual('added', cloned.path2id('added'))
423
        self.assertEqual(None, cloned.path2id('deleted'))
424
        self.assertEqual(None, cloned.path2id('notadded'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
425
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
426
    def test_basis_tree_returns_last_revision(self):
427
        wt = self.make_branch_and_tree('.')
428
        self.build_tree(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
429
        wt.add('foo')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
430
        a = wt.commit('A')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
431
        wt.rename_one('foo', 'bar')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
432
        b = wt.commit('B')
433
        wt.set_parent_ids([b])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
434
        tree = wt.basis_tree()
2255.2.30 by Robert Collins
Some workingtree_implementations/test_workingtree.py test work - add DirStateRevisionTree.has_filename, locks around appropriate calls in tests.
435
        tree.lock_read()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
436
        self.assertTrue(tree.has_filename('bar'))
2255.2.30 by Robert Collins
Some workingtree_implementations/test_workingtree.py test work - add DirStateRevisionTree.has_filename, locks around appropriate calls in tests.
437
        tree.unlock()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
438
        wt.set_parent_ids([a])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
439
        tree = wt.basis_tree()
2255.2.30 by Robert Collins
Some workingtree_implementations/test_workingtree.py test work - add DirStateRevisionTree.has_filename, locks around appropriate calls in tests.
440
        tree.lock_read()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
441
        self.assertTrue(tree.has_filename('foo'))
2255.2.30 by Robert Collins
Some workingtree_implementations/test_workingtree.py test work - add DirStateRevisionTree.has_filename, locks around appropriate calls in tests.
442
        tree.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
443
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
444
    def test_clone_tree_revision(self):
445
        # make a tree with a last-revision,
446
        # and clone it with a different last-revision, this should switch
447
        # do it.
448
        #
449
        # also test that the content is merged
450
        # and conflicts recorded.
451
        # This should merge between the trees - local edits should be preserved
452
        # but other changes occured.
453
        # we test this by having one file that does
454
        # not change between two revisions, and another that does -
455
        # if the changed one is not changed, fail,
456
        # if the one that did not change has lost a local change, fail.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
457
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
458
        raise TestSkipped('revision limiting is not implemented yet.')
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
459
460
    def test_initialize_with_revision_id(self):
461
        # a bzrdir can construct a working tree for itself @ a specific revision.
462
        source = self.make_branch_and_tree('source')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
463
        a = source.commit('a', allow_pointless=True)
464
        source.commit('b', allow_pointless=True)
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
465
        self.build_tree(['new/'])
466
        made_control = self.bzrdir_format.initialize('new')
467
        source.branch.repository.clone(made_control)
468
        source.branch.clone(made_control)
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
469
        made_tree = self.workingtree_format.initialize(made_control,
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
470
            revision_id=a)
471
        self.assertEqual([a], made_tree.get_parent_ids())
1508.1.23 by Robert Collins
Test that the working tree last revision is indeed set during commit.
472
6435.1.1 by Jelmer Vernooij
Add post_build_tree hook.
473
    def test_post_build_tree_hook(self):
474
        calls = []
475
        def track_post_build_tree(tree):
476
            calls.append(tree.last_revision())
477
        source = self.make_branch_and_tree('source')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
478
        a = source.commit('a', allow_pointless=True)
479
        source.commit('b', allow_pointless=True)
6435.1.2 by Jelmer Vernooij
Fix test against wt2.
480
        self.build_tree(['new/'])
481
        made_control = self.bzrdir_format.initialize('new')
482
        source.branch.repository.clone(made_control)
483
        source.branch.clone(made_control)
6435.1.1 by Jelmer Vernooij
Add post_build_tree hook.
484
        MutableTree.hooks.install_named_hook("post_build_tree",
485
            track_post_build_tree, "Test")
486
        made_tree = self.workingtree_format.initialize(made_control,
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
487
            revision_id=a)
488
        self.assertEqual([a], calls)
6435.1.1 by Jelmer Vernooij
Add post_build_tree hook.
489
1508.1.24 by Robert Collins
Add update command for use with checkouts.
490
    def test_update_sets_last_revision(self):
491
        # working tree formats from the meta-dir format and newer support
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
492
        # setting the last revision on a tree independently of that on the
493
        # branch. Its concievable that some future formats may want to
1508.1.24 by Robert Collins
Add update command for use with checkouts.
494
        # couple them again (i.e. because its really a smart server and
495
        # the working tree will always match the branch). So we test
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
496
        # that formats where initialising a branch does not initialise a
497
        # tree - and thus have separable entities - support skewing the
1508.1.24 by Robert Collins
Add update command for use with checkouts.
498
        # two things.
6437.70.14 by John Arbash Meinel
Finish bug #1046697 and run all per_workingtree tests against a checkout.
499
        self.requireBranchReference()
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
500
        wt = self.make_branch_and_tree('tree')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
501
        # create an out of date working tree by making a checkout in this
502
        # current format
503
        self.build_tree(['checkout/', 'tree/file'])
504
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
505
        checkout.set_branch_reference(wt.branch)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
506
        old_tree = self.workingtree_format.initialize(checkout)
507
        # now commit to 'tree'
508
        wt.add('file')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
509
        a = wt.commit('A')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
510
        # and update old_tree
511
        self.assertEqual(0, old_tree.update())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
512
        self.assertPathExists('checkout/file')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
513
        self.assertEqual([a], old_tree.get_parent_ids())
1508.1.24 by Robert Collins
Add update command for use with checkouts.
514
1731.1.33 by Aaron Bentley
Revert no-special-root changes
515
    def test_update_sets_root_id(self):
516
        """Ensure tree root is set properly by update.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
517
1731.1.33 by Aaron Bentley
Revert no-special-root changes
518
        Since empty trees don't have root_ids, but workingtrees do,
519
        an update of a checkout of revision 0 to a new revision,  should set
520
        the root id.
521
        """
522
        wt = self.make_branch_and_tree('tree')
523
        main_branch = wt.branch
524
        # create an out of date working tree by making a checkout in this
525
        # current format
526
        self.build_tree(['checkout/', 'tree/file'])
1731.1.43 by Aaron Bentley
Merge more checkout changes
527
        checkout = main_branch.create_checkout('checkout')
1731.1.33 by Aaron Bentley
Revert no-special-root changes
528
        # now commit to 'tree'
529
        wt.add('file')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
530
        a = wt.commit('A')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
531
        # and update checkout
1731.1.33 by Aaron Bentley
Revert no-special-root changes
532
        self.assertEqual(0, checkout.update())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
533
        self.assertPathExists('checkout/file')
1731.1.33 by Aaron Bentley
Revert no-special-root changes
534
        self.assertEqual(wt.get_root_id(), checkout.get_root_id())
535
        self.assertNotEqual(None, wt.get_root_id())
536
4634.123.1 by John Arbash Meinel
Add a failing test for 'update'. When this branch lands, update should work.
537
    def test_update_sets_updated_root_id(self):
538
        wt = self.make_branch_and_tree('tree')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
539
        if not wt._format.supports_setting_file_ids:
540
            self.assertRaises(SettingFileIdUnsupported, wt.set_root_id,
541
                    'first_root_id')
542
            return
4634.123.1 by John Arbash Meinel
Add a failing test for 'update'. When this branch lands, update should work.
543
        wt.set_root_id('first_root_id')
544
        self.assertEqual('first_root_id', wt.get_root_id())
545
        self.build_tree(['tree/file'])
546
        wt.add(['file'])
547
        wt.commit('first')
548
        co = wt.branch.create_checkout('checkout')
549
        wt.set_root_id('second_root_id')
550
        wt.commit('second')
551
        self.assertEqual('second_root_id', wt.get_root_id())
552
        self.assertEqual(0, co.update())
553
        self.assertEqual('second_root_id', co.get_root_id())
554
1508.1.24 by Robert Collins
Add update command for use with checkouts.
555
    def test_update_returns_conflict_count(self):
556
        # working tree formats from the meta-dir format and newer support
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
557
        # setting the last revision on a tree independently of that on the
558
        # branch. Its concievable that some future formats may want to
1508.1.24 by Robert Collins
Add update command for use with checkouts.
559
        # couple them again (i.e. because its really a smart server and
560
        # the working tree will always match the branch). So we test
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
561
        # that formats where initialising a branch does not initialise a
562
        # tree - and thus have separable entities - support skewing the
1508.1.24 by Robert Collins
Add update command for use with checkouts.
563
        # two things.
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
564
        self.requireBranchReference()
565
        wt = self.make_branch_and_tree('tree')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
566
        # create an out of date working tree by making a checkout in this
567
        # current format
568
        self.build_tree(['checkout/', 'tree/file'])
569
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
570
        checkout.set_branch_reference(wt.branch)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
571
        old_tree = self.workingtree_format.initialize(checkout)
572
        # now commit to 'tree'
573
        wt.add('file')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
574
        a = wt.commit('A')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
575
        # and add a file file to the checkout
576
        self.build_tree(['checkout/file'])
577
        old_tree.add('file')
578
        # and update old_tree
579
        self.assertEqual(1, old_tree.update())
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
580
        self.assertEqual([a], old_tree.get_parent_ids())
1508.1.24 by Robert Collins
Add update command for use with checkouts.
581
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
582
    def test_merge_revert(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
583
        from breezy.merge import merge_inner
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
584
        this = self.make_branch_and_tree('b1')
4789.12.1 by John Arbash Meinel
Fix per_workingtree.test_workingtree.test_merge_revert
585
        self.build_tree_contents([('b1/a', 'a test\n'), ('b1/b', 'b test\n')])
586
        this.add(['a', 'b'])
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
587
        this.commit(message='')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
588
        base = this.controldir.clone('b2').open_workingtree()
4789.12.1 by John Arbash Meinel
Fix per_workingtree.test_workingtree.test_merge_revert
589
        self.build_tree_contents([('b2/a', 'b test\n')])
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
590
        other = this.controldir.clone('b3').open_workingtree()
4789.12.1 by John Arbash Meinel
Fix per_workingtree.test_workingtree.test_merge_revert
591
        self.build_tree_contents([('b3/a', 'c test\n'), ('b3/c', 'c test\n')])
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
592
        other.add('c')
593
4789.12.1 by John Arbash Meinel
Fix per_workingtree.test_workingtree.test_merge_revert
594
        self.build_tree_contents([('b1/b', 'q test\n'), ('b1/d', 'd test\n')])
595
        # Note: If we don't lock this before calling merge_inner, then we get a
596
        #       lock-contention failure. This probably indicates something
597
        #       weird going on inside merge_inner. Probably something about
598
        #       calling bt = this_tree.basis_tree() in one lock, and then
599
        #       locking both this_tree and bt separately, causing a dirstate
600
        #       locking race.
601
        this.lock_write()
602
        self.addCleanup(this.unlock)
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
603
        merge_inner(this.branch, other, base, this_tree=this)
4789.12.1 by John Arbash Meinel
Fix per_workingtree.test_workingtree.test_merge_revert
604
        a = open('b1/a', 'rb')
605
        try:
606
            self.assertNotEqual(a.read(), 'a test\n')
607
        finally:
608
            a.close()
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
609
        this.revert()
4789.12.1 by John Arbash Meinel
Fix per_workingtree.test_workingtree.test_merge_revert
610
        self.assertFileEqual('a test\n', 'b1/a')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
611
        self.assertPathExists('b1/b.~1~')
612
        self.assertPathDoesNotExist('b1/c')
613
        self.assertPathDoesNotExist('b1/a.~1~')
614
        self.assertPathExists('b1/d')
1534.7.200 by Aaron Bentley
Merge from mainline
615
1587.1.10 by Robert Collins
update updates working tree and branch together.
616
    def test_update_updates_bound_branch_no_local_commits(self):
617
        # doing an update in a tree updates the branch its bound to too.
618
        master_tree = self.make_branch_and_tree('master')
619
        tree = self.make_branch_and_tree('tree')
620
        try:
621
            tree.branch.bind(master_tree.branch)
622
        except errors.UpgradeRequired:
623
            # legacy branches cannot bind
624
            return
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
625
        foo = master_tree.commit('foo', allow_pointless=True)
1587.1.10 by Robert Collins
update updates working tree and branch together.
626
        tree.update()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
627
        self.assertEqual([foo], tree.get_parent_ids())
628
        self.assertEqual(foo, tree.branch.last_revision())
1587.1.11 by Robert Collins
Local commits appear to be working properly.
629
630
    def test_update_turns_local_commit_into_merge(self):
631
        # doing an update with a few local commits and no master commits
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
632
        # makes pending-merges.
1587.1.13 by Robert Collins
Explain why update pivots more clearly in the relevant test.
633
        # this is done so that 'bzr update; bzr revert' will always produce
634
        # an exact copy of the 'logical branch' - the referenced branch for
635
        # a checkout, and the master for a bound branch.
636
        # its possible that we should instead have 'bzr update' when there
637
        # is nothing new on the master leave the current commits intact and
638
        # alter 'revert' to revert to the master always. But for now, its
639
        # good.
1587.1.11 by Robert Collins
Local commits appear to be working properly.
640
        master_tree = self.make_branch_and_tree('master')
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
641
        master_tip = master_tree.commit('first master commit')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
642
        tree = self.make_branch_and_tree('tree')
643
        try:
644
            tree.branch.bind(master_tree.branch)
645
        except errors.UpgradeRequired:
646
            # legacy branches cannot bind
647
            return
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
648
        # sync with master
649
        tree.update()
650
        # work locally
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
651
        tree.commit('foo', allow_pointless=True, local=True)
652
        bar = tree.commit('bar', allow_pointless=True, local=True)
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
653
        # sync with master prepatory to committing
1587.1.11 by Robert Collins
Local commits appear to be working properly.
654
        tree.update()
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
655
        # which should have pivoted the local tip into a merge
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
656
        self.assertEqual([master_tip, bar], tree.get_parent_ids())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
657
        # and the local branch history should match the masters now.
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
658
        self.assertEqual(master_tree.branch.last_revision(),
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
659
                         tree.branch.last_revision())
1587.1.11 by Robert Collins
Local commits appear to be working properly.
660
4916.1.7 by Martin Pool
Add per_workingtree test you can update to arbitrary revisions
661
    def test_update_takes_revision_parameter(self):
662
        wt = self.make_branch_and_tree('wt')
663
        self.build_tree_contents([('wt/a', 'old content')])
664
        wt.add(['a'])
665
        rev1 = wt.commit('first master commit')
666
        self.build_tree_contents([('wt/a', 'new content')])
667
        rev2 = wt.commit('second master commit')
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
668
        # https://bugs.launchpad.net/bzr/+bug/45719/comments/20
4916.1.7 by Martin Pool
Add per_workingtree test you can update to arbitrary revisions
669
        # when adding 'update -r' we should make sure all wt formats support
670
        # it
671
        conflicts = wt.update(revision=rev1)
672
        self.assertFileEqual('old content', 'wt/a')
673
        self.assertEqual([rev1], wt.get_parent_ids())
674
2255.2.156 by Martin Pool
Merge WorkingTree implementation back from trunk
675
    def test_merge_modified_detects_corruption(self):
676
        # FIXME: This doesn't really test that it works; also this is not
677
        # implementation-independent. mbp 20070226
1558.3.3 by Aaron Bentley
Fix error handling for merge_modified
678
        tree = self.make_branch_and_tree('master')
6072.1.1 by Jelmer Vernooij
Various fixes for tests of foreign plugins.
679
        if not isinstance(tree, InventoryWorkingTree):
680
            raise TestNotApplicable("merge-hashes is specific to bzr "
681
                "working trees")
3407.2.7 by Martin Pool
Deprecate LockableFiles.put_utf8 and put_bytes.
682
        tree._transport.put_bytes('merge-hashes', 'asdfasdf')
1558.3.3 by Aaron Bentley
Fix error handling for merge_modified
683
        self.assertRaises(errors.MergeModifiedFormatError, tree.merge_modified)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
684
2298.1.1 by Martin Pool
Add test for merge_modified
685
    def test_merge_modified(self):
686
        # merge_modified stores a map from file id to hash
687
        tree = self.make_branch_and_tree('tree')
688
        self.build_tree_contents([('tree/somefile', 'hello')])
689
        tree.lock_write()
690
        try:
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
691
            tree.add(['somefile'])
692
            d = {tree.path2id('somefile'): osutils.sha_string('hello')}
2298.1.1 by Martin Pool
Add test for merge_modified
693
            tree.set_merge_modified(d)
694
            mm = tree.merge_modified()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
695
            self.assertEqual(mm, d)
2298.1.1 by Martin Pool
Add test for merge_modified
696
        finally:
697
            tree.unlock()
698
        mm = tree.merge_modified()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
699
        self.assertEqual(mm, d)
2298.1.1 by Martin Pool
Add test for merge_modified
700
1534.10.22 by Aaron Bentley
Got ConflictList implemented
701
    def test_conflicts(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
702
        from breezy.tests.test_conflicts import example_conflicts
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
703
        tree = self.make_branch_and_tree('master')
704
        try:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
705
            tree.set_conflicts(example_conflicts)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
706
        except UnsupportedOperation:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
707
            raise TestSkipped('set_conflicts not supported')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
708
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
709
        tree2 = WorkingTree.open('master')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
710
        self.assertEqual(tree2.conflicts(), example_conflicts)
3407.2.7 by Martin Pool
Deprecate LockableFiles.put_utf8 and put_bytes.
711
        tree2._transport.put_bytes('conflicts', '')
712
        self.assertRaises(errors.ConflictFormatError,
1955.3.14 by John Arbash Meinel
Correctly fix the workingtree put() test fixes
713
                          tree2.conflicts)
3407.2.7 by Martin Pool
Deprecate LockableFiles.put_utf8 and put_bytes.
714
        tree2._transport.put_bytes('conflicts', 'a')
715
        self.assertRaises(errors.ConflictFormatError,
1955.3.14 by John Arbash Meinel
Correctly fix the workingtree put() test fixes
716
                          tree2.conflicts)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
717
718
    def make_merge_conflicts(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
719
        from breezy.merge import merge_inner
1534.10.12 by Aaron Bentley
Merge produces new conflicts
720
        tree = self.make_branch_and_tree('mine')
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
721
        with file('mine/bloo', 'wb') as f: f.write('one')
722
        with file('mine/blo', 'wb') as f: f.write('on')
2255.2.32 by Robert Collins
Make test_clear_merge_conflicts pass for dirstate. This involved working
723
        tree.add(['bloo', 'blo'])
1534.10.12 by Aaron Bentley
Merge produces new conflicts
724
        tree.commit("blah", allow_pointless=False)
2255.5.3 by John Arbash Meinel
XXX Workaround the DirStateRevisionTree bug until we get a proper fix, tests pass again
725
        base = tree.branch.repository.revision_tree(tree.last_revision())
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
726
        controldir.ControlDir.open("mine").sprout("other")
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
727
        with file('other/bloo', 'wb') as f: f.write('two')
1534.10.12 by Aaron Bentley
Merge produces new conflicts
728
        othertree = WorkingTree.open('other')
729
        othertree.commit('blah', allow_pointless=False)
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
730
        with file('mine/bloo', 'wb') as f: f.write('three')
1534.10.12 by Aaron Bentley
Merge produces new conflicts
731
        tree.commit("blah", allow_pointless=False)
732
        merge_inner(tree.branch, othertree, base, this_tree=tree)
733
        return tree
734
735
    def test_merge_conflicts(self):
736
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
737
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
738
739
    def test_clear_merge_conflicts(self):
740
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
741
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
742
        try:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
743
            tree.set_conflicts(ConflictList())
1534.10.12 by Aaron Bentley
Merge produces new conflicts
744
        except UnsupportedOperation:
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
745
            raise TestSkipped('unsupported operation')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
746
        self.assertEqual(tree.conflicts(), ConflictList())
1534.10.14 by Aaron Bentley
Made revert clear conflicts
747
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
748
    def test_add_conflicts(self):
749
        tree = self.make_branch_and_tree('tree')
750
        try:
751
            tree.add_conflicts([TextConflict('path_a')])
752
        except UnsupportedOperation:
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
753
            raise TestSkipped('unsupported operation')
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
754
        self.assertEqual(ConflictList([TextConflict('path_a')]),
755
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
756
        tree.add_conflicts([TextConflict('path_a')])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
757
        self.assertEqual(ConflictList([TextConflict('path_a')]),
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
758
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
759
        tree.add_conflicts([ContentsConflict('path_a')])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
760
        self.assertEqual(ConflictList([ContentsConflict('path_a'),
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
761
                                       TextConflict('path_a')]),
762
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
763
        tree.add_conflicts([TextConflict('path_b')])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
764
        self.assertEqual(ConflictList([ContentsConflict('path_a'),
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
765
                                       TextConflict('path_a'),
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
766
                                       TextConflict('path_b')]),
767
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
768
1534.10.14 by Aaron Bentley
Made revert clear conflicts
769
    def test_revert_clear_conflicts(self):
770
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
771
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
772
        tree.revert(["blo"])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
773
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
774
        tree.revert(["bloo"])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
775
        self.assertEqual(len(tree.conflicts()), 0)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
776
777
    def test_revert_clear_conflicts2(self):
778
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
779
        self.assertEqual(len(tree.conflicts()), 1)
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
780
        tree.revert()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
781
        self.assertEqual(len(tree.conflicts()), 0)
1624.3.22 by Olaf Conradi
Merge bzr.dev
782
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
783
    def test_format_description(self):
784
        tree = self.make_branch_and_tree('tree')
785
        text = tree._format.get_format_description()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
786
        self.assertTrue(len(text))
1681.1.1 by Robert Collins
Make WorkingTree.branch a read only property. (Robert Collins)
787
788
    def test_branch_attribute_is_not_settable(self):
789
        # the branch attribute is an aspect of the working tree, not a
790
        # configurable attribute
791
        tree = self.make_branch_and_tree('tree')
792
        def set_branch():
793
            tree.branch = tree.branch
794
        self.assertRaises(AttributeError, set_branch)
795
1713.3.1 by Robert Collins
Smoke tests for tree.list_files and bzr ignored when a versioned file matches an ignore rule.
796
    def test_list_files_versioned_before_ignored(self):
797
        """A versioned file matching an ignore rule should not be ignored."""
798
        tree = self.make_branch_and_tree('.')
799
        self.build_tree(['foo.pyc'])
800
        # ensure that foo.pyc is ignored
801
        self.build_tree_contents([('.bzrignore', 'foo.pyc')])
802
        tree.add('foo.pyc', 'anid')
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
803
        tree.lock_read()
1713.3.1 by Robert Collins
Smoke tests for tree.list_files and bzr ignored when a versioned file matches an ignore rule.
804
        files = sorted(list(tree.list_files()))
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
805
        tree.unlock()
1713.3.1 by Robert Collins
Smoke tests for tree.list_files and bzr ignored when a versioned file matches an ignore rule.
806
        self.assertEqual((u'.bzrignore', '?', 'file', None), files[0][:-1])
807
        self.assertEqual((u'foo.pyc', 'V', 'file', 'anid'), files[1][:-1])
808
        self.assertEqual(2, len(files))
1711.8.2 by John Arbash Meinel
Test that WorkingTree locks Branch before self, and unlocks self before Branch
809
1830.3.7 by John Arbash Meinel
Check that WorkingTree.add does the right thing.
810
    def test_non_normalized_add_accessible(self):
811
        try:
812
            self.build_tree([u'a\u030a'])
813
        except UnicodeError:
814
            raise TestSkipped('Filesystem does not support unicode filenames')
815
        tree = self.make_branch_and_tree('.')
816
        orig = osutils.normalized_filename
817
        osutils.normalized_filename = osutils._accessible_normalized_filename
818
        try:
819
            tree.add([u'a\u030a'])
2255.2.58 by Robert Collins
Fix the way we used osutils.normalized_filename in dirstate to support overriding in tests - and document this in the original location it was used.
820
            tree.lock_read()
1907.1.3 by Aaron Bentley
Fixed unicode test cases
821
            self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
822
                    [(path, ie.kind) for path, ie in
5807.1.2 by Jelmer Vernooij
Skip some inventory-specific tests for non-inventory working trees.
823
                                tree.iter_entries_by_dir()])
2255.2.58 by Robert Collins
Fix the way we used osutils.normalized_filename in dirstate to support overriding in tests - and document this in the original location it was used.
824
            tree.unlock()
1830.3.7 by John Arbash Meinel
Check that WorkingTree.add does the right thing.
825
        finally:
826
            osutils.normalized_filename = orig
827
828
    def test_non_normalized_add_inaccessible(self):
829
        try:
830
            self.build_tree([u'a\u030a'])
831
        except UnicodeError:
832
            raise TestSkipped('Filesystem does not support unicode filenames')
833
        tree = self.make_branch_and_tree('.')
834
        orig = osutils.normalized_filename
835
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
836
        try:
837
            self.assertRaises(errors.InvalidNormalization,
838
                tree.add, [u'a\u030a'])
839
        finally:
840
            osutils.normalized_filename = orig
2123.3.9 by Steffen Eichenberg
added tests for deprecated API workingtree.move
841
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
842
    def test__write_inventory(self):
843
        # The private interface _write_inventory is currently used by transform.
844
        tree = self.make_branch_and_tree('.')
5807.1.2 by Jelmer Vernooij
Skip some inventory-specific tests for non-inventory working trees.
845
        if not isinstance(tree, InventoryWorkingTree):
846
            raise TestNotApplicable("_write_inventory does not exist on "
847
                "non-inventory working trees")
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
848
        # if we write write an inventory then do a walkdirs we should get back
849
        # missing entries, and actual, and unknowns as appropriate.
850
        self.build_tree(['present', 'unknown'])
2946.3.3 by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('')
851
        inventory = Inventory(tree.get_root_id())
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
852
        inventory.add_path('missing', 'file', 'missing-id')
853
        inventory.add_path('present', 'file', 'present-id')
2255.2.28 by Robert Collins
TestWorkingTree.test__write_inventory needs to lock the tree before calling _write_inventory for dirstate.
854
        # there is no point in being able to write an inventory to an unlocked
855
        # tree object - its a low level api not a convenience api.
856
        tree.lock_write()
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
857
        tree._write_inventory(inventory)
2255.2.28 by Robert Collins
TestWorkingTree.test__write_inventory needs to lock the tree before calling _write_inventory for dirstate.
858
        tree.unlock()
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
859
        tree.lock_read()
860
        try:
861
            present_stat = os.lstat('present')
862
            unknown_stat = os.lstat('unknown')
863
            expected_results = [
2946.3.3 by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('')
864
                (('', tree.get_root_id()),
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
865
                 [('missing', 'missing', 'unknown', None, 'missing-id', 'file'),
866
                  ('present', 'present', 'file', present_stat, 'present-id', 'file'),
867
                  ('unknown', 'unknown', 'file', unknown_stat, None, None),
868
                 ]
869
                )]
870
            self.assertEqual(expected_results, list(tree.walkdirs()))
871
        finally:
872
            tree.unlock()
2255.7.56 by Robert Collins
Document behaviour of tree.path2id("path/").
873
874
    def test_path2id(self):
2255.7.62 by Robert Collins
Update the Tree.filter_unversioned_files docstring to reflect what the existing implementations actually do, and change the WorkingTree4 implementation to match a newly created test for it.
875
        # smoke test for path2id
2255.7.56 by Robert Collins
Document behaviour of tree.path2id("path/").
876
        tree = self.make_branch_and_tree('.')
877
        self.build_tree(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
878
        if tree.supports_setting_file_ids():
879
            tree.add(['foo'], ['foo-id'])
880
            self.assertEqual('foo-id', tree.path2id('foo'))
881
            # the next assertion is for backwards compatability with
882
            # WorkingTree3, though its probably a bad idea, it makes things
883
            # work. Perhaps it should raise a deprecation warning?
884
            self.assertEqual('foo-id', tree.path2id('foo/'))
885
        else:
886
            tree.add(['foo'])
6821.2.2 by Jelmer Vernooij
More foreign fixes.
887
            if tree.branch.repository._format.supports_versioned_directories:
888
                self.assertIsInstance(str, tree.path2id('foo'))
889
            else:
890
                self.skipTest('format does not support versioning directories')
2255.7.62 by Robert Collins
Update the Tree.filter_unversioned_files docstring to reflect what the existing implementations actually do, and change the WorkingTree4 implementation to match a newly created test for it.
891
892
    def test_filter_unversioned_files(self):
893
        # smoke test for filter_unversioned_files
894
        tree = self.make_branch_and_tree('.')
895
        paths = ['here-and-versioned', 'here-and-not-versioned',
896
            'not-here-and-versioned', 'not-here-and-not-versioned']
897
        tree.add(['here-and-versioned', 'not-here-and-versioned'],
898
            kinds=['file', 'file'])
899
        self.build_tree(['here-and-versioned', 'here-and-not-versioned'])
900
        tree.lock_read()
901
        self.addCleanup(tree.unlock)
902
        self.assertEqual(
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
903
            {'not-here-and-not-versioned', 'here-and-not-versioned'},
2255.7.62 by Robert Collins
Update the Tree.filter_unversioned_files docstring to reflect what the existing implementations actually do, and change the WorkingTree4 implementation to match a newly created test for it.
904
            tree.filter_unversioned_files(paths))
2255.2.200 by Martin Pool
Add simple test for WorkingTree.kind
905
906
    def test_detect_real_kind(self):
907
        # working trees report the real kind of the file on disk, not the kind
908
        # they had when they were first added
909
        # create one file of every interesting type
910
        tree = self.make_branch_and_tree('.')
4100.2.2 by Aaron Bentley
Remove locking decorator
911
        tree.lock_write()
912
        self.addCleanup(tree.unlock)
2255.2.200 by Martin Pool
Add simple test for WorkingTree.kind
913
        self.build_tree(['file', 'directory/'])
914
        names = ['file', 'directory']
915
        if has_symlinks():
916
            os.symlink('target', 'symlink')
917
            names.append('symlink')
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
918
        tree.add(names)
2255.2.200 by Martin Pool
Add simple test for WorkingTree.kind
919
        # now when we first look, we should see everything with the same kind
920
        # with which they were initially added
921
        for n in names:
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
922
            actual_kind = tree.kind(n)
2255.2.200 by Martin Pool
Add simple test for WorkingTree.kind
923
            self.assertEqual(n, actual_kind)
924
        # move them around so the names no longer correspond to the types
925
        os.rename(names[0], 'tmp')
926
        for i in range(1, len(names)):
927
            os.rename(names[i], names[i-1])
928
        os.rename('tmp', names[-1])
2255.2.202 by Martin Pool
WorkingTree_4.kind should report tree-references if they're
929
        # now look and expect to see the correct types again
930
        for i in range(len(names)):
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
931
            actual_kind = tree.kind(names[i-1])
2255.2.202 by Martin Pool
WorkingTree_4.kind should report tree-references if they're
932
            expected_kind = names[i]
933
            self.assertEqual(expected_kind, actual_kind)
2499.3.1 by Aaron Bentley
Fix Workingtree4.get_file_sha1 on missing files
934
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
935
    def test_stored_kind_with_missing(self):
936
        tree = self.make_branch_and_tree('tree')
937
        tree.lock_write()
938
        self.addCleanup(tree.unlock)
939
        self.build_tree(['tree/a', 'tree/b/'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
940
        tree.add(['a', 'b'])
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
941
        os.unlink('tree/a')
942
        os.rmdir('tree/b')
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
943
        self.assertEqual('file', tree.stored_kind('a'))
6816.1.1 by Jelmer Vernooij
Avoid passing in file ids.
944
        if tree.branch.repository._format.supports_versioned_directories:
6809.4.26 by Jelmer Vernooij
Merge trunk.
945
            self.assertEqual('directory', tree.stored_kind('b'))
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
946
2499.3.1 by Aaron Bentley
Fix Workingtree4.get_file_sha1 on missing files
947
    def test_missing_file_sha1(self):
948
        """If a file is missing, its sha1 should be reported as None."""
949
        tree = self.make_branch_and_tree('.')
950
        tree.lock_write()
951
        self.addCleanup(tree.unlock)
952
        self.build_tree(['file'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
953
        tree.add('file')
2499.3.1 by Aaron Bentley
Fix Workingtree4.get_file_sha1 on missing files
954
        tree.commit('file added')
955
        os.unlink('file')
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
956
        self.assertIs(None, tree.get_file_sha1('file'))
1551.15.56 by Aaron Bentley
Raise NoSuchId when get_file_sha1 is invoked with a baed file id
957
958
    def test_no_file_sha1(self):
6809.4.13 by Jelmer Vernooij
Fix tests.
959
        """If a file is not present, get_file_sha1 should raise NoSuchFile"""
1551.15.56 by Aaron Bentley
Raise NoSuchId when get_file_sha1 is invoked with a baed file id
960
        tree = self.make_branch_and_tree('.')
961
        tree.lock_write()
962
        self.addCleanup(tree.unlock)
6809.4.13 by Jelmer Vernooij
Fix tests.
963
        self.assertRaises(errors.NoSuchFile, tree.get_file_sha1,
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
964
                          'nonexistant')
1551.15.56 by Aaron Bentley
Raise NoSuchId when get_file_sha1 is invoked with a baed file id
965
        self.build_tree(['file'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
966
        tree.add('file')
967
        file_id = tree.path2id('file')
1551.15.56 by Aaron Bentley
Raise NoSuchId when get_file_sha1 is invoked with a baed file id
968
        tree.commit('foo')
969
        tree.remove('file')
6809.4.13 by Jelmer Vernooij
Fix tests.
970
        self.assertRaises(errors.NoSuchFile, tree.get_file_sha1,
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
971
                          'file')
3034.4.5 by Aaron Bentley
Add workingtree test for case_insensitive var
972
973
    def test_case_sensitive(self):
974
        """If filesystem is case-sensitive, tree should report this.
975
976
        We check case-sensitivity by creating a file with a lowercase name,
977
        then testing whether it exists with an uppercase name.
978
        """
3034.4.9 by Alexander Belchenko
skip test_workingtree.TestWorkingTree.test_case_sensitive for WT2
979
        self.build_tree(['filename'])
3034.4.5 by Aaron Bentley
Add workingtree test for case_insensitive var
980
        if os.path.exists('FILENAME'):
981
            case_sensitive = False
982
        else:
983
            case_sensitive = True
984
        tree = self.make_branch_and_tree('test')
985
        self.assertEqual(case_sensitive, tree.case_sensitive)
6113.1.1 by Jelmer Vernooij
Skip some tests against foreign formats.
986
        if not isinstance(tree, InventoryWorkingTree):
987
            raise TestNotApplicable("get_format_string is only available "
988
                                    "on bzr working trees")
5632.1.1 by John Arbash Meinel
Make case_sensitive_filename an attribute of the format.
989
        # now we cheat, and make a file that matches the case-sensitive name
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
990
        t = tree.controldir.get_workingtree_transport(None)
5632.1.1 by John Arbash Meinel
Make case_sensitive_filename an attribute of the format.
991
        try:
992
            content = tree._format.get_format_string()
993
        except NotImplementedError:
994
            # All-in-one formats didn't have a separate format string.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
995
            content = tree.controldir._format.get_format_string()
5632.1.1 by John Arbash Meinel
Make case_sensitive_filename an attribute of the format.
996
        t.put_bytes(tree._format.case_sensitive_filename, content)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
997
        tree = tree.controldir.open_workingtree()
5632.1.1 by John Arbash Meinel
Make case_sensitive_filename an attribute of the format.
998
        self.assertFalse(tree.case_sensitive)
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
999
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1000
    def test_supports_executable(self):
1001
        self.build_tree(['filename'])
1002
        tree = self.make_branch_and_tree('.')
1003
        tree.add('filename')
1004
        self.assertIsInstance(tree._supports_executable(), bool)
1005
        if tree._supports_executable():
1006
            tree.lock_read()
1007
            try:
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
1008
                self.assertFalse(tree.is_executable('filename'))
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1009
            finally:
1010
                tree.unlock()
6619.3.14 by Jelmer Vernooij
Convert some octal numbers to new notations.
1011
            os.chmod('filename', 0o755)
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1012
            self.addCleanup(tree.lock_read().unlock)
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
1013
            self.assertTrue(tree.is_executable('filename'))
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1014
        else:
1015
            self.addCleanup(tree.lock_read().unlock)
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
1016
            self.assertFalse(tree.is_executable('filename'))
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1017
3146.8.16 by Aaron Bentley
Updates from review
1018
    def test_all_file_ids_with_missing(self):
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
1019
        tree = self.make_branch_and_tree('tree')
1020
        tree.lock_write()
1021
        self.addCleanup(tree.unlock)
1022
        self.build_tree(['tree/a', 'tree/b'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
1023
        tree.add(['a', 'b'])
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
1024
        os.unlink('tree/a')
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
1025
        self.assertEqual(
1026
                {tree.path2id('a'), tree.path2id('b'), tree.get_root_id()},
1027
                tree.all_file_ids())
3146.8.19 by Aaron Bentley
Merge with bzr.dev
1028
3136.1.10 by Aaron Bentley
Clean error if filesystem does not support hard-links
1029
    def test_sprout_hardlink(self):
3619.6.9 by Mark Hammond
Move check for os.link to the start of the test
1030
        real_os_link = getattr(os, 'link', None)
1031
        if real_os_link is None:
1032
            raise TestNotApplicable("This platform doesn't provide os.link")
3136.1.10 by Aaron Bentley
Clean error if filesystem does not support hard-links
1033
        source = self.make_branch_and_tree('source')
1034
        self.build_tree(['source/file'])
1035
        source.add('file')
1036
        source.commit('added file')
1037
        def fake_link(source, target):
1038
            raise OSError(errno.EPERM, 'Operation not permitted')
1039
        os.link = fake_link
1040
        try:
1041
            # Hard-link support is optional, so supplying hardlink=True may
1042
            # or may not raise an exception.  But if it does, it must be
1043
            # HardLinkNotSupported
1044
            try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1045
                source.controldir.sprout('target', accelerator_tree=source,
3136.1.10 by Aaron Bentley
Clean error if filesystem does not support hard-links
1046
                                     hardlink=True)
1047
            except errors.HardLinkNotSupported:
1048
                pass
1049
        finally:
1050
            os.link = real_os_link
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1051
1052
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1053
class TestWorkingTreeUpdate(TestCaseWithWorkingTree):
1054
1055
    def make_diverged_master_branch(self):
1056
        """
1057
        B: wt.branch.last_revision()
1058
        M: wt.branch.get_master_branch().last_revision()
1059
        W: wt.last_revision()
1060
1061
1062
            1
1063
            |\
1064
          B-2 3
1065
            | |
1066
            4 5-M
1067
            |
1068
            W
6162.3.2 by Jelmer Vernooij
Add WorkingTreeFormat.get_controldir_for_branch().
1069
        """
1070
        format = self.workingtree_format.get_controldir_for_branch()
1071
        builder = self.make_branch_builder(".", format=format)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1072
        builder.start_series()
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1073
        revids = {}
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1074
        # mainline
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1075
        revids['1'] = builder.build_snapshot(
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1076
            None,
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1077
            [('add', ('', 'root-id', 'directory', '')),
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1078
             ('add', ('file1', 'file1-id', 'file', 'file1 content\n'))])
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1079
        # branch
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1080
        revids['2'] = builder.build_snapshot([revids['1']], [])
1081
        revids['4'] = builder.build_snapshot(
1082
            [revids['1']],
1083
            [('add', ('file4', 'file4-id', 'file', 'file4 content\n'))])
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1084
        # master
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1085
        revids['3'] = builder.build_snapshot([revids['1']], [])
1086
        revids['5'] = builder.build_snapshot(
1087
            [revids['3']],
1088
            [('add', ('file5', 'file5-id', 'file', 'file5 content\n'))])
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1089
        builder.finish_series()
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1090
        return (builder, builder._branch.last_revision(), revids)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1091
4985.3.21 by Vincent Ladeuil
Final cleanup.
1092
    def make_checkout_and_master(self, builder, wt_path, master_path, wt_revid,
1093
                                 master_revid=None, branch_revid=None):
1094
        """Build a lightweight checkout and its master branch."""
1095
        if master_revid is None:
1096
            master_revid = wt_revid
1097
        if branch_revid is None:
1098
            branch_revid = master_revid
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1099
        final_branch = builder.get_branch()
1100
        # The master branch
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1101
        master = final_branch.controldir.sprout(master_path,
4985.3.21 by Vincent Ladeuil
Final cleanup.
1102
                                            master_revid).open_branch()
1103
        # The checkout
1104
        wt = self.make_branch_and_tree(wt_path)
1105
        wt.pull(final_branch, stop_revision=wt_revid)
1106
        wt.branch.pull(final_branch, stop_revision=branch_revid, overwrite=True)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1107
        try:
4985.3.21 by Vincent Ladeuil
Final cleanup.
1108
            wt.branch.bind(master)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1109
        except errors.UpgradeRequired:
4985.3.21 by Vincent Ladeuil
Final cleanup.
1110
            raise TestNotApplicable(
1111
                "Can't bind %s" % wt.branch._format.__class__)
1112
        return wt, master
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1113
1114
    def test_update_remove_commit(self):
1115
        """Update should remove revisions when the branch has removed
1116
        some commits.
1117
1118
        We want to revert 4, so that strating with the
1119
        make_diverged_master_branch() graph the final result should be
1120
        equivalent to:
1121
1122
           1
1123
           |\
1124
           3 2
1125
           | |\
1126
        MB-5 | 4
1127
           |/
1128
           W
1129
1130
        And the changes in 4 have been removed from the WT.
1131
        """
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1132
        builder, tip, revids = self.make_diverged_master_branch()
4985.3.21 by Vincent Ladeuil
Final cleanup.
1133
        wt, master = self.make_checkout_and_master(
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1134
            builder, 'checkout', 'master', revids['4'],
1135
            master_revid=tip, branch_revid=revids['2'])
4985.3.19 by Vincent Ladeuil
Make the test more precise.
1136
        # First update the branch
1137
        old_tip = wt.branch.update()
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1138
        self.assertEqual(revids['2'], old_tip)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1139
        # No conflicts should occur
4985.3.21 by Vincent Ladeuil
Final cleanup.
1140
        self.assertEqual(0, wt.update(old_tip=old_tip))
4985.3.19 by Vincent Ladeuil
Make the test more precise.
1141
        # We are in sync with the master
1142
        self.assertEqual(tip, wt.branch.last_revision())
4985.3.20 by Vincent Ladeuil
Remove the blackbox test and fix typo.
1143
        # We have the right parents ready to be committed
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1144
        self.assertEqual([revids['5'], revids['2']],
1145
                         wt.get_parent_ids())
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1146
4985.3.21 by Vincent Ladeuil
Final cleanup.
1147
    def test_update_revision(self):
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1148
        builder, tip, revids = self.make_diverged_master_branch()
4985.3.21 by Vincent Ladeuil
Final cleanup.
1149
        wt, master = self.make_checkout_and_master(
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1150
            builder, 'checkout', 'master', revids['4'],
1151
            master_revid=tip, branch_revid=revids['2'])
1152
        self.assertEqual(0, wt.update(revision=revids['1']))
1153
        self.assertEqual(revids['1'], wt.last_revision())
4985.3.21 by Vincent Ladeuil
Final cleanup.
1154
        self.assertEqual(tip, wt.branch.last_revision())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
1155
        self.assertPathExists('checkout/file1')
1156
        self.assertPathDoesNotExist('checkout/file4')
1157
        self.assertPathDoesNotExist('checkout/file5')
4985.3.21 by Vincent Ladeuil
Final cleanup.
1158
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1159
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1160
class TestIllegalPaths(TestCaseWithWorkingTree):
1161
1162
    def test_bad_fs_path(self):
3638.3.14 by Vincent Ladeuil
Make test_bad_fs_path not applicable on OSX.
1163
        if osutils.normalizes_filenames():
1164
            # You *can't* create an illegal filename on OSX.
1165
            raise tests.TestNotApplicable('OSX normalizes filenames')
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
1166
        self.requireFeature(features.UTF8Filesystem)
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1167
        # We require a UTF8 filesystem, because otherwise we would need to get
1168
        # tricky to figure out how to create an illegal filename.
1169
        # \xb5 is an illegal path because it should be \xc2\xb5 for UTF-8
1170
        tree = self.make_branch_and_tree('tree')
1171
        self.build_tree(['tree/subdir/'])
1172
        tree.add('subdir')
1173
1174
        f = open('tree/subdir/m\xb5', 'wb')
1175
        try:
1176
            f.write('trivial\n')
1177
        finally:
1178
            f.close()
1179
1180
        tree.lock_read()
1181
        self.addCleanup(tree.unlock)
1182
        basis = tree.basis_tree()
1183
        basis.lock_read()
1184
        self.addCleanup(basis.unlock)
1185
1186
        e = self.assertListRaises(errors.BadFilenameEncoding,
1187
                                  tree.iter_changes, tree.basis_tree(),
1188
                                                     want_unversioned=True)
1189
        # We should display the relative path
1190
        self.assertEqual('subdir/m\xb5', e.filename)
1191
        self.assertEqual(osutils._fs_enc, e.fs_encoding)
5158.6.5 by Martin Pool
Implement ControlComponent on WorkingTree
1192
1193
1194
class TestControlComponent(TestCaseWithWorkingTree):
1195
    """WorkingTree implementations adequately implement ControlComponent."""
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1196
5158.6.5 by Martin Pool
Implement ControlComponent on WorkingTree
1197
    def test_urls(self):
1198
        wt = self.make_branch_and_tree('wt')
1199
        self.assertIsInstance(wt.user_url, str)
1200
        self.assertEqual(wt.user_url, wt.user_transport.base)
1201
        # for all current bzrdir implementations the user dir must be 
1202
        # above the control dir but we might need to relax that?
1203
        self.assertEqual(wt.control_url.find(wt.user_url), 0)
1204
        self.assertEqual(wt.control_url, wt.control_transport.base)
5807.4.7 by John Arbash Meinel
Add a config setting.
1205
1206
1207
class TestWorthSavingLimit(TestCaseWithWorkingTree):
1208
1209
    def make_wt_with_worth_saving_limit(self):
1210
        wt = self.make_branch_and_tree('wt')
1211
        if getattr(wt, '_worth_saving_limit', None) is None:
1212
            raise tests.TestNotApplicable('no _worth_saving_limit for'
1213
                                          ' this tree type')
1214
        wt.lock_write()
1215
        self.addCleanup(wt.unlock)
1216
        return wt
1217
1218
    def test_not_set(self):
1219
        # Default should be 10
1220
        wt = self.make_wt_with_worth_saving_limit()
1221
        self.assertEqual(10, wt._worth_saving_limit())
1222
        ds = wt.current_dirstate()
1223
        self.assertEqual(10, ds._worth_saving_limit)
1224
1225
    def test_set_in_branch(self):
1226
        wt = self.make_wt_with_worth_saving_limit()
6449.4.3 by Jelmer Vernooij
Use WorkingTree.get_config_stack.
1227
        conf = wt.get_config_stack()
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1228
        conf.set('bzr.workingtree.worth_saving_limit', '20')
5807.4.7 by John Arbash Meinel
Add a config setting.
1229
        self.assertEqual(20, wt._worth_saving_limit())
1230
        ds = wt.current_dirstate()
1231
        self.assertEqual(10, ds._worth_saving_limit)
1232
1233
    def test_invalid(self):
1234
        wt = self.make_wt_with_worth_saving_limit()
6449.4.3 by Jelmer Vernooij
Use WorkingTree.get_config_stack.
1235
        conf = wt.get_config_stack()
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1236
        conf.set('bzr.workingtree.worth_saving_limit', 'a')
5807.4.7 by John Arbash Meinel
Add a config setting.
1237
        # If the config entry is invalid, default to 10
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1238
        warnings = []
1239
        def warning(*args):
1240
            warnings.append(args[0] % args[1:])
1241
        self.overrideAttr(trace, 'warning', warning)
5807.4.7 by John Arbash Meinel
Add a config setting.
1242
        self.assertEqual(10, wt._worth_saving_limit())
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1243
        self.assertLength(1, warnings)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1244
        self.assertEqual('Value "a" is not valid for'
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1245
                          ' "bzr.workingtree.worth_saving_limit"',
1246
                          warnings[0])
5993.3.1 by Jelmer Vernooij
Add WorkingTreeFormat.supports_versioned_directories attribute.
1247
1248
1249
class TestFormatAttributes(TestCaseWithWorkingTree):
1250
1251
    def test_versioned_directories(self):
1252
        self.assertSubset(
1253
            [self.workingtree_format.supports_versioned_directories],
1254
            (True, False))
6741.1.1 by Jelmer Vernooij
Add WorkingTreeFormat.supports_setting_file_ids.
1255
1256
    def test_supports_setting_file_ids(self):
1257
        self.assertSubset(
1258
            [self.workingtree_format.supports_setting_file_ids],
1259
            (True, False))
6772.3.2 by Jelmer Vernooij
Add flag for store uncommitted in working tree formats.
1260
1261
    def test_supports_store_uncommitted(self):
1262
        self.assertSubset(
1263
            [self.workingtree_format.supports_store_uncommitted],
1264
            (True, False))