~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from cStringIO import StringIO
19
19
import os
20
20
 
21
 
from bzrlib import (
22
 
    bzrdir,
23
 
    conflicts,
24
 
    errors,
25
 
    workingtree,
26
 
    )
 
21
from bzrlib import ignores
 
22
import bzrlib
27
23
from bzrlib.branch import Branch
 
24
from bzrlib import bzrdir, conflicts, errors, workingtree
28
25
from bzrlib.bzrdir import BzrDir
 
26
from bzrlib.errors import NotBranchError, NotVersionedError
29
27
from bzrlib.lockdir import LockDir
30
28
from bzrlib.mutabletree import needs_tree_write_lock
 
29
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
 
30
from bzrlib.symbol_versioning import zero_thirteen
31
31
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
 
32
from bzrlib.trace import mutter
32
33
from bzrlib.transport import get_transport
33
34
from bzrlib.workingtree import (
34
35
    TreeEntry,
35
36
    TreeDirectory,
36
37
    TreeFile,
37
38
    TreeLink,
 
39
    WorkingTree,
38
40
    )
39
41
 
40
 
 
41
42
class TestTreeDirectory(TestCaseWithTransport):
42
43
 
43
44
    def test_kind_character(self):
93
94
        """See WorkingTreeFormat.get_format_string()."""
94
95
        return "Sample tree format."
95
96
 
96
 
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
97
 
                   accelerator_tree=None, hardlink=False):
 
97
    def initialize(self, a_bzrdir, revision_id=None):
98
98
        """Sample branches cannot be created."""
99
99
        t = a_bzrdir.get_workingtree_transport(self)
100
100
        t.put_bytes('format', self.get_format_string())
174
174
        t = control.get_workingtree_transport(None)
175
175
        self.assertEqualDiff('Bazaar-NG Working Tree format 3',
176
176
                             t.get('format').read())
177
 
        self.assertEqualDiff(t.get('inventory').read(), 
 
177
        # self.assertContainsRe(t.get('inventory').read(), 
 
178
        #                       '<inventory file_id="[^"]*" format="5">\n'
 
179
        #                       '</inventory>\n',
 
180
        #                      )
 
181
        # WorkingTreeFormat3 doesn't default to creating a unique root id,
 
182
        # because it is incompatible with older bzr versions
 
183
        self.assertContainsRe(t.get('inventory').read(),
178
184
                              '<inventory format="5">\n'
179
185
                              '</inventory>\n',
180
186
                             )
216
222
        control.create_repository()
217
223
        control.create_branch()
218
224
        tree = workingtree.WorkingTreeFormat3().initialize(control)
219
 
        tree._transport.delete("pending-merges")
 
225
        tree._control_files._transport.delete("pending-merges")
220
226
        self.assertEqual([], tree.get_parent_ids())
221
227
 
222
228
 
225
231
 
226
232
    def create_format2_tree(self, url):
227
233
        return self.make_branch_and_tree(
228
 
            url, format=bzrdir.BzrDirFormat6())
 
234
            url, format=bzrlib.bzrdir.BzrDirFormat6())
229
235
 
230
236
    def test_conflicts(self):
231
237
        # test backwards compatability
250
256
        self.assertEqual(list(tree.conflicts()), [expected])
251
257
 
252
258
 
 
259
class TestNonFormatSpecificCode(TestCaseWithTransport):
 
260
    """This class contains tests of workingtree that are not format specific."""
 
261
 
 
262
    def test_gen_file_id(self):
 
263
        file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_file_id,
 
264
                                      'filename')
 
265
        self.assertStartsWith(file_id, 'filename-')
 
266
 
 
267
    def test_gen_root_id(self):
 
268
        file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_root_id)
 
269
        self.assertStartsWith(file_id, 'tree_root-')
 
270
        
 
271
 
253
272
class InstrumentedTree(object):
254
273
    """A instrumented tree to check the needs_tree_write_lock decorator."""
255
274
 
294
313
        self.assertEqual(['t', 'u'], tree._locks)
295
314
        self.assertRaises(TypeError, tree.method_that_raises, 'foo')
296
315
        self.assertEqual(['t', 'u', 't', 'u'], tree._locks)
297
 
 
298
 
 
299
 
class TestRevert(TestCaseWithTransport):
300
 
 
301
 
    def test_revert_conflicts_recursive(self):
302
 
        this_tree = self.make_branch_and_tree('this-tree')
303
 
        self.build_tree_contents([('this-tree/foo/',),
304
 
                                  ('this-tree/foo/bar', 'bar')])
305
 
        this_tree.add(['foo', 'foo/bar'])
306
 
        this_tree.commit('created foo/bar')
307
 
        other_tree = this_tree.bzrdir.sprout('other-tree').open_workingtree()
308
 
        self.build_tree_contents([('other-tree/foo/bar', 'baz')])
309
 
        other_tree.commit('changed bar')
310
 
        self.build_tree_contents([('this-tree/foo/bar', 'qux')])
311
 
        this_tree.commit('changed qux')
312
 
        this_tree.merge_from_branch(other_tree.branch)
313
 
        self.assertEqual(1, len(this_tree.conflicts()))
314
 
        this_tree.revert(['foo'])
315
 
        self.assertEqual(0, len(this_tree.conflicts()))
316
 
 
317
 
 
318
 
class TestAutoResolve(TestCaseWithTransport):
319
 
 
320
 
    def test_auto_resolve(self):
321
 
        base = self.make_branch_and_tree('base')
322
 
        self.build_tree_contents([('base/hello', 'Hello')])
323
 
        base.add('hello', 'hello_id')
324
 
        base.commit('Hello')
325
 
        other = base.bzrdir.sprout('other').open_workingtree()
326
 
        self.build_tree_contents([('other/hello', 'hELLO')])
327
 
        other.commit('Case switch')
328
 
        this = base.bzrdir.sprout('this').open_workingtree()
329
 
        self.failUnlessExists('this/hello')
330
 
        self.build_tree_contents([('this/hello', 'Hello World')])
331
 
        this.commit('Add World')
332
 
        this.merge_from_branch(other.branch)
333
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
334
 
                         this.conflicts())
335
 
        this.auto_resolve()
336
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
337
 
                         this.conflicts())
338
 
        self.build_tree_contents([('this/hello', '<<<<<<<')])
339
 
        this.auto_resolve()
340
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
341
 
                         this.conflicts())
342
 
        self.build_tree_contents([('this/hello', '=======')])
343
 
        this.auto_resolve()
344
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
345
 
                         this.conflicts())
346
 
        self.build_tree_contents([('this/hello', '\n>>>>>>>')])
347
 
        remaining, resolved = this.auto_resolve()
348
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
349
 
                         this.conflicts())
350
 
        self.assertEqual([], resolved)
351
 
        self.build_tree_contents([('this/hello', 'hELLO wORLD')])
352
 
        remaining, resolved = this.auto_resolve()
353
 
        self.assertEqual([], this.conflicts())
354
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
355
 
                         resolved)
356
 
        self.failIfExists('this/hello.BASE')
357
 
 
358
 
    def test_auto_resolve_dir(self):
359
 
        tree = self.make_branch_and_tree('tree')
360
 
        self.build_tree(['tree/hello/'])
361
 
        tree.add('hello', 'hello-id')
362
 
        file_conflict = conflicts.TextConflict('file', None, 'hello-id')
363
 
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
364
 
        tree.auto_resolve()
365
 
 
366
 
 
367
 
class TestFindTrees(TestCaseWithTransport):
368
 
 
369
 
    def test_find_trees(self):
370
 
        self.make_branch_and_tree('foo')
371
 
        self.make_branch_and_tree('foo/bar')
372
 
        # Sticking a tree inside a control dir is heinous, so let's skip it
373
 
        self.make_branch_and_tree('foo/.bzr/baz')
374
 
        self.make_branch('qux')
375
 
        trees = workingtree.WorkingTree.find_trees('.')
376
 
        self.assertEqual(2, len(list(trees)))