20
from bzrlib import bzrdir
21
from bzrlib.tests import TestCaseWithTransport, TestCase
20
from bzrlib.selftest import TestCaseInTempDir
22
21
from bzrlib.branch import Branch
23
from bzrlib.conflicts import (MissingParent, ContentsConflict, TextConflict,
24
PathConflict, DuplicateID, DuplicateEntry, ParentLoop, UnversionedParent,
27
from bzrlib.errors import NotConflicted
22
from bzrlib.commit import Commit
30
25
# TODO: Test commit with some added, and added-but-missing files
31
# RBC 20060124 is that not tested in test_commit.py ?
33
# The order of 'path' here is important - do not let it
35
# u'\xe5' == a with circle
36
# '\xc3\xae' == u'\xee' == i with hat
37
# So these are u'pathg' and 'idg' only with a circle and a hat. (shappo?)
38
example_conflicts = ConflictList([
39
MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
40
ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
41
TextConflict(u'p\xe5tha'),
42
PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
43
DuplicateID('Unversioned existing file', u'p\xe5thc', u'p\xe5thc2',
44
'\xc3\xaedc', '\xc3\xaedc'),
45
DuplicateEntry('Moved existing file to', u'p\xe5thdd.moved', u'p\xe5thd',
47
ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
49
UnversionedParent('Versioned directory', u'p\xe5thf', '\xc3\xaedf'),
53
class TestConflicts(TestCaseWithTransport):
27
class TestConflicts(TestCaseInTempDir):
55
29
def test_conflicts(self):
56
30
"""Conflicts are detected properly"""
57
tree = self.make_branch_and_tree('.',
58
format=bzrdir.BzrDirFormat6())
60
file('hello', 'w').write('hello world4')
61
file('hello.THIS', 'w').write('hello world2')
62
file('hello.BASE', 'w').write('hello world1')
63
file('hello.OTHER', 'w').write('hello world3')
31
b = Branch.initialize('.')
32
file('hello', 'w').write('hello world')
33
file('hello.BASE', 'w').write('hello world')
64
34
file('hello.sploo.BASE', 'w').write('yellow world')
65
file('hello.sploo.OTHER', 'w').write('yellow world2')
67
self.assertEqual(len(list(tree.list_files())), 6)
69
conflicts = tree.conflicts()
35
tree = b.working_tree()
36
self.assertEqual(len(list(tree.list_files())), 3)
37
conflicts = list(tree.iter_conflicts())
70
38
self.assertEqual(len(conflicts), 2)
71
self.assert_('hello' in conflicts[0].path)
72
self.assert_('hello.sploo' in conflicts[1].path)
74
restore('hello.sploo')
75
self.assertEqual(len(tree.conflicts()), 0)
76
self.assertFileEqual('hello world2', 'hello')
77
assert not os.path.lexists('hello.sploo')
78
self.assertRaises(NotConflicted, restore, 'hello')
79
self.assertRaises(NotConflicted, restore, 'hello.sploo')
81
def test_resolve_conflict_dir(self):
82
tree = self.make_branch_and_tree('.')
84
file('hello', 'w').write('hello world4')
85
tree.add('hello', 'q')
86
file('hello.THIS', 'w').write('hello world2')
87
file('hello.BASE', 'w').write('hello world1')
88
os.mkdir('hello.OTHER')
89
l = ConflictList([TextConflict('hello')])
93
class TestConflictStanzas(TestCase):
95
def test_stanza_roundtrip(self):
96
# write and read our example stanza.
97
stanza_iter = example_conflicts.to_stanzas()
98
processed = ConflictList.from_stanzas(stanza_iter)
99
for o, p in zip(processed, example_conflicts):
100
self.assertEqual(o, p)
102
self.assertIsInstance(o.path, unicode)
104
if o.file_id is not None:
105
self.assertIsInstance(o.file_id, str)
107
conflict_path = getattr(o, 'conflict_path', None)
108
if conflict_path is not None:
109
self.assertIsInstance(conflict_path, unicode)
111
conflict_file_id = getattr(o, 'conflict_file_id', None)
112
if conflict_file_id is not None:
113
self.assertIsInstance(conflict_file_id, str)
115
def test_stanzification(self):
116
for stanza in example_conflicts.to_stanzas():
117
if 'file_id' in stanza:
118
# In Stanza form, the file_id has to be unicode.
119
self.assertStartsWith(stanza['file_id'], u'\xeed')
120
self.assertStartsWith(stanza['path'], u'p\xe5th')
121
if 'conflict_path' in stanza:
122
self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
123
if 'conflict_file_id' in stanza:
124
self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
39
assert 'hello' in conflicts
40
assert 'hello.sploo' in conflicts
41
os.unlink('hello.BASE')
42
os.unlink('hello.sploo.BASE')
43
self.assertEqual(len(list(tree.iter_conflicts())), 0)