22
22
from bzrlib.tests import script
24
def make_tree_with_conflicts(test, this_path='this', other_path='other'):
25
this_tree = test.make_branch_and_tree(this_path)
26
test.build_tree_contents([
27
('%s/myfile' % (this_path,), 'this content\n'),
28
('%s/my_other_file' % (this_path,), 'this content\n'),
29
('%s/mydir/' % (this_path,),),
31
this_tree.add('myfile')
32
this_tree.add('my_other_file')
33
this_tree.add('mydir')
34
this_tree.commit(message="new")
35
other_tree = this_tree.bzrdir.sprout(other_path).open_workingtree()
36
test.build_tree_contents([
37
('%s/myfile' % (other_path,), 'contentsb\n'),
38
('%s/my_other_file' % (other_path,), 'contentsb\n'),
40
other_tree.rename_one('mydir', 'mydir2')
41
other_tree.commit(message="change")
42
test.build_tree_contents([
43
('%s/myfile' % (this_path,), 'contentsa2\n'),
44
('%s/my_other_file' % (this_path,), 'contentsa2\n'),
46
this_tree.rename_one('mydir', 'mydir3')
47
this_tree.commit(message='change')
48
this_tree.merge_from_branch(other_tree.branch)
49
return this_tree, other_tree
25
52
# FIXME: These don't really look at the output of the conflict commands, just
26
53
# the number of lines - there should be more examination.
77
104
out, err = self.run_bzr('conflicts --directory a', working_dir='.')
78
105
self.assertEqual(3, len(out.splitlines()))
79
106
self.assertEqual('', err)
82
class TestResolve(TestConflictsBase):
84
def test_resolve(self):
85
self.run_bzr('resolve myfile')
86
out, err = self.run_bzr('conflicts')
87
self.assertEqual(2, len(out.splitlines()))
88
self.run_bzr('resolve my_other_file')
89
self.run_bzr('resolve mydir2')
90
out, err = self.run_bzr('conflicts')
91
self.assertEqual(0, len(out.splitlines()))
93
def test_resolve_all(self):
94
self.run_bzr('resolve --all')
95
out, err = self.run_bzr('conflicts')
96
self.assertEqual(0, len(out.splitlines()))
98
def test_resolve_in_subdir(self):
99
"""resolve when run from subdirectory should handle relative paths"""
100
self.build_tree(["a/subdir/"])
101
self.run_bzr("resolve ../myfile", working_dir='a/subdir')
102
self.run_bzr("resolve ../a/myfile", working_dir='b')
103
wt = workingtree.WorkingTree.open_containing('b')[0]
104
conflicts = wt.conflicts()
105
self.assertEqual(True, conflicts.is_empty(),
106
"tree still contains conflicts: %r" % conflicts)
108
def test_resolve_via_directory(self):
109
"""resolve when run from subdirectory should handle relative paths"""
110
self.build_tree(["a/subdir/"])
111
self.run_bzr("resolve -d a/subdir ../myfile")
113
def test_auto_resolve(self):
114
"""Text conflicts can be resolved automatically"""
115
tree = self.make_branch_and_tree('tree')
116
self.build_tree_contents([('tree/file',
117
'<<<<<<<\na\n=======\n>>>>>>>\n')])
118
tree.add('file', 'file_id')
119
self.assertEqual(tree.kind('file_id'), 'file')
120
file_conflict = conflicts.TextConflict('file', file_id='file_id')
121
tree.set_conflicts(conflicts.ConflictList([file_conflict]))
122
note = self.run_bzr('resolve', retcode=1, working_dir='tree')[1]
123
self.assertContainsRe(note, '0 conflict\\(s\\) auto-resolved.')
124
self.assertContainsRe(note,
125
'Remaining conflicts:\nText conflict in file')
126
self.build_tree_contents([('tree/file', 'a\n')])
127
note = self.run_bzr('resolve', working_dir='tree')[1]
128
self.assertContainsRe(note, 'All conflicts resolved.')
130
def test_resolve_all_directory(self):
131
"""Test --directory option"""
132
out, err = self.run_bzr('resolve --all -d a', working_dir='.')
133
self.assertEqual('', err)
134
out, err = self.run_bzr('conflicts')
135
self.assertEqual(0, len(out.splitlines()))
137
class TestResolveSilentlyIgnore(script.TestCaseWithTransportAndScript):
139
def test_bug_646961(self):
142
Created a standalone tree (format: 2a)
148
2>Committing to: .../base/
150
2>Committed revision 1.
152
$ bzr branch base branch
153
2>Branched 1 revision(s).
156
$ bzr ci -m "branch 1"
157
2>Committing to: .../base/
159
2>Committed revision 2.
162
$ bzr ci -m "branch 2"
163
2>Committing to: .../branch/
165
2>Committed revision 2.
167
$ bzr merge ../branch
169
2>Text conflict in file1
170
2>1 conflicts encountered.
171
# The following succeeds silently without resolving the conflict
172
$ bzr resolve file1 --take-other
173
# The following wil fail when --take-other is implemented
176
Text conflict in file1