/brz/remove-bazaar

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