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