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