/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1
# (C) 2005,2006 Canonical Ltd
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
20
21
import bzrlib
1508.1.25 by Robert Collins
Update per review comments.
22
import bzrlib.branch
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
23
from bzrlib.branch import Branch
24
import bzrlib.bzrdir as bzrdir
25
from bzrlib.bzrdir import BzrDir
26
import bzrlib.errors as errors
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
27
from bzrlib.errors import (NotBranchError, NotVersionedError, 
28
                           UnsupportedOperation)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
29
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.
30
from bzrlib.tests import TestSkipped
31
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
32
from bzrlib.trace import mutter
33
import bzrlib.workingtree as workingtree
34
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
35
                                WorkingTree)
36
37
38
class TestWorkingTree(TestCaseWithWorkingTree):
39
40
    def test_listfiles(self):
41
        tree = self.make_branch_and_tree('.')
42
        os.mkdir('dir')
43
        print >> open('file', 'w'), "content"
44
        if has_symlinks():
45
            os.symlink('target', 'symlink')
46
        files = list(tree.list_files())
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
52
    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.
53
        branch = self.make_branch_and_tree('.').branch
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
54
        wt, relpath = WorkingTree.open_containing()
55
        self.assertEqual('', relpath)
56
        self.assertEqual(wt.basedir + '/', branch.base)
57
        wt, relpath = WorkingTree.open_containing(u'.')
58
        self.assertEqual('', relpath)
59
        self.assertEqual(wt.basedir + '/', branch.base)
60
        wt, relpath = WorkingTree.open_containing('./foo')
61
        self.assertEqual('foo', relpath)
62
        self.assertEqual(wt.basedir + '/', branch.base)
63
        wt, relpath = WorkingTree.open_containing('file://' + getcwd() + '/foo')
64
        self.assertEqual('foo', relpath)
65
        self.assertEqual(wt.basedir + '/', branch.base)
66
67
    def test_basic_relpath(self):
68
        # 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.
69
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
70
        self.assertEqual('child',
71
                         tree.relpath(pathjoin(getcwd(), 'child')))
72
73
    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.
74
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
75
        tree.lock_read()
76
        self.assertEqual('r', tree.branch.peek_lock_mode())
77
        tree.unlock()
78
        self.assertEqual(None, tree.branch.peek_lock_mode())
79
        tree.lock_write()
80
        self.assertEqual('w', tree.branch.peek_lock_mode())
81
        tree.unlock()
82
        self.assertEqual(None, tree.branch.peek_lock_mode())
83
 
84
    def test_revert(self):
