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