1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
from bzrlib import bzrdir
20
21
from bzrlib.tests import TestCaseWithTransport, TestCase
21
22
from bzrlib.branch import Branch
22
from bzrlib.conflicts import *
23
from bzrlib.conflicts import (MissingParent, ContentsConflict, TextConflict,
24
PathConflict, DuplicateID, DuplicateEntry, ParentLoop, UnversionedParent,
23
27
from bzrlib.errors import NotConflicted
29
33
# The order of 'path' here is important - do not let it
30
34
# be a sorted list.
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?)
31
38
example_conflicts = ConflictList([
32
MissingParent('Not deleting', 'pathg', 'idg'),
33
ContentsConflict('patha', 'ida'),
34
TextConflict('patha'),
35
PathConflict('pathb', 'pathc', 'idb'),
36
DuplicateID('Unversioned existing file', 'pathc', 'pathc2', 'idc', 'idc'),
37
DuplicateEntry('Moved existing file to', 'pathdd.moved', 'pathd', 'idd',
39
ParentLoop('Cancelled move', 'pathe', 'path2e', None, 'id2e'),
40
UnversionedParent('Versioned directory', 'pathf', 'idf'),
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'),
46
55
def test_conflicts(self):
47
56
"""Conflicts are detected properly"""
48
57
tree = self.make_branch_and_tree('.',
49
format=bzrlib.bzrdir.BzrDirFormat6())
58
format=bzrdir.BzrDirFormat6())
51
60
file('hello', 'w').write('hello world4')
52
61
file('hello.THIS', 'w').write('hello world2')
54
63
file('hello.OTHER', 'w').write('hello world3')
55
64
file('hello.sploo.BASE', 'w').write('yellow world')
56
65
file('hello.sploo.OTHER', 'w').write('yellow world2')
57
67
self.assertEqual(len(list(tree.list_files())), 6)
58
69
conflicts = tree.conflicts()
59
70
self.assertEqual(len(conflicts), 2)
60
71
self.assert_('hello' in conflicts[0].path)
85
96
# write and read our example stanza.
86
97
stanza_iter = example_conflicts.to_stanzas()
87
98
processed = ConflictList.from_stanzas(stanza_iter)
88
for o,p in zip(processed, example_conflicts):
99
for o, p in zip(processed, example_conflicts):
89
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)
91
115
def test_stanzification(self):
92
116
for stanza in example_conflicts.to_stanzas():
94
self.assertStartsWith(stanza['file_id'], 'id')
97
self.assertStartsWith(stanza['path'], 'path')
99
self.assertStartsWith(stanza['conflict_file_id'], 'id')
100
self.assertStartsWith(stanza['conflict_file_path'], 'path')
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')