85
        """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.
86
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
87
88
        self.build_tree(['hello.txt'])
89
        file('hello.txt', 'w').write('initial hello')
90
91
        self.assertRaises(NotVersionedError,
92
                          tree.revert, ['hello.txt'])
93
        tree.add(['hello.txt'])
94
        tree.commit('create initial hello.txt')
95
96
        self.check_file_contents('hello.txt', 'initial hello')
97
        file('hello.txt', 'w').write('new hello')
98
        self.check_file_contents('hello.txt', 'new hello')
99
100
        # revert file modified since last revision
101
        tree.revert(['hello.txt'])
102
        self.check_file_contents('hello.txt', 'initial hello')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
103
        self.check_file_contents('hello.txt.~1~', 'new hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
104
105
        # reverting again does not clobber the backup
106
        tree.revert(['hello.txt'])
107
        self.check_file_contents('hello.txt', 'initial hello')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
108
        self.check_file_contents('hello.txt.~1~', 'new hello')
1534.10.28 by Aaron Bentley
Use numbered backup files
109
        
110
        # backup files are numbered
111
        file('hello.txt', 'w').write('new hello2')
112
        tree.revert(['hello.txt'])
113
        self.check_file_contents('hello.txt', 'initial hello')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
114
        self.check_file_contents('hello.txt.~1~', 'new hello')
115
        self.check_file_contents('hello.txt.~2~', 'new hello2')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
116
1558.12.7 by Aaron Bentley
Fixed revert with missing files
117
    def test_revert_missing(self):
118
        # Revert a file that has been deleted since last commit
119
        tree = self.make_branch_and_tree('.')
120
        file('hello.txt', 'w').write('initial hello')
121
        tree.add('hello.txt')
122
        tree.commit('added hello.txt')
123
        os.unlink('hello.txt')
124
        tree.remove('hello.txt')
125
        tree.revert(['hello.txt'])
126
        self.failUnlessExists('hello.txt')
127
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
128
    def test_unknowns(self):
129
        tree = self.make_branch_and_tree('.')
130
        self.build_tree(['hello.txt',
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
131
                         'hello.txt.~1~'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
132
        self.assertEquals(list(tree.unknowns()),
133
                          ['hello.txt'])
134
135
    def test_hashcache(self):
136
        from bzrlib.tests.test_hashcache import pause
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
        self.build_tree(['hello.txt',
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
139
                         'hello.txt.~1~'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
140
        tree.add('hello.txt')
141
        pause()
142
        sha = tree.get_file_sha1(tree.path2id('hello.txt'))
143
        self.assertEqual(1, tree._hashcache.miss_count)
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
144
        tree2 = WorkingTree.open('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
145
        sha2 = tree2.get_file_sha1(tree2.path2id('hello.txt'))
146
        self.assertEqual(0, tree2._hashcache.miss_count)
147
        self.assertEqual(1, tree2._hashcache.hit_count)
148
149
    def test_initialize(self):
150
        # 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.
151
        t = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
152
        b = Branch.open('.')
153
        self.assertEqual(t.branch.base, b.base)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
154
        t2 = WorkingTree.open('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
155
        self.assertEqual(t.basedir, t2.basedir)
156
        self.assertEqual(b.base, t2.branch.base)
157
        # TODO maybe we should check the branch format? not sure if its
158
        # appropriate here.
159
160
    def test_rename_dirs(self):
161
        """Test renaming directories and the files within them."""
162
        wt = self.make_branch_and_tree('.')
163
        b = wt.branch
164
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
165
        wt.add(['dir', 'dir/sub', 'dir/sub/file'])
166
167
        wt.commit('create initial state')
168
169
        revid = b.revision_history()[0]
170
        self.log('first revision_id is {%s}' % revid)
171
        
172
        inv = b.repository.get_revision_inventory(revid)
173
        self.log('contents of inventory: %r' % inv.entries())
174
175
        self.check_inventory_shape(inv,
176
                                   ['dir', 'dir/sub', 'dir/sub/file'])
177
178
        wt.rename_one('dir', 'newdir')
179
180
        self.check_inventory_shape(wt.read_working_inventory(),
181
                                   ['newdir', 'newdir/sub', 'newdir/sub/file'])
182
183
        wt.rename_one('newdir/sub', 'newdir/newsub')
184
        self.check_inventory_shape(wt.read_working_inventory(),
185
                                   ['newdir', 'newdir/newsub',
186
                                    'newdir/newsub/file'])
187
188
    def test_add_in_unversioned(self):
189
        """Try to add a file in an unversioned directory.
190
191
        "bzr add" adds the parent as necessary, but simple working tree add
192
        doesn't do that.
