1
# Copyright (C) 2005-2011 Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
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.
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.
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
18
"""Tests for weave-era working tree formats."""
27
from bzrlib.tests import (
28
TestCaseWithTransport,
31
from bzrlib.plugins.weave_fmt.bzrdir import BzrDirFormat6
34
class TestFormat2WorkingTree(TestCaseWithTransport):
35
"""Tests that are specific to format 2 trees."""
37
def create_format2_tree(self, url):
38
return self.make_branch_and_tree(
39
url, format=BzrDirFormat6())
41
def test_conflicts(self):
42
# test backwards compatability
43
tree = self.create_format2_tree('.')
44
self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
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])
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'),
74
self.assertLength(6, list(tree.list_files()))
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')