1
# Copyright (C) 2005-2011 Canonical Ltd
2
# Copyright (C) 2018-2020 Breezy Developers
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
20
from ...conflicts import resolve
25
from ...tests import (
28
from ...tests.test_conflicts import vary_by_conflicts
31
from .. import conflicts as bzr_conflicts
34
load_tests = scenarios.load_tests_apply_scenarios
37
class TestPerConflict(tests.TestCase):
39
scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
41
def test_stringification(self):
42
text = str(self.conflict)
43
self.assertContainsString(text, self.conflict.path)
44
self.assertContainsString(text.lower(), "conflict")
45
self.assertContainsString(repr(self.conflict),
46
self.conflict.__class__.__name__)
48
def test_stanza_roundtrip(self):
50
o = bzr_conflicts.Conflict.factory(**p.as_stanza().as_dict())
51
self.assertEqual(o, p)
53
self.assertIsInstance(o.path, str)
55
if o.file_id is not None:
56
self.assertIsInstance(o.file_id, bytes)
58
conflict_path = getattr(o, 'conflict_path', None)
59
if conflict_path is not None:
60
self.assertIsInstance(conflict_path, str)
62
conflict_file_id = getattr(o, 'conflict_file_id', None)
63
if conflict_file_id is not None:
64
self.assertIsInstance(conflict_file_id, bytes)
66
def test_stanzification(self):
67
stanza = self.conflict.as_stanza()
68
if 'file_id' in stanza:
69
# In Stanza form, the file_id has to be unicode.
70
self.assertStartsWith(stanza['file_id'], u'\xeed')
71
self.assertStartsWith(stanza['path'], u'p\xe5th')
72
if 'conflict_path' in stanza:
73
self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
74
if 'conflict_file_id' in stanza:
75
self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
78
class TestConflicts(tests.TestCaseWithTransport):
80
def test_resolve_conflict_dir(self):
81
tree = self.make_branch_and_tree('.')
82
self.build_tree_contents([('hello', b'hello world4'),
83
('hello.THIS', b'hello world2'),
84
('hello.BASE', b'hello world1'),
86
os.mkdir('hello.OTHER')
87
tree.add('hello', b'q')
88
l = bzr_conflicts.ConflictList([bzr_conflicts.TextConflict('hello')])
91
def test_select_conflicts(self):
92
tree = self.make_branch_and_tree('.')
93
clist = bzr_conflicts.ConflictList
95
def check_select(not_selected, selected, paths, **kwargs):
97
(not_selected, selected),
98
tree_conflicts.select_conflicts(tree, paths, **kwargs))
100
foo = bzr_conflicts.ContentsConflict('foo')
101
bar = bzr_conflicts.ContentsConflict('bar')
102
tree_conflicts = clist([foo, bar])
104
check_select(clist([bar]), clist([foo]), ['foo'])
105
check_select(clist(), tree_conflicts,
106
[''], ignore_misses=True, recurse=True)
108
foobaz = bzr_conflicts.ContentsConflict('foo/baz')
109
tree_conflicts = clist([foobaz, bar])
111
check_select(clist([bar]), clist([foobaz]),
112
['foo'], ignore_misses=True, recurse=True)
114
qux = bzr_conflicts.PathConflict('qux', 'foo/baz')
115
tree_conflicts = clist([qux])
117
check_select(clist(), tree_conflicts,
118
['foo'], ignore_misses=True, recurse=True)
119
check_select(tree_conflicts, clist(), ['foo'], ignore_misses=True)
121
def test_resolve_conflicts_recursive(self):
122
tree = self.make_branch_and_tree('.')
123
self.build_tree(['dir/', 'dir/hello'])
124
tree.add(['dir', 'dir/hello'])
126
dirhello = [bzr_conflicts.TextConflict('dir/hello')]
127
tree.set_conflicts(dirhello)
129
resolve(tree, ['dir'], recursive=False, ignore_misses=True)
130
self.assertEqual(dirhello, tree.conflicts())
132
resolve(tree, ['dir'], recursive=True, ignore_misses=True)
133
self.assertEqual(bzr_conflicts.ConflictList([]), tree.conflicts())