193
        """
194
        from bzrlib.errors import NotVersionedError
195
        wt = self.make_branch_and_tree('.')
196
        self.build_tree(['foo/',
197
                         'foo/hello'])
198
        self.assertRaises(NotVersionedError,
199
                          wt.add,
200
                          'foo/hello')
201
202
    def test_add_missing(self):
203
        # adding a msising file -> NoSuchFile
204
        wt = self.make_branch_and_tree('.')
205
        self.assertRaises(errors.NoSuchFile, wt.add, 'fpp')
206
207
    def test_remove_verbose(self):
208
        #FIXME the remove api should not print or otherwise depend on the
209
        # text UI - RBC 20060124
210
        wt = self.make_branch_and_tree('.')
211
        self.build_tree(['hello'])
212
        wt.add(['hello'])
213
        wt.commit(message='add hello')
214
        stdout = StringIO()
215
        stderr = StringIO()
216
        self.assertEqual(None, self.apply_redirected(None, stdout, stderr,
217
                                                     wt.remove,
218
                                                     ['hello'],
219
                                                     verbose=True))
220
        self.assertEqual('?       hello\n', stdout.getvalue())
221
        self.assertEqual('', stderr.getvalue())
222
223
    def test_clone_trivial(self):
224
        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.
225
        cloned_dir = wt.bzrdir.clone('target')
226
        cloned = cloned_dir.open_workingtree()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
227
        self.assertEqual(cloned.last_revision(), wt.last_revision())
228
229
    def test_last_revision(self):
230
        wt = self.make_branch_and_tree('source')
231
        self.assertEqual(None, wt.last_revision())
232
        wt.commit('A', allow_pointless=True, rev_id='A')
233
        self.assertEqual('A', wt.last_revision())
234
235
    def test_set_last_revision(self):
236
        wt = self.make_branch_and_tree('source')
237
        self.assertEqual(None, wt.last_revision())
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
238
        # cannot set the last revision to one not in the branch history.
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
239
        self.assertRaises(errors.NoSuchRevision, wt.set_last_revision, 'A')
240
        wt.commit('A', allow_pointless=True, rev_id='A')
241
        self.assertEqual('A', wt.last_revision())
242
        # None is aways in the branch
243
        wt.set_last_revision(None)
244
        self.assertEqual(None, wt.last_revision())
245
        # and now we can set it to 'A'
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
246
        # because some formats mutate the branch to set it on the tree
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
247
        # we need to alter the branch to let this pass.
248
        wt.branch.set_revision_history(['A', 'B'])
249
        wt.set_last_revision('A')
250
        self.assertEqual('A', wt.last_revision())
251
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
252
    def test_set_last_revision_different_to_branch(self):
253
        # working tree formats from the meta-dir format and newer support
254
        # setting the last revision on a tree independently of that on the 
255
        # branch. Its concievable that some future formats may want to 
256
        # couple them again (i.e. because its really a smart server and
257
        # the working tree will always match the branch). So we test
258
        # that formats where initialising a branch does not initialise a 
259
        # tree - and thus have separable entities - support skewing the 
260
        # two things.
261
        branch = self.make_branch('tree')
262
        try:
263
            # if there is a working tree now, this is not supported.
264
            branch.bzrdir.open_workingtree()
265
            return
266
        except errors.NoWorkingTree:
267
            pass
268
        wt = branch.bzrdir.create_workingtree()
269
        wt.commit('A', allow_pointless=True, rev_id='A')
270
        wt.set_last_revision(None)
271
        self.assertEqual(None, wt.last_revision())
272
        self.assertEqual('A', wt.branch.last_revision())
273
        # and now we can set it back to 'A'
274
        wt.set_last_revision('A')
275
        self.assertEqual('A', wt.last_revision())
276
        self.assertEqual('A', wt.branch.last_revision())
277
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
278
    def test_clone_and_commit_preserves_last_revision(self):
279
        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.
280
        cloned_dir = wt.bzrdir.clone('target')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
281
        wt.commit('A', allow_pointless=True, rev_id='A')
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.
282
        self.assertNotEqual(cloned_dir.open_workingtree().last_revision(),
283
                            wt.last_revision())
284
285
    def test_clone_preserves_content(self):
286
        wt = self.make_branch_and_tree('source')
287
        self.build_tree(['added', 'deleted', 'notadded'], transport=wt.bzrdir.transport.clone('..'))
288
        wt.add('deleted', 'deleted')
289
        wt.commit('add deleted')
290
        wt.remove('deleted')
291
        wt.add('added', 'added')
292
        cloned_dir = wt.bzrdir.clone('target')
293
        cloned = cloned_dir.open_workingtree()
294
        cloned_transport = cloned.bzrdir.transport.clone('..')
295
        self.assertFalse(cloned_transport.has('deleted'))
296
        self.assertTrue(cloned_transport.has('added'))
297
        self.assertFalse(cloned_transport.has('notadded'))
298
        self.assertEqual('added', cloned.path2id('added'))
299
        self.assertEqual(None, cloned.path2id('deleted'))
300
        self.assertEqual(None, cloned.path2id('notadded'))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
301
        
302
    def test_basis_tree_returns_last_revision(self):
303
        wt = self.make_branch_and_tree('.')
304
        self.build_tree(['foo'])
305
        wt.add('foo', 'foo-id')
306
        wt.commit('A', rev_id='A')
307
        wt.rename_one('foo', 'bar')
308
        wt.commit('B', rev_id='B')
309
        wt.set_last_revision('B')
310
        tree = wt.basis_tree()
311
        self.failUnless(tree.has_filename('bar'))
312
        wt.set_last_revision('A')
313
        tree = wt.basis_tree()
314
        self.failUnless(tree.has_filename('foo'))
315
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.
316
    def test_clone_tree_revision(self):
317
        # make a tree with a last-revision,
318
        # and clone it with a different last-revision, this should switch
319
        # do it.
320
        #
321
        # also test that the content is merged
322
        # and conflicts recorded.
323
        # This should merge between the trees - local edits should be preserved
324
        # but other changes occured.
325
        # we test this by having one file that does
326
        # not change between two revisions, and another that does -
327
        # if the changed one is not changed, fail,
328
        # if the one that did not change has lost a local change, fail.
329
        # 
330
        raise TestSkipped('revision limiting is not implemented yet.')
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
331
332
    def test_initialize_with_revision_id(self):
333
        # a bzrdir can construct a working tree for itself @ a specific revision.
334
        source = self.make_branch_and_tree('source')
335
        source.commit('a', rev_id='a', allow_pointless=True)
336
        source.commit('b', rev_id='b', allow_pointless=True)
337
        self.build_tree(['new/'])
338
        made_control = self.bzrdir_format.initialize('new')
339
        source.branch.repository.clone(made_control)
340
        source.branch.clone(made_control)
341
        made_tree = self.workingtree_format.initialize(made_control, revision_id='a')
342
        self.assertEqual('a', made_tree.last_revision())
1508.1.23 by Robert Collins
Test that the working tree last revision is indeed set during commit.
343
1508.1.24 by Robert Collins
Add update command for use with checkouts.
344
    def test_update_sets_last_revision(self):
345
        # working tree formats from the meta-dir format and newer support
346
        # setting the last revision on a tree independently of that on the 
347
        # branch. Its concievable that some future formats may want to 
348
        # couple them again (i.e. because its really a smart server and
349
        # the working tree will always match the branch). So we test
350
        # that formats where initialising a branch does not initialise a 
351
        # tree - and thus have separable entities - support skewing the 
352
        # two things.
353
        main_branch = self.make_branch('tree')
354
        try:
355
            # if there is a working tree now, this is not supported.
356
            main_branch.bzrdir.open_workingtree()
357
            return
358
        except errors.NoWorkingTree:
359
            pass
360
        wt = main_branch.bzrdir.create_workingtree()
361
        # create an out of date working tree by making a checkout in this
362
        # current format
363
        self.build_tree(['checkout/', 'tree/file'])
364
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
1508.1.25 by Robert Collins
Update per review comments.
365
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, main_branch)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
366
        old_tree = self.workingtree_format.initialize(checkout)
367
        # now commit to 'tree'
368
        wt.add('file')
369
        wt.commit('A', rev_id='A')
370
        # and update old_tree
371
        self.assertEqual(0, old_tree.update())
372
        self.failUnlessExists('checkout/file')
373
        self.assertEqual('A', old_tree.last_revision())
374
375
    def test_update_returns_conflict_count(self):
376
        # working tree formats from the meta-dir format and newer support
377
        # setting the last revision on a tree independently of that on the 
378
        # branch. Its concievable that some future formats may want to 
379
        # couple them again (i.e. because its really a smart server and
380
        # the working tree will always match the branch). So we test
381
        # that formats where initialising a branch does not initialise a 
382
        # tree - and thus have separable entities - support skewing the 
383
        # two things.
384
        main_branch = self.make_branch('tree')
385
        try:
386
            # if there is a working tree now, this is not supported.
387
            main_branch.bzrdir.open_workingtree()
388
            return
389
        except errors.NoWorkingTree:
390
            pass
391
        wt = main_branch.bzrdir.create_workingtree()
392
        # create an out of date working tree by making a checkout in this
393
        # current format
394
        self.build_tree(['checkout/', 'tree/file'])
395
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
1508.1.25 by Robert Collins
Update per review comments.
396
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, main_branch)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
397
        old_tree = self.workingtree_format.initialize(checkout)
398
        # now commit to 'tree'
399
        wt.add('file')
400
        wt.commit('A', rev_id='A')
401
        # and add a file file to the checkout
402
        self.build_tree(['checkout/file'])
403
        old_tree.add('file')
404
        # and update old_tree
405
        self.assertEqual(1, old_tree.update())
406
        self.assertEqual('A', old_tree.last_revision())
407
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
408
    def test_merge_revert(self):
409
        from bzrlib.merge import merge_inner
410
        this = self.make_branch_and_tree('b1')
411
        open('b1/a', 'wb').write('a test\n')
412
        this.add('a')
413
        open('b1/b', 'wb').write('b test\n')
414
        this.add('b')
415
        this.commit(message='')
416
        base = this.bzrdir.clone('b2').open_workingtree()
417
        open('b2/a', 'wb').write('b test\n')
418
        other = this.bzrdir.clone('b3').open_workingtree()
419
        open('b3/a', 'wb').write('c test\n')
420
        open('b3/c', 'wb').write('c test\n')
421
        other.add('c')
422
423
        open('b1/b', 'wb').write('q test\n')
424
        open('b1/d', 'wb').write('d test\n')
425
        merge_inner(this.branch, other, base, this_tree=this)
426
        self.assertNotEqual(open('b1/a', 'rb').read(), 'a test\n')
427
        this.revert([])
428
        self.assertEqual(open('b1/a', 'rb').read(), 'a test\n')
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
429
        self.assertIs(os.path.exists('b1/b.~1~'), True)
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
430
        self.assertIs(os.path.exists('b1/c'), False)
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
431
        self.assertIs(os.path.exists('b1/a.~1~'), False)
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
432
        self.assertIs(os.path.exists('b1/d'), True)
1534.7.200 by Aaron Bentley
Merge from mainline
433
1587.1.10 by Robert Collins
update updates working tree and branch together.
434
    def test_update_updates_bound_branch_no_local_commits(self):
435
        # doing an update in a tree updates the branch its bound to too.
436
        master_tree = self.make_branch_and_tree('master')
437
        tree = self.make_branch_and_tree('tree')
438
        try:
439
            tree.branch.bind(master_tree.branch)
440
        except errors.UpgradeRequired:
441
            # legacy branches cannot bind
442
            return
443
        master_tree.commit('foo', rev_id='foo', allow_pointless=True)
444
        tree.update()
445
        self.assertEqual('foo', tree.last_revision())
446
        self.assertEqual('foo', tree.branch.last_revision())
1587.1.11 by Robert Collins
Local commits appear to be working properly.
447
448
    def test_update_turns_local_commit_into_merge(self):
449
        # 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.
450
        # makes pending-merges. 
451
        # this is done so that 'bzr update; bzr revert' will always produce
452
        # an exact copy of the 'logical branch' - the referenced branch for
453
        # a checkout, and the master for a bound branch.
454
        # its possible that we should instead have 'bzr update' when there
455
        # is nothing new on the master leave the current commits intact and
456
        # alter 'revert' to revert to the master always. But for now, its
457
        # good.
1587.1.11 by Robert Collins
Local commits appear to be working properly.
458
        master_tree = self.make_branch_and_tree('master')
459
        tree = self.make_branch_and_tree('tree')
460
        try:
461
            tree.branch.bind(master_tree.branch)
462
        except errors.UpgradeRequired:
463
            # legacy branches cannot bind
464
            return
465
        tree.commit('foo', rev_id='foo', allow_pointless=True, local=True)
466
        tree.commit('bar', rev_id='bar', allow_pointless=True, local=True)
467
        tree.update()
468
        self.assertEqual(None, tree.last_revision())
469
        self.assertEqual([], tree.branch.revision_history())
470
        self.assertEqual(['bar'], tree.pending_merges())
471
1558.3.3 by Aaron Bentley
Fix error handling for merge_modified
472
    def test_merge_modified(self):
473
        tree = self.make_branch_and_tree('master')
474
        tree._control_files.put('merge-hashes', StringIO('asdfasdf'))
475
        self.assertRaises(errors.MergeModifiedFormatError, tree.merge_modified)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
476
1534.10.22 by Aaron Bentley
Got ConflictList implemented
477
    def test_conflicts(self):
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
478
        from bzrlib.tests.test_conflicts import example_conflicts
479
        tree = self.make_branch_and_tree('master')
480
        try:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
481
            tree.set_conflicts(example_conflicts)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
482
        except UnsupportedOperation:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
483
            raise TestSkipped('set_conflicts not supported')
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
484
            
485
        tree2 = WorkingTree.open('master')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
486
        self.assertEqual(tree2.conflicts(), example_conflicts)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
487
        tree2._control_files.put('conflicts', StringIO(''))
488
        self.assertRaises(errors.ConflictFormatError, 
1534.10.22 by Aaron Bentley
Got ConflictList implemented
489
                          tree2.conflicts)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
490
        tree2._control_files.put('conflicts', StringIO('a'))
491
        self.assertRaises(errors.ConflictFormatError, 
1534.10.22 by Aaron Bentley
Got ConflictList implemented
492
                          tree2.conflicts)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
493
494
    def make_merge_conflicts(self):
495
        from bzrlib.merge import merge_inner 
496
        tree = self.make_branch_and_tree('mine')
497
        file('mine/bloo', 'wb').write('one')
498
        tree.add('bloo')
1534.10.14 by Aaron Bentley
Made revert clear conflicts
499
        file('mine/blo', 'wb').write('on')
500
        tree.add('blo')
1534.10.12 by Aaron Bentley
Merge produces new conflicts
501
        tree.commit("blah", allow_pointless=False)
502
        base = tree.basis_tree()
503
        BzrDir.open("mine").sprout("other")
504
        file('other/bloo', 'wb').write('two')
505
        othertree = WorkingTree.open('other')
506
        othertree.commit('blah', allow_pointless=False)
507
        file('mine/bloo', 'wb').write('three')
508
        tree.commit("blah", allow_pointless=False)
509
        merge_inner(tree.branch, othertree, base, this_tree=tree)
510
        return tree
511
512
    def test_merge_conflicts(self):
513
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
514
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
515
516
    def test_clear_merge_conflicts(self):
1534.10.22 by Aaron Bentley
Got ConflictList implemented
517
        from bzrlib.conflicts import ConflictList
1534.10.12 by Aaron Bentley
Merge produces new conflicts
518
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
519
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
520
        try:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
521
            tree.set_conflicts(ConflictList())
1534.10.12 by Aaron Bentley
Merge produces new conflicts
522
        except UnsupportedOperation:
523
            raise TestSkipped
1534.10.22 by Aaron Bentley
Got ConflictList implemented
524
        self.assertEqual(tree.conflicts(), ConflictList())
1534.10.14 by Aaron Bentley
Made revert clear conflicts
525
526
    def test_revert_clear_conflicts(self):
527
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
528
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
529
        tree.revert(["blo"])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
530
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
531
        tree.revert(["bloo"])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
532
        self.assertEqual(len(tree.conflicts()), 0)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
533
534
    def test_revert_clear_conflicts2(self):
535
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
536
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
537
        tree.revert([])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
538
        self.assertEqual(len(tree.conflicts()), 0)
1624.3.22 by Olaf Conradi
Merge bzr.dev
539
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
540
    def test_format_description(self):
541
        tree = self.make_branch_and_tree('tree')
542
        text = tree._format.get_format_description()
543
        self.failUnless(len(text))
1681.1.1 by Robert Collins
Make WorkingTree.branch a read only property. (Robert Collins)
544
545
    def test_branch_attribute_is_not_settable(self):
546
        # the branch attribute is an aspect of the working tree, not a
547
        # configurable attribute
548
        tree = self.make_branch_and_tree('tree')
549
        def set_branch():
550
            tree.branch = tree.branch
551
        self.assertRaises(AttributeError, set_branch)
552
1713.3.1 by Robert Collins
Smoke tests for tree.list_files and bzr ignored when a versioned file matches an ignore rule.
553
    def test_list_files_versioned_before_ignored(self):
554
        """A versioned file matching an ignore rule should not be ignored."""
555
        tree = self.make_branch_and_tree('.')
556
        self.build_tree(['foo.pyc'])
557
        # ensure that foo.pyc is ignored
558
        self.build_tree_contents([('.bzrignore', 'foo.pyc')])
559
        tree.add('foo.pyc', 'anid')
560
        files = sorted(list(tree.list_files()))
561
        self.assertEqual((u'.bzrignore', '?', 'file', None), files[0][:-1])
562
        self.assertEqual((u'foo.pyc', 'V', 'file', 'anid'), files[1][:-1])
563
        self.assertEqual(2, len(files))