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