/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1852.15.19 by John Arbash Meinel
[merge] bzr.dev 2255
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
from cStringIO import StringIO
19
import os
1711.7.19 by John Arbash Meinel
file:// urls look slightly different on win32
20
import sys
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
21
22
import bzrlib
1830.3.7 by John Arbash Meinel
Check that WorkingTree.add does the right thing.
23
from bzrlib import branch, bzrdir, errors, osutils, urlutils, workingtree
1836.1.18 by John Arbash Meinel
Cleaned up the last failing tests. All tests pass again.
24
from bzrlib.errors import (NotBranchError, NotVersionedError,
1551.7.17 by Aaron Bentley
Switch to PathsNotVersioned, accept extra_trees
25
                           UnsupportedOperation, PathsNotVersionedError)
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
26
from bzrlib.inventory import Inventory
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
27
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
1534.5.5 by Robert Collins
Move is_control_file into WorkingTree.is_control_filename and test.
28
from bzrlib.tests import TestSkipped
29
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
30
from bzrlib.trace import mutter
31
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
32
                                WorkingTree)
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
33
from bzrlib.conflicts import ConflictList, TextConflict, ContentsConflict
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
34
1711.7.19 by John Arbash Meinel
file:// urls look slightly different on win32
35
1711.8.2 by John Arbash Meinel
Test that WorkingTree locks Branch before self, and unlocks self before Branch
36
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
37
class TestWorkingTree(TestCaseWithWorkingTree):
38
1732.1.8 by John Arbash Meinel
Adding a test for list_files
39
    def test_list_files(self):
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
40
        tree = self.make_branch_and_tree('.')
1732.1.8 by John Arbash Meinel
Adding a test for list_files
41
        self.build_tree(['dir/', 'file'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
42
        if has_symlinks():
43
            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.
44
        tree.lock_read()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
45
        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.
46
        tree.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
47
        self.assertEqual(files[0], ('dir', '?', 'directory', None, TreeDirectory()))
48
        self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile()))
49
        if has_symlinks():
50
            self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
51
1732.1.8 by John Arbash Meinel
Adding a test for list_files
52
    def test_list_files_sorted(self):
53
        tree = self.make_branch_and_tree('.')
1836.1.18 by John Arbash Meinel
Cleaned up the last failing tests. All tests pass again.
54
        self.build_tree(['dir/', 'file', 'dir/file', 'dir/b',
55
                         'dir/subdir/', 'a', 'dir/subfile',
56
                         '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.
57
        tree.lock_read()
1836.1.18 by John Arbash Meinel
Cleaned up the last failing tests. All tests pass again.
58
        files = [(path, kind) for (path, v, kind, file_id, entry)
59
                               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.
60
        tree.unlock()
1732.1.8 by John Arbash Meinel
Adding a test for list_files
61
        self.assertEqual([
62
            ('a', 'file'),
63
            ('dir', 'directory'),
64
            ('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.
65
            ('zz_dir', 'directory'),
1732.1.8 by John Arbash Meinel
Adding a test for list_files
66
            ], files)
67
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.
68
        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.
69
        tree.lock_read()
1836.1.18 by John Arbash Meinel
Cleaned up the last failing tests. All tests pass again.
70
        files = [(path, kind) for (path, v, kind, file_id, entry)
71
                               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.
72
        tree.unlock()
1732.1.8 by John Arbash Meinel
Adding a test for list_files
73
        self.assertEqual([
74
            ('a', 'file'),
75
            ('dir', 'directory'),
76
            ('dir/b', 'file'),
77
            ('dir/file', 'file'),
78
            ('dir/subdir', 'directory'),
79
            ('dir/subfile', 'file'),
80
            ('file', 'file'),
1732.1.22 by John Arbash Meinel
Bug in list_files if the last entry in a directory is another directory
81
            ('zz_dir', 'directory'),
82
            ('zz_dir/subfile', 'file'),
1732.1.8 by John Arbash Meinel
Adding a test for list_files
83
            ], files)
84
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
85
    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.
86
        branch = self.make_branch_and_tree('.').branch
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
87
        local_base = urlutils.local_path_from_url(branch.base)
88
89
        # Empty opens '.'
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
90
        wt, relpath = WorkingTree.open_containing()
91
        self.assertEqual('', relpath)
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
92
        self.assertEqual(wt.basedir + '/', local_base)
93
94
        # '.' opens this dir
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
95
        wt, relpath = WorkingTree.open_containing(u'.')
96
        self.assertEqual('', relpath)
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
97
        self.assertEqual(wt.basedir + '/', local_base)
98
99
        # './foo' finds '.' and a relpath of 'foo'
100
        wt, relpath = WorkingTree.open_containing('./foo')
101
        self.assertEqual('foo', relpath)
102
        self.assertEqual(wt.basedir + '/', local_base)
103
104
        # abspath(foo) finds '.' and relpath of 'foo'
105
        wt, relpath = WorkingTree.open_containing('./foo')
106
        wt, relpath = WorkingTree.open_containing(getcwd() + '/foo')
107
        self.assertEqual('foo', relpath)
108
        self.assertEqual(wt.basedir + '/', local_base)
109
110
        # can even be a url: finds '.' and relpath of 'foo'
111
        wt, relpath = WorkingTree.open_containing('./foo')
112
        wt, relpath = WorkingTree.open_containing(
113
                    urlutils.local_path_to_url(getcwd() + '/foo'))
114
        self.assertEqual('foo', relpath)
115
        self.assertEqual(wt.basedir + '/', local_base)
116
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
117
118
    def test_basic_relpath(self):
119
        # 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.
120
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
121
        self.assertEqual('child',
122
                         tree.relpath(pathjoin(getcwd(), 'child')))
123
124
    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.
125
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
126
        tree.lock_read()
127
        self.assertEqual('r', tree.branch.peek_lock_mode())
128
        tree.unlock()
129
        self.assertEqual(None, tree.branch.peek_lock_mode())
130
        tree.lock_write()
131
        self.assertEqual('w', tree.branch.peek_lock_mode())
132
        tree.unlock()
133
        self.assertEqual(None, tree.branch.peek_lock_mode())
134
 
135
    def test_revert(self):
136
        """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.
137
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
138
139
        self.build_tree(['hello.txt'])
140
        file('hello.txt', 'w').write('initial hello')
141
1551.7.17 by Aaron Bentley
Switch to PathsNotVersioned, accept extra_trees
142
        self.assertRaises(PathsNotVersionedError,
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
143
                          tree.revert, ['hello.txt'])
144
        tree.add(['hello.txt'])
145
        tree.commit('create initial hello.txt')
146
147
        self.check_file_contents('hello.txt', 'initial hello')
148
        file('hello.txt', 'w').write('new hello')
149
        self.check_file_contents('hello.txt', 'new hello')
150
151
        # revert file modified since last revision
152
        tree.revert(['hello.txt'])
153
        self.check_file_contents('hello.txt', 'initial hello')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
154
        self.check_file_contents('hello.txt.~1~', 'new hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
155
156
        # reverting again does not clobber the backup
157
        tree.revert(['hello.txt'])
158
        self.check_file_contents('hello.txt', 'initial hello')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
159
        self.check_file_contents('hello.txt.~1~', 'new hello')
1534.10.28 by Aaron Bentley
Use numbered backup files
160
        
161
        # backup files are numbered
162
        file('hello.txt', 'w').write('new hello2')
163
        tree.revert(['hello.txt'])
164
        self.check_file_contents('hello.txt', 'initial hello')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
165
        self.check_file_contents('hello.txt.~1~', 'new hello')
166
        self.check_file_contents('hello.txt.~2~', 'new hello2')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
167
1558.12.7 by Aaron Bentley
Fixed revert with missing files
168
    def test_revert_missing(self):
169
        # Revert a file that has been deleted since last commit
170
        tree = self.make_branch_and_tree('.')
171
        file('hello.txt', 'w').write('initial hello')
172
        tree.add('hello.txt')
173
        tree.commit('added hello.txt')
174
        os.unlink('hello.txt')
175
        tree.remove('hello.txt')
176
        tree.revert(['hello.txt'])
177
        self.failUnlessExists('hello.txt')
178
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
179
    def test_versioned_files_not_unknown(self):
180
        tree = self.make_branch_and_tree('.')
1831.1.1 by Martin Pool
[merge] remove default ignore list & update
181
        self.build_tree(['hello.txt'])
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
182
        tree.add('hello.txt')
183
        self.assertEquals(list(tree.unknowns()),
184
                          [])
1831.1.1 by Martin Pool
[merge] remove default ignore list & update
185
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
186
    def test_unknowns(self):
187
        tree = self.make_branch_and_tree('.')
188
        self.build_tree(['hello.txt',
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
189
                         'hello.txt.~1~'])
1765.1.1 by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add.
190
        self.build_tree_contents([('.bzrignore', '*.~*\n')])
191
        tree.add('.bzrignore')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
192
        self.assertEquals(list(tree.unknowns()),
193
                          ['hello.txt'])
194
195
    def test_initialize(self):
196
        # 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.
197
        t = self.make_branch_and_tree('.')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
198
        b = branch.Branch.open('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
199
        self.assertEqual(t.branch.base, b.base)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
200
        t2 = WorkingTree.open('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
201
        self.assertEqual(t.basedir, t2.basedir)
202
        self.assertEqual(b.base, t2.branch.base)
203
        # TODO maybe we should check the branch format? not sure if its
204
        # appropriate here.
205
206
    def test_rename_dirs(self):
207
        """Test renaming directories and the files within them."""
208
        wt = self.make_branch_and_tree('.')
209
        b = wt.branch
210
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
211
        wt.add(['dir', 'dir/sub', 'dir/sub/file'])
212
213
        wt.commit('create initial state')
214
215
        revid = b.revision_history()[0]
216
        self.log('first revision_id is {%s}' % revid)
217
        
218
        inv = b.repository.get_revision_inventory(revid)
219
        self.log('contents of inventory: %r' % inv.entries())
220
221
        self.check_inventory_shape(inv,
222
                                   ['dir', 'dir/sub', 'dir/sub/file'])
223
224
        wt.rename_one('dir', 'newdir')
225
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
226
        wt.lock_read()
227
        self.check_inventory_shape(wt.inventory,
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
228
                                   ['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.
229
        wt.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
230
        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.
231
        wt.lock_read()
232
        self.check_inventory_shape(wt.inventory,
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
233
                                   ['newdir', 'newdir/newsub',
234
                                    'newdir/newsub/file'])
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
235
        wt.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
236
237
    def test_add_in_unversioned(self):
238
        """Try to add a file in an unversioned directory.
239
240
        "bzr add" adds the parent as necessary, but simple working tree add
241
        doesn't do that.
242
        """
243
        from bzrlib.errors import NotVersionedError
244
        wt = self.make_branch_and_tree('.')
245
        self.build_tree(['foo/',
246
                         'foo/hello'])
247
        self.assertRaises(NotVersionedError,
248
                          wt.add,
249
                          'foo/hello')
250
251
    def test_add_missing(self):
252
        # adding a msising file -> NoSuchFile
253
        wt = self.make_branch_and_tree('.')
254
        self.assertRaises(errors.NoSuchFile, wt.add, 'fpp')
255
256
    def test_remove_verbose(self):
257
        #FIXME the remove api should not print or otherwise depend on the
258
        # text UI - RBC 20060124
259
        wt = self.make_branch_and_tree('.')
260
        self.build_tree(['hello'])
261
        wt.add(['hello'])
262
        wt.commit(message='add hello')
263
        stdout = StringIO()
264
        stderr = StringIO()
265
        self.assertEqual(None, self.apply_redirected(None, stdout, stderr,
266
                                                     wt.remove,
267
                                                     ['hello'],
268
                                                     verbose=True))
269
        self.assertEqual('?       hello\n', stdout.getvalue())
270
        self.assertEqual('', stderr.getvalue())
271
272
    def test_clone_trivial(self):
273
        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.
274
        cloned_dir = wt.bzrdir.clone('target')
275
        cloned = cloned_dir.open_workingtree()
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
276
        self.assertEqual(cloned.get_parent_ids(), wt.get_parent_ids())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
277
278
    def test_last_revision(self):
279
        wt = self.make_branch_and_tree('source')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
280
        self.assertEqual([], wt.get_parent_ids())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
281
        wt.commit('A', allow_pointless=True, rev_id='A')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
282
        self.assertEqual(['A'], wt.get_parent_ids())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
283
284
    def test_set_last_revision(self):
285
        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.
286
        # set last-revision to one not in the history
287
        wt.set_last_revision('A')
288
        # set it back to None for an empty tree.
289
        wt.set_last_revision(None)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
290
        wt.commit('A', allow_pointless=True, rev_id='A')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
291
        self.assertEqual(['A'], wt.get_parent_ids())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
292
        # None is aways in the branch
293
        wt.set_last_revision(None)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
294
        self.assertEqual([], wt.get_parent_ids())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
295
        # and now we can set it to 'A'
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
296
        # because some formats mutate the branch to set it on the tree
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
297
        # we need to alter the branch to let this pass.
298
        wt.branch.set_revision_history(['A', 'B'])
299
        wt.set_last_revision('A')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
300
        self.assertEqual(['A'], wt.get_parent_ids())
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
301
        self.assertRaises(errors.ReservedId, wt.set_last_revision, 'A:')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
302
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
303
    def test_set_last_revision_different_to_branch(self):
304
        # working tree formats from the meta-dir format and newer support
305
        # setting the last revision on a tree independently of that on the 
306
        # branch. Its concievable that some future formats may want to 
307
        # couple them again (i.e. because its really a smart server and
308
        # the working tree will always match the branch). So we test
309
        # that formats where initialising a branch does not initialise a 
310
        # tree - and thus have separable entities - support skewing the 
311
        # two things.
312
        branch = self.make_branch('tree')
313
        try:
314
            # if there is a working tree now, this is not supported.
315
            branch.bzrdir.open_workingtree()
316
            return
317
        except errors.NoWorkingTree:
318
            pass
319
        wt = branch.bzrdir.create_workingtree()
320
        wt.commit('A', allow_pointless=True, rev_id='A')
321
        wt.set_last_revision(None)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
322
        self.assertEqual([], wt.get_parent_ids())
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
323
        self.assertEqual('A', wt.branch.last_revision())
324
        # and now we can set it back to 'A'
325
        wt.set_last_revision('A')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
326
        self.assertEqual(['A'], wt.get_parent_ids())
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
327
        self.assertEqual('A', wt.branch.last_revision())
328
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
329
    def test_clone_and_commit_preserves_last_revision(self):
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
330
        """Doing a commit into a clone tree does not affect the source."""
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
331
        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.
332
        cloned_dir = wt.bzrdir.clone('target')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
333
        wt.commit('A', allow_pointless=True, rev_id='A')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
334
        self.assertNotEqual(cloned_dir.open_workingtree().get_parent_ids(),
335
                            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.
336
337
    def test_clone_preserves_content(self):
338
        wt = self.make_branch_and_tree('source')
2255.2.51 by John Arbash Meinel
simple rewrap for 79 char lines
339
        self.build_tree(['added', 'deleted', 'notadded'],
340
                        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.
341
        wt.add('deleted', 'deleted')
342
        wt.commit('add deleted')
343
        wt.remove('deleted')
344
        wt.add('added', 'added')
345
        cloned_dir = wt.bzrdir.clone('target')
346
        cloned = cloned_dir.open_workingtree()
347
        cloned_transport = cloned.bzrdir.transport.clone('..')
348
        self.assertFalse(cloned_transport.has('deleted'))
349
        self.assertTrue(cloned_transport.has('added'))
350
        self.assertFalse(cloned_transport.has('notadded'))
351
        self.assertEqual('added', cloned.path2id('added'))
352
        self.assertEqual(None, cloned.path2id('deleted'))
353
        self.assertEqual(None, cloned.path2id('notadded'))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
354
        
355
    def test_basis_tree_returns_last_revision(self):
356
        wt = self.make_branch_and_tree('.')
357
        self.build_tree(['foo'])
358
        wt.add('foo', 'foo-id')
359
        wt.commit('A', rev_id='A')
360
        wt.rename_one('foo', 'bar')
361
        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.
362
        wt.set_parent_ids(['B'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
363
        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.
364
        tree.lock_read()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
365
        self.failUnless(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.
366
        tree.unlock()
1908.6.3 by Robert Collins
Tidy up the last_revision_id and add_pending_merge conversion to use cleaner apis.
367
        wt.set_parent_ids(['A'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
368
        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.
369
        tree.lock_read()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
370
        self.failUnless(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.
371
        tree.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
372
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
    def test_clone_tree_revision(self):
374
        # make a tree with a last-revision,
375
        # and clone it with a different last-revision, this should switch
376
        # do it.
377
        #
378
        # also test that the content is merged
379
        # and conflicts recorded.
380
        # This should merge between the trees - local edits should be preserved
381
        # but other changes occured.
382
        # we test this by having one file that does
383
        # not change between two revisions, and another that does -
384
        # if the changed one is not changed, fail,
385
        # if the one that did not change has lost a local change, fail.
386
        # 
387
        raise TestSkipped('revision limiting is not implemented yet.')
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
388
389
    def test_initialize_with_revision_id(self):
390
        # a bzrdir can construct a working tree for itself @ a specific revision.
391
        source = self.make_branch_and_tree('source')
392
        source.commit('a', rev_id='a', allow_pointless=True)
393
        source.commit('b', rev_id='b', allow_pointless=True)
394
        self.build_tree(['new/'])
395
        made_control = self.bzrdir_format.initialize('new')
396
        source.branch.repository.clone(made_control)
397
        source.branch.clone(made_control)
398
        made_tree = self.workingtree_format.initialize(made_control, revision_id='a')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
399
        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.
400
1508.1.24 by Robert Collins
Add update command for use with checkouts.
401
    def test_update_sets_last_revision(self):
402
        # working tree formats from the meta-dir format and newer support
403
        # setting the last revision on a tree independently of that on the 
404
        # branch. Its concievable that some future formats may want to 
405
        # couple them again (i.e. because its really a smart server and
406
        # the working tree will always match the branch). So we test
407
        # that formats where initialising a branch does not initialise a 
408
        # tree - and thus have separable entities - support skewing the 
409
        # two things.
410
        main_branch = self.make_branch('tree')
411
        try:
412
            # if there is a working tree now, this is not supported.
413
            main_branch.bzrdir.open_workingtree()
414
            return
415
        except errors.NoWorkingTree:
416
            pass
417
        wt = main_branch.bzrdir.create_workingtree()
418
        # create an out of date working tree by making a checkout in this
419
        # current format
420
        self.build_tree(['checkout/', 'tree/file'])
421
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
422
        branch.BranchReferenceFormat().initialize(checkout, main_branch)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
423
        old_tree = self.workingtree_format.initialize(checkout)
424
        # now commit to 'tree'
425
        wt.add('file')
426
        wt.commit('A', rev_id='A')
427
        # and update old_tree
428
        self.assertEqual(0, old_tree.update())
429
        self.failUnlessExists('checkout/file')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
430
        self.assertEqual(['A'], old_tree.get_parent_ids())
1508.1.24 by Robert Collins
Add update command for use with checkouts.
431
1731.1.33 by Aaron Bentley
Revert no-special-root changes
432
    def test_update_sets_root_id(self):
433
        """Ensure tree root is set properly by update.
434
        
435
        Since empty trees don't have root_ids, but workingtrees do,
436
        an update of a checkout of revision 0 to a new revision,  should set
437
        the root id.
438
        """
439
        wt = self.make_branch_and_tree('tree')
440
        main_branch = wt.branch
441
        # create an out of date working tree by making a checkout in this
442
        # current format
443
        self.build_tree(['checkout/', 'tree/file'])
1731.1.43 by Aaron Bentley
Merge more checkout changes
444
        checkout = main_branch.create_checkout('checkout')
1731.1.33 by Aaron Bentley
Revert no-special-root changes
445
        # now commit to 'tree'
446
        wt.add('file')
447
        wt.commit('A', rev_id='A')
448
        # and update checkout 
449
        self.assertEqual(0, checkout.update())
450
        self.failUnlessExists('checkout/file')
451
        self.assertEqual(wt.get_root_id(), checkout.get_root_id())
452
        self.assertNotEqual(None, wt.get_root_id())
453
1508.1.24 by Robert Collins
Add update command for use with checkouts.
454
    def test_update_returns_conflict_count(self):
455
        # working tree formats from the meta-dir format and newer support
456
        # setting the last revision on a tree independently of that on the 
457
        # branch. Its concievable that some future formats may want to 
458
        # couple them again (i.e. because its really a smart server and
459
        # the working tree will always match the branch). So we test
460
        # that formats where initialising a branch does not initialise a 
461
        # tree - and thus have separable entities - support skewing the 
462
        # two things.
463
        main_branch = self.make_branch('tree')
464
        try:
465
            # if there is a working tree now, this is not supported.
466
            main_branch.bzrdir.open_workingtree()
467
            return
468
        except errors.NoWorkingTree:
469
            pass
470
        wt = main_branch.bzrdir.create_workingtree()
471
        # create an out of date working tree by making a checkout in this
472
        # current format
473
        self.build_tree(['checkout/', 'tree/file'])
474
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
475
        branch.BranchReferenceFormat().initialize(checkout, main_branch)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
476
        old_tree = self.workingtree_format.initialize(checkout)
477
        # now commit to 'tree'
478
        wt.add('file')
479
        wt.commit('A', rev_id='A')
480
        # and add a file file to the checkout
481
        self.build_tree(['checkout/file'])
482
        old_tree.add('file')
483
        # and update old_tree
484
        self.assertEqual(1, old_tree.update())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
485
        self.assertEqual(['A'], old_tree.get_parent_ids())
1508.1.24 by Robert Collins
Add update command for use with checkouts.
486
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
487
    def test_merge_revert(self):
488
        from bzrlib.merge import merge_inner
489
        this = self.make_branch_and_tree('b1')
490
        open('b1/a', 'wb').write('a test\n')
491
        this.add('a')
492
        open('b1/b', 'wb').write('b test\n')
493
        this.add('b')
494
        this.commit(message='')
495
        base = this.bzrdir.clone('b2').open_workingtree()
496
        open('b2/a', 'wb').write('b test\n')
497
        other = this.bzrdir.clone('b3').open_workingtree()
498
        open('b3/a', 'wb').write('c test\n')
499
        open('b3/c', 'wb').write('c test\n')
500
        other.add('c')
501
502
        open('b1/b', 'wb').write('q test\n')
503
        open('b1/d', 'wb').write('d test\n')
504
        merge_inner(this.branch, other, base, this_tree=this)
505
        self.assertNotEqual(open('b1/a', 'rb').read(), 'a test\n')
506
        this.revert([])
507
        self.assertEqual(open('b1/a', 'rb').read(), 'a test\n')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
508
        self.assertIs(os.path.exists('b1/b.~1~'), True)
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
509
        self.assertIs(os.path.exists('b1/c'), False)
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
510
        self.assertIs(os.path.exists('b1/a.~1~'), False)
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
511
        self.assertIs(os.path.exists('b1/d'), True)
1534.7.200 by Aaron Bentley
Merge from mainline
512
1587.1.10 by Robert Collins
update updates working tree and branch together.
513
    def test_update_updates_bound_branch_no_local_commits(self):
514
        # doing an update in a tree updates the branch its bound to too.
515
        master_tree = self.make_branch_and_tree('master')
516
        tree = self.make_branch_and_tree('tree')
517
        try:
518
            tree.branch.bind(master_tree.branch)
519
        except errors.UpgradeRequired:
520
            # legacy branches cannot bind
521
            return
522
        master_tree.commit('foo', rev_id='foo', allow_pointless=True)
523
        tree.update()
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
524
        self.assertEqual(['foo'], tree.get_parent_ids())
1587.1.10 by Robert Collins
update updates working tree and branch together.
525
        self.assertEqual('foo', tree.branch.last_revision())
1587.1.11 by Robert Collins
Local commits appear to be working properly.
526
527
    def test_update_turns_local_commit_into_merge(self):
528
        # doing an update with a few local commits and no master commits
1587.1.13 by Robert Collins
Explain why update pivots more clearly in the relevant test.
529
        # makes pending-merges. 
530
        # this is done so that 'bzr update; bzr revert' will always produce
531
        # an exact copy of the 'logical branch' - the referenced branch for
532
        # a checkout, and the master for a bound branch.
533
        # its possible that we should instead have 'bzr update' when there
534
        # is nothing new on the master leave the current commits intact and
535
        # alter 'revert' to revert to the master always. But for now, its
536
        # good.
1587.1.11 by Robert Collins
Local commits appear to be working properly.
537
        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.
538
        master_tip = master_tree.commit('first master commit')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
539
        tree = self.make_branch_and_tree('tree')
540
        try:
541
            tree.branch.bind(master_tree.branch)
542
        except errors.UpgradeRequired:
543
            # legacy branches cannot bind
544
            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.
545
        # sync with master
546
        tree.update()
547
        # work locally
1587.1.11 by Robert Collins
Local commits appear to be working properly.
548
        tree.commit('foo', rev_id='foo', allow_pointless=True, local=True)
549
        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.
550
        # sync with master prepatory to committing
1587.1.11 by Robert Collins
Local commits appear to be working properly.
551
        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.
552
        # which should have pivoted the local tip into a merge
553
        self.assertEqual([master_tip, 'bar'], tree.get_parent_ids())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
554
        # and the local branch history should match the masters now.
555
        self.assertEqual(master_tree.branch.revision_history(),
556
            tree.branch.revision_history())
1587.1.11 by Robert Collins
Local commits appear to be working properly.
557
1558.3.3 by Aaron Bentley
Fix error handling for merge_modified
558
    def test_merge_modified(self):
559
        tree = self.make_branch_and_tree('master')
1955.3.14 by John Arbash Meinel
Correctly fix the workingtree put() test fixes
560
        tree._control_files.put('merge-hashes', StringIO('asdfasdf'))
1558.3.3 by Aaron Bentley
Fix error handling for merge_modified
561
        self.assertRaises(errors.MergeModifiedFormatError, tree.merge_modified)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
562
1534.10.22 by Aaron Bentley
Got ConflictList implemented
563
    def test_conflicts(self):
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
564
        from bzrlib.tests.test_conflicts import example_conflicts
565
        tree = self.make_branch_and_tree('master')
566
        try:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
567
            tree.set_conflicts(example_conflicts)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
568
        except UnsupportedOperation:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
569
            raise TestSkipped('set_conflicts not supported')
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
570
            
571
        tree2 = WorkingTree.open('master')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
572
        self.assertEqual(tree2.conflicts(), example_conflicts)
1955.3.14 by John Arbash Meinel
Correctly fix the workingtree put() test fixes
573
        tree2._control_files.put('conflicts', StringIO(''))
574
        self.assertRaises(errors.ConflictFormatError, 
575
                          tree2.conflicts)
576
        tree2._control_files.put('conflicts', StringIO('a'))
577
        self.assertRaises(errors.ConflictFormatError, 
578
                          tree2.conflicts)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
579
580
    def make_merge_conflicts(self):
2255.2.32 by Robert Collins
Make test_clear_merge_conflicts pass for dirstate. This involved working
581
        from bzrlib.merge import merge_inner
1534.10.12 by Aaron Bentley
Merge produces new conflicts
582
        tree = self.make_branch_and_tree('mine')
583
        file('mine/bloo', 'wb').write('one')
1534.10.14 by Aaron Bentley
Made revert clear conflicts
584
        file('mine/blo', 'wb').write('on')
2255.2.32 by Robert Collins
Make test_clear_merge_conflicts pass for dirstate. This involved working
585
        tree.add(['bloo', 'blo'])
1534.10.12 by Aaron Bentley
Merge produces new conflicts
586
        tree.commit("blah", allow_pointless=False)
587
        base = tree.basis_tree()
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
588
        bzrdir.BzrDir.open("mine").sprout("other")
1534.10.12 by Aaron Bentley
Merge produces new conflicts
589
        file('other/bloo', 'wb').write('two')
590
        othertree = WorkingTree.open('other')
591
        othertree.commit('blah', allow_pointless=False)
592
        file('mine/bloo', 'wb').write('three')
593
        tree.commit("blah", allow_pointless=False)
594
        merge_inner(tree.branch, othertree, base, this_tree=tree)
595
        return tree
596
597
    def test_merge_conflicts(self):
598
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
599
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
600
601
    def test_clear_merge_conflicts(self):
602
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
603
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
604
        try:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
605
            tree.set_conflicts(ConflictList())
1534.10.12 by Aaron Bentley
Merge produces new conflicts
606
        except UnsupportedOperation:
607
            raise TestSkipped
1534.10.22 by Aaron Bentley
Got ConflictList implemented
608
        self.assertEqual(tree.conflicts(), ConflictList())
1534.10.14 by Aaron Bentley
Made revert clear conflicts
609
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
610
    def test_add_conflicts(self):
611
        tree = self.make_branch_and_tree('tree')
612
        try:
613
            tree.add_conflicts([TextConflict('path_a')])
614
        except UnsupportedOperation:
615
            raise TestSkipped()
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
616
        self.assertEqual(ConflictList([TextConflict('path_a')]),
617
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
618
        tree.add_conflicts([TextConflict('path_a')])
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
619
        self.assertEqual(ConflictList([TextConflict('path_a')]), 
620
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
621
        tree.add_conflicts([ContentsConflict('path_a')])
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
622
        self.assertEqual(ConflictList([ContentsConflict('path_a'), 
623
                                       TextConflict('path_a')]),
624
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
625
        tree.add_conflicts([TextConflict('path_b')])
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
626
        self.assertEqual(ConflictList([ContentsConflict('path_a'), 
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
627
                                       TextConflict('path_a'),
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
628
                                       TextConflict('path_b')]),
629
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
630
1534.10.14 by Aaron Bentley
Made revert clear conflicts
631
    def test_revert_clear_conflicts(self):
632
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
633
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
634
        tree.revert(["blo"])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
635
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
636
        tree.revert(["bloo"])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
637
        self.assertEqual(len(tree.conflicts()), 0)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
638
639
    def test_revert_clear_conflicts2(self):
640
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
641
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
642
        tree.revert([])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
643
        self.assertEqual(len(tree.conflicts()), 0)
1624.3.22 by Olaf Conradi
Merge bzr.dev
644
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
645
    def test_format_description(self):
646
        tree = self.make_branch_and_tree('tree')
647
        text = tree._format.get_format_description()
648
        self.failUnless(len(text))
1681.1.1 by Robert Collins
Make WorkingTree.branch a read only property. (Robert Collins)
649
650
    def test_branch_attribute_is_not_settable(self):
651
        # the branch attribute is an aspect of the working tree, not a
652
        # configurable attribute
653
        tree = self.make_branch_and_tree('tree')
654
        def set_branch():
655
            tree.branch = tree.branch
656
        self.assertRaises(AttributeError, set_branch)
657
1713.3.1 by Robert Collins
Smoke tests for tree.list_files and bzr ignored when a versioned file matches an ignore rule.
658
    def test_list_files_versioned_before_ignored(self):
659
        """A versioned file matching an ignore rule should not be ignored."""
660
        tree = self.make_branch_and_tree('.')
661
        self.build_tree(['foo.pyc'])
662
        # ensure that foo.pyc is ignored
663
        self.build_tree_contents([('.bzrignore', 'foo.pyc')])
664
        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.
665
        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.
666
        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.
667
        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.
668
        self.assertEqual((u'.bzrignore', '?', 'file', None), files[0][:-1])
669
        self.assertEqual((u'foo.pyc', 'V', 'file', 'anid'), files[1][:-1])
670
        self.assertEqual(2, len(files))
1711.8.2 by John Arbash Meinel
Test that WorkingTree locks Branch before self, and unlocks self before Branch
671
1830.3.7 by John Arbash Meinel
Check that WorkingTree.add does the right thing.
672
    def test_non_normalized_add_accessible(self):
673
        try:
674
            self.build_tree([u'a\u030a'])
675
        except UnicodeError:
676
            raise TestSkipped('Filesystem does not support unicode filenames')
677
        tree = self.make_branch_and_tree('.')
678
        orig = osutils.normalized_filename
679
        osutils.normalized_filename = osutils._accessible_normalized_filename
680
        try:
681
            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.
682
            tree.lock_read()
1907.1.3 by Aaron Bentley
Fixed unicode test cases
683
            self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
1830.3.17 by John Arbash Meinel
list_files() with wrong normalized_filename code raises exceptions. Fix this
684
                    [(path, ie.kind) for path,ie in 
685
                                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.
686
            tree.unlock()
1830.3.7 by John Arbash Meinel
Check that WorkingTree.add does the right thing.
687
        finally:
688
            osutils.normalized_filename = orig
689
690
    def test_non_normalized_add_inaccessible(self):
691
        try:
692
            self.build_tree([u'a\u030a'])
693
        except UnicodeError:
694
            raise TestSkipped('Filesystem does not support unicode filenames')
695
        tree = self.make_branch_and_tree('.')
696
        orig = osutils.normalized_filename
697
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
698
        try:
699
            self.assertRaises(errors.InvalidNormalization,
700
                tree.add, [u'a\u030a'])
701
        finally:
702
            osutils.normalized_filename = orig
2123.3.9 by Steffen Eichenberg
added tests for deprecated API workingtree.move
703
2255.2.59 by Robert Collins
All WorkingTree4 and dirstate tests passing.
704
    def test_move_correct_call_named(self):
2123.3.9 by Steffen Eichenberg
added tests for deprecated API workingtree.move
705
        """tree.move has the deprecated parameter 'to_name'.
706
        It has been replaced by 'to_dir' for consistency.
707
        Test the new API using named parameter"""
708
        self.build_tree(['a1', 'sub1/'])
709
        tree = self.make_branch_and_tree('.')
710
        tree.add(['a1', 'sub1'])
711
        tree.commit('initial commit')
712
        tree.move(['a1'], to_dir='sub1', after=False)
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
713
2255.2.59 by Robert Collins
All WorkingTree4 and dirstate tests passing.
714
    def test_move_correct_call_unnamed(self):
2123.3.9 by Steffen Eichenberg
added tests for deprecated API workingtree.move
715
        """tree.move has the deprecated parameter 'to_name'.
716
        It has been replaced by 'to_dir' for consistency.
717
        Test the new API using unnamed parameter"""
718
        self.build_tree(['a1', 'sub1/'])
719
        tree = self.make_branch_and_tree('.')
720
        tree.add(['a1', 'sub1'])
721
        tree.commit('initial commit')
722
        tree.move(['a1'], 'sub1', after=False)
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
723
2123.3.9 by Steffen Eichenberg
added tests for deprecated API workingtree.move
724
    def test_move_deprecated_wrong_call(self):
725
        """tree.move has the deprecated parameter 'to_name'.
726
        It has been replaced by 'to_dir' for consistency.
727
        Test the new API using wrong parameter"""
728
        self.build_tree(['a1', 'sub1/'])
729
        tree = self.make_branch_and_tree('.')
730
        tree.add(['a1', 'sub1'])
731
        tree.commit('initial commit')
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
732
        self.assertRaises(TypeError, tree.move, ['a1'],
2123.3.9 by Steffen Eichenberg
added tests for deprecated API workingtree.move
733
                          to_this_parameter_does_not_exist='sub1',
734
                          after=False)
735
2255.2.59 by Robert Collins
All WorkingTree4 and dirstate tests passing.
736
    def test_move_deprecated_call(self):
2123.3.9 by Steffen Eichenberg
added tests for deprecated API workingtree.move
737
        """tree.move has the deprecated parameter 'to_name'.
738
        It has been replaced by 'to_dir' for consistency.
739
        Test the new API using deprecated parameter"""
740
        self.build_tree(['a1', 'sub1/'])
741
        tree = self.make_branch_and_tree('.')
742
        tree.add(['a1', 'sub1'])
743
        tree.commit('initial commit')
744
745
        self.callDeprecated(['The parameter to_name was deprecated'
746
                             ' in version 0.13. Use to_dir instead'],
747
                            tree.move, ['a1'], to_name='sub1',
748
                            after=False)
1852.15.19 by John Arbash Meinel
[merge] bzr.dev 2255
749
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
750
    def test__write_inventory(self):
751
        # The private interface _write_inventory is currently used by transform.
752
        tree = self.make_branch_and_tree('.')
753
        # if we write write an inventory then do a walkdirs we should get back
754
        # missing entries, and actual, and unknowns as appropriate.
755
        self.build_tree(['present', 'unknown'])
2255.2.28 by Robert Collins
TestWorkingTree.test__write_inventory needs to lock the tree before calling _write_inventory for dirstate.
756
        inventory = Inventory(tree.path2id(''))
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
757
        inventory.add_path('missing', 'file', 'missing-id')
758
        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.
759
        # there is no point in being able to write an inventory to an unlocked
760
        # tree object - its a low level api not a convenience api.
761
        tree.lock_write()
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
762
        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.
763
        tree.unlock()
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
764
        tree.lock_read()
765
        try:
766
            present_stat = os.lstat('present')
767
            unknown_stat = os.lstat('unknown')
768
            expected_results = [
769
                (('', tree.inventory.root.file_id),
770
                 [('missing', 'missing', 'unknown', None, 'missing-id', 'file'),
771
                  ('present', 'present', 'file', present_stat, 'present-id', 'file'),
772
                  ('unknown', 'unknown', 'file', unknown_stat, None, None),
773
                 ]
774
                )]
775
            self.assertEqual(expected_results, list(tree.walkdirs()))
776
        finally:
777
            tree.unlock()