44
32
# be a sorted list.
45
33
# u'\xe5' == a with circle
46
34
# '\xc3\xae' == u'\xee' == i with hat
47
# So these are u'pathg' and 'idg' only with a circle and a hat. (shappo?)
48
example_conflicts = ConflictList([
49
MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
50
ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
51
TextConflict(u'p\xe5tha'),
52
PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
53
DuplicateID('Unversioned existing file', u'p\xe5thc', u'p\xe5thc2',
54
'\xc3\xaedc', '\xc3\xaedc'),
55
DuplicateEntry('Moved existing file to', u'p\xe5thdd.moved', u'p\xe5thd',
57
ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
59
UnversionedParent('Versioned directory', u'p\xe5thf', '\xc3\xaedf'),
60
NonDirectoryParent('Created directory', u'p\xe5thg', '\xc3\xaedg'),
35
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
36
example_conflicts = conflicts.ConflictList(
37
[conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
38
conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
39
conflicts.TextConflict(u'p\xe5tha'),
40
conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
41
conflicts.DuplicateID('Unversioned existing file',
42
u'p\xe5thc', u'p\xe5thc2',
43
'\xc3\xaedc', '\xc3\xaedc'),
44
conflicts.DuplicateEntry('Moved existing file to',
45
u'p\xe5thdd.moved', u'p\xe5thd',
47
conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
49
conflicts.UnversionedParent('Versioned directory',
50
u'p\xe5thf', '\xc3\xaedf'),
51
conflicts.NonDirectoryParent('Created directory',
52
u'p\xe5thg', '\xc3\xaedg'),
64
class TestConflicts(TestCaseWithTransport):
66
def test_conflicts(self):
67
"""Conflicts are detected properly"""
68
tree = self.make_branch_and_tree('.',
69
format=bzrdir.BzrDirFormat6())
71
file('hello', 'w').write('hello world4')
72
file('hello.THIS', 'w').write('hello world2')
73
file('hello.BASE', 'w').write('hello world1')
74
file('hello.OTHER', 'w').write('hello world3')
75
file('hello.sploo.BASE', 'w').write('yellow world')
76
file('hello.sploo.OTHER', 'w').write('yellow world2')
78
self.assertEqual(len(list(tree.list_files())), 6)
80
conflicts = tree.conflicts()
81
self.assertEqual(len(conflicts), 2)
82
self.assert_('hello' in conflicts[0].path)
83
self.assert_('hello.sploo' in conflicts[1].path)
85
restore('hello.sploo')
86
self.assertEqual(len(tree.conflicts()), 0)
87
self.assertFileEqual('hello world2', 'hello')
88
self.assertFalse(os.path.lexists('hello.sploo'))
89
self.assertRaises(NotConflicted, restore, 'hello')
90
self.assertRaises(NotConflicted, restore, 'hello.sploo')
92
def test_resolve_conflict_dir(self):
93
tree = self.make_branch_and_tree('.')
95
file('hello', 'w').write('hello world4')
96
tree.add('hello', 'q')
97
file('hello.THIS', 'w').write('hello world2')
98
file('hello.BASE', 'w').write('hello world1')
99
os.mkdir('hello.OTHER')
100
l = ConflictList([TextConflict('hello')])
103
def test_select_conflicts(self):
104
tree = self.make_branch_and_tree('.')
105
tree_conflicts = ConflictList([ContentsConflict('foo'),
106
ContentsConflict('bar')])
107
self.assertEqual((ConflictList([ContentsConflict('bar')]),
108
ConflictList([ContentsConflict('foo')])),
109
tree_conflicts.select_conflicts(tree, ['foo']))
110
self.assertEqual((ConflictList(), tree_conflicts),
111
tree_conflicts.select_conflicts(tree, [''],
112
ignore_misses=True, recurse=True))
113
tree_conflicts = ConflictList([ContentsConflict('foo/baz'),
114
ContentsConflict('bar')])
115
self.assertEqual((ConflictList([ContentsConflict('bar')]),
116
ConflictList([ContentsConflict('foo/baz')])),
117
tree_conflicts.select_conflicts(tree, ['foo'],
120
tree_conflicts = ConflictList([PathConflict('qux', 'foo/baz')])
121
self.assertEqual((ConflictList(), tree_conflicts),
122
tree_conflicts.select_conflicts(tree, ['foo'],
125
self.assertEqual((tree_conflicts, ConflictList()),
126
tree_conflicts.select_conflicts(tree, ['foo'],
129
def test_resolve_conflicts_recursive(self):
130
tree = self.make_branch_and_tree('.')
131
self.build_tree(['dir/', 'dir/hello'])
132
tree.add(['dir', 'dir/hello'])
133
tree.set_conflicts(ConflictList([TextConflict('dir/hello')]))
134
resolve(tree, ['dir'], recursive=False, ignore_misses=True)
135
self.assertEqual(ConflictList([TextConflict('dir/hello')]),
137
resolve(tree, ['dir'], recursive=True, ignore_misses=True)
138
self.assertEqual(ConflictList([]),
142
class TestConflictStanzas(TestCase):
56
class TestConflictStanzas(tests.TestCase):
144
58
def test_stanza_roundtrip(self):
145
59
# write and read our example stanza.
146
60
stanza_iter = example_conflicts.to_stanzas()
147
processed = ConflictList.from_stanzas(stanza_iter)
61
processed = conflicts.ConflictList.from_stanzas(stanza_iter)
148
62
for o, p in zip(processed, example_conflicts):
149
63
self.assertEqual(o, p)
171
85
self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
172
86
if 'conflict_file_id' in stanza:
173
87
self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
90
class TestConflicts(tests.TestCaseWithTransport):
92
def test_conflicts(self):
93
"""Conflicts are detected properly"""
94
# Use BzrDirFormat6 so we can fake conflicts
95
tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
96
self.build_tree_contents([('hello', 'hello world4'),
97
('hello.THIS', 'hello world2'),
98
('hello.BASE', 'hello world1'),
99
('hello.OTHER', 'hello world3'),
100
('hello.sploo.BASE', 'yellowworld'),
101
('hello.sploo.OTHER', 'yellowworld2'),
104
self.assertEqual(6, len(list(tree.list_files())))
106
tree_conflicts = tree.conflicts()
107
self.assertEqual(2, len(tree_conflicts))
108
self.assertTrue('hello' in tree_conflicts[0].path)
109
self.assertTrue('hello.sploo' in tree_conflicts[1].path)
110
conflicts.restore('hello')
111
conflicts.restore('hello.sploo')
112
self.assertEqual(0, len(tree.conflicts()))
113
self.assertFileEqual('hello world2', 'hello')
114
self.assertFalse(os.path.lexists('hello.sploo'))
115
self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
116
self.assertRaises(errors.NotConflicted,
117
conflicts.restore, 'hello.sploo')
119
def test_resolve_conflict_dir(self):
120
tree = self.make_branch_and_tree('.')
121
self.build_tree_contents([('hello', 'hello world4'),
122
('hello.THIS', 'hello world2'),
123
('hello.BASE', 'hello world1'),
125
os.mkdir('hello.OTHER')
126
tree.add('hello', 'q')
127
l = conflicts.ConflictList([conflicts.TextConflict('hello')])
130
def test_select_conflicts(self):
131
tree = self.make_branch_and_tree('.')
132
clist = conflicts.ConflictList
134
def check_select(not_selected, selected, paths, **kwargs):
136
(not_selected, selected),
137
tree_conflicts.select_conflicts(tree, paths, **kwargs))
139
foo = conflicts.ContentsConflict('foo')
140
bar = conflicts.ContentsConflict('bar')
141
tree_conflicts = clist([foo, bar])
143
check_select(clist([bar]), clist([foo]), ['foo'])
144
check_select(clist(), tree_conflicts,
145
[''], ignore_misses=True, recurse=True)
147
foobaz = conflicts.ContentsConflict('foo/baz')
148
tree_conflicts = clist([foobaz, bar])
150
check_select(clist([bar]), clist([foobaz]),
151
['foo'], ignore_misses=True, recurse=True)
153
qux = conflicts.PathConflict('qux', 'foo/baz')
154
tree_conflicts = clist([qux])
156
check_select(clist(), tree_conflicts,
157
['foo'], ignore_misses=True, recurse=True)
158
check_select (tree_conflicts, clist(), ['foo'], ignore_misses=True)
160
def test_resolve_conflicts_recursive(self):
161
tree = self.make_branch_and_tree('.')
162
self.build_tree(['dir/', 'dir/hello'])
163
tree.add(['dir', 'dir/hello'])
165
dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
166
tree.set_conflicts(dirhello)
168
conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
169
self.assertEqual(dirhello, tree.conflicts())
171
conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
172
self.assertEqual(conflicts.ConflictList([]), tree.conflicts())