1
# Copyright (C) 2010, 2011 Canonical Ltd
 
 
3
# This program is free software; you can redistribute it and/or modify
 
 
4
# it under the terms of the GNU General Public License as published by
 
 
5
# the Free Software Foundation; either version 2 of the License, or
 
 
6
# (at your option) any later version.
 
 
8
# This program is distributed in the hope that it will be useful,
 
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 
11
# GNU General Public License for more details.
 
 
13
# You should have received a copy of the GNU General Public License
 
 
14
# along with this program; if not, write to the Free Software
 
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 
21
from breezy.tests import (
 
 
25
from breezy.tests.blackbox import test_conflicts
 
 
28
class TestResolve(script.TestCaseWithTransportAndScript):
 
 
31
        super(TestResolve, self).setUp()
 
 
32
        test_conflicts.make_tree_with_conflicts(self, 'branch', 'other')
 
 
34
    def test_resolve_one_by_one(self):
 
 
38
Text conflict in my_other_file
 
 
39
Path conflict: mydir3 / mydir2
 
 
40
Text conflict in myfile
 
 
42
2>1 conflict resolved, 2 remaining
 
 
43
$ brz resolve my_other_file
 
 
44
2>1 conflict resolved, 1 remaining
 
 
46
2>1 conflict resolved, 0 remaining
 
 
49
    def test_resolve_all(self):
 
 
53
2>3 conflicts resolved, 0 remaining
 
 
57
    def test_resolve_from_subdir(self):
 
 
61
$ brz resolve ../myfile
 
 
62
2>1 conflict resolved, 2 remaining
 
 
65
    def test_resolve_via_directory_option(self):
 
 
67
$ brz resolve -d branch myfile
 
 
68
2>1 conflict resolved, 2 remaining
 
 
71
    def test_resolve_all_via_directory_option(self):
 
 
73
$ brz resolve -d branch --all
 
 
74
2>3 conflicts resolved, 0 remaining
 
 
75
$ brz conflicts -d branch
 
 
78
    def test_bug_842575_manual_rm(self):
 
 
81
$ echo original > trunk/foo
 
 
82
$ brz add -q trunk/foo
 
 
83
$ brz commit -q -m first trunk
 
 
84
$ brz checkout -q trunk tree
 
 
86
$ brz commit -q -m second trunk
 
 
87
$ echo modified > tree/foo
 
 
90
2>Contents conflict in foo
 
 
91
2>1 conflicts encountered.
 
 
92
2>Updated to revision 2 of branch ...
 
 
93
$ rm tree/foo.BASE tree/foo.THIS
 
 
94
$ brz resolve --all -d tree
 
 
95
2>1 conflict resolved, 0 remaining
 
 
101
        except AssertionError:
 
 
102
            raise KnownFailure("bug #842575")
 
 
104
    def test_bug_842575_take_other(self):
 
 
107
$ echo original > trunk/foo
 
 
108
$ brz add -q trunk/foo
 
 
109
$ brz commit -q -m first trunk
 
 
110
$ brz checkout -q --lightweight trunk tree
 
 
111
$ brz rm -q trunk/foo
 
 
112
$ brz ignore -d trunk foo
 
 
113
$ brz commit -q -m second trunk
 
 
114
$ echo modified > tree/foo
 
 
118
2>Contents conflict in foo
 
 
119
2>1 conflicts encountered.
 
 
120
2>Updated to revision 2 of branch ...
 
 
121
$ brz resolve --take-other --all -d tree
 
 
122
2>1 conflict resolved, 0 remaining
 
 
127
$ echo mustignore > tree/foo
 
 
130
        except AssertionError:
 
 
131
            raise KnownFailure("bug 842575")
 
 
134
class TestBug788000(script.TestCaseWithTransportAndScript):
 
 
136
    def test_bug_788000(self):
 
 
140
$ echo foo > a/dir/file
 
 
146
$ echo bar > b/dir/file
 
 
152
                        null_output_matches_anything=True)
 
 
156
Using saved parent location:...
 
 
158
2>RM  dir/file => dir/file.THIS
 
 
159
2>Conflict: can't delete dir because it is not empty.  Not deleting.
 
 
160
2>Conflict because dir is not versioned, but has versioned children...
 
 
161
2>Contents conflict in dir/file
 
 
162
2>3 conflicts encountered.
 
 
165
$ brz resolve --take-other
 
 
166
2>deleted dir/file.THIS
 
 
168
2>3 conflicts resolved, 0 remaining
 
 
172
class TestResolveAuto(tests.TestCaseWithTransport):
 
 
174
    def test_auto_resolve(self):
 
 
175
        """Text conflicts can be resolved automatically"""
 
 
176
        tree = self.make_branch_and_tree('tree')
 
 
177
        self.build_tree_contents([('tree/file',
 
 
178
            b'<<<<<<<\na\n=======\n>>>>>>>\n')])
 
 
179
        tree.add('file', 'file_id')
 
 
180
        self.assertEqual(tree.kind('file', 'file_id'), 'file')
 
 
181
        file_conflict = conflicts.TextConflict('file', file_id='file_id')
 
 
182
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
 
 
183
        note = self.run_bzr('resolve', retcode=1, working_dir='tree')[1]
 
 
184
        self.assertContainsRe(note, '0 conflicts auto-resolved.')
 
 
185
        self.assertContainsRe(note,
 
 
186
            'Remaining conflicts:\nText conflict in file')
 
 
187
        self.build_tree_contents([('tree/file', b'a\n')])
 
 
188
        note = self.run_bzr('resolve', working_dir='tree')[1]
 
 
189
        self.assertContainsRe(note, 'All conflicts resolved.')