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