/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
1
# Copyright (C) 2005-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18
"""Tests for weave-era working tree formats."""
19
20
import os
21
22
from bzrlib import (
23
    conflicts,
24
    errors,
25
    )
26
27
from bzrlib.tests import (
28
    TestCaseWithTransport,
29
    )
30
5582.12.6 by Jelmer Vernooij
merge bzr.dev.
31
from bzrlib.plugins.weave_fmt.bzrdir import BzrDirFormat6
5697.1.1 by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file.
32
33
34
class TestFormat2WorkingTree(TestCaseWithTransport):
35
    """Tests that are specific to format 2 trees."""
36
37
    def create_format2_tree(self, url):
38
        return self.make_branch_and_tree(
39
            url, format=BzrDirFormat6())
40
41
    def test_conflicts(self):
42
        # test backwards compatability
43
        tree = self.create_format2_tree('.')
44
        self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
45
                          None)
46
        file('lala.BASE', 'wb').write('labase')
47
        expected = conflicts.ContentsConflict('lala')
48
        self.assertEqual(list(tree.conflicts()), [expected])
49
        file('lala', 'wb').write('la')
50
        tree.add('lala', 'lala-id')
51
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
52
        self.assertEqual(list(tree.conflicts()), [expected])
53
        file('lala.THIS', 'wb').write('lathis')
54
        file('lala.OTHER', 'wb').write('laother')
55
        # When "text conflict"s happen, stem, THIS and OTHER are text
56
        expected = conflicts.TextConflict('lala', file_id='lala-id')
57
        self.assertEqual(list(tree.conflicts()), [expected])
58
        os.unlink('lala.OTHER')
59
        os.mkdir('lala.OTHER')
60
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
61
        self.assertEqual(list(tree.conflicts()), [expected])
62
63
    def test_detect_conflicts(self):
64
        """Conflicts are detected properly"""
65
        tree = self.create_format2_tree('.')
66
        self.build_tree_contents([('hello', 'hello world4'),
67
                                  ('hello.THIS', 'hello world2'),
68
                                  ('hello.BASE', 'hello world1'),
69
                                  ('hello.OTHER', 'hello world3'),
70
                                  ('hello.sploo.BASE', 'yellowworld'),
71
                                  ('hello.sploo.OTHER', 'yellowworld2'),
72
                                  ])
73
        tree.lock_read()
74
        self.assertLength(6, list(tree.list_files()))
75
        tree.unlock()
76
        tree_conflicts = tree.conflicts()
77
        self.assertLength(2, tree_conflicts)
78
        self.assertTrue('hello' in tree_conflicts[0].path)
79
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
80
        conflicts.restore('hello')
81
        conflicts.restore('hello.sploo')
82
        self.assertLength(0, tree.conflicts())
83
        self.assertFileEqual('hello world2', 'hello')
84
        self.assertFalse(os.path.lexists('hello.sploo'))
85
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
86
        self.assertRaises(errors.NotConflicted,
87
                          conflicts.restore, 'hello.sploo')