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