1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
from bzrlib import (
bzrdir,
conflicts,
errors,
tests,
)
# TODO: Test commit with some added, and added-but-missing files
# RBC 20060124 is that not tested in test_commit.py ?
# The order of 'path' here is important - do not let it
# be a sorted list.
# u'\xe5' == a with circle
# '\xc3\xae' == u'\xee' == i with hat
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
example_conflicts = conflicts.ConflictList(
[conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
conflicts.TextConflict(u'p\xe5tha'),
conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
conflicts.DuplicateID('Unversioned existing file',
u'p\xe5thc', u'p\xe5thc2',
'\xc3\xaedc', '\xc3\xaedc'),
conflicts.DuplicateEntry('Moved existing file to',
u'p\xe5thdd.moved', u'p\xe5thd',
'\xc3\xaedd', None),
conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
None, '\xc3\xaed2e'),
conflicts.UnversionedParent('Versioned directory',
u'p\xe5thf', '\xc3\xaedf'),
conflicts.NonDirectoryParent('Created directory',
u'p\xe5thg', '\xc3\xaedg'),
])
class TestConflicts(tests.TestCaseWithTransport):
def test_conflicts(self):
"""Conflicts are detected properly"""
# Use BzrDirFormat6 so we can fake conflicts
tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
self.build_tree_contents([('hello', 'hello world4'),
('hello.THIS', 'hello world2'),
('hello.BASE', 'hello world1'),
('hello.OTHER', 'hello world3'),
('hello.sploo.BASE', 'yellowworld'),
('hello.sploo.OTHER', 'yellowworld2'),
])
tree.lock_read()
self.assertEqual(6, len(list(tree.list_files())))
tree.unlock()
tree_conflicts = tree.conflicts()
self.assertEqual(2, len(tree_conflicts))
self.assertTrue('hello' in tree_conflicts[0].path)
self.assertTrue('hello.sploo' in tree_conflicts[1].path)
conflicts.restore('hello')
conflicts.restore('hello.sploo')
self.assertEqual(0, len(tree.conflicts()))
self.assertFileEqual('hello world2', 'hello')
self.assertFalse(os.path.lexists('hello.sploo'))
self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
self.assertRaises(errors.NotConflicted,
conflicts.restore, 'hello.sploo')
def test_resolve_conflict_dir(self):
tree = self.make_branch_and_tree('.')
self.build_tree_contents([('hello', 'hello world4'),
('hello.THIS', 'hello world2'),
('hello.BASE', 'hello world1'),
])
os.mkdir('hello.OTHER')
tree.add('hello', 'q')
l = conflicts.ConflictList([conflicts.TextConflict('hello')])
l.remove_files(tree)
def test_select_conflicts(self):
tree = self.make_branch_and_tree('.')
clist = conflicts.ConflictList
def check_select(not_selected, selected, paths, **kwargs):
self.assertEqual(
(not_selected, selected),
tree_conflicts.select_conflicts(tree, paths, **kwargs))
foo = conflicts.ContentsConflict('foo')
bar = conflicts.ContentsConflict('bar')
tree_conflicts = clist([foo, bar])
check_select(clist([bar]), clist([foo]), ['foo'])
check_select(clist(), tree_conflicts,
[''], ignore_misses=True, recurse=True)
foobaz = conflicts.ContentsConflict('foo/baz')
tree_conflicts = clist([foobaz, bar])
check_select(clist([bar]), clist([foobaz]),
['foo'], ignore_misses=True, recurse=True)
qux = conflicts.PathConflict('qux', 'foo/baz')
tree_conflicts = clist([qux])
check_select(clist(), tree_conflicts,
['foo'], ignore_misses=True, recurse=True)
check_select (tree_conflicts, clist(), ['foo'], ignore_misses=True)
def test_resolve_conflicts_recursive(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['dir/', 'dir/hello'])
tree.add(['dir', 'dir/hello'])
dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
tree.set_conflicts(dirhello)
conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
self.assertEqual(dirhello, tree.conflicts())
conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
class TestConflictStanzas(tests.TestCase):
def test_stanza_roundtrip(self):
# write and read our example stanza.
stanza_iter = example_conflicts.to_stanzas()
processed = conflicts.ConflictList.from_stanzas(stanza_iter)
for o, p in zip(processed, example_conflicts):
self.assertEqual(o, p)
self.assertIsInstance(o.path, unicode)
if o.file_id is not None:
self.assertIsInstance(o.file_id, str)
conflict_path = getattr(o, 'conflict_path', None)
if conflict_path is not None:
self.assertIsInstance(conflict_path, unicode)
conflict_file_id = getattr(o, 'conflict_file_id', None)
if conflict_file_id is not None:
self.assertIsInstance(conflict_file_id, str)
def test_stanzification(self):
for stanza in example_conflicts.to_stanzas():
if 'file_id' in stanza:
# In Stanza form, the file_id has to be unicode.
self.assertStartsWith(stanza['file_id'], u'\xeed')
self.assertStartsWith(stanza['path'], u'p\xe5th')
if 'conflict_path' in stanza:
self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
if 'conflict_file_id' in stanza:
self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
|