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