~bzr-pqm/bzr/bzr.dev

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
# Copyright (C) 2010 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

from bzrlib import (
    conflicts,
    tests,
    )
from bzrlib.tests import script
from bzrlib.tests.blackbox import test_conflicts


class TestResolve(script.TestCaseWithTransportAndScript):

    def setUp(self):
        super(TestResolve, self).setUp()
        test_conflicts.make_tree_with_conflicts(self, 'branch', 'other')

    def test_resolve_one_by_one(self):
        self.run_script("""\
$ cd branch
$ bzr conflicts
Text conflict in my_other_file
Path conflict: mydir3 / mydir2
Text conflict in myfile
$ bzr resolve myfile
2>1 conflict(s) resolved, 2 remaining
$ bzr resolve my_other_file
2>1 conflict(s) resolved, 1 remaining
$ bzr resolve mydir2
2>1 conflict(s) resolved, 0 remaining
""")

    def test_resolve_all(self):
        self.run_script("""\
$ cd branch
$ bzr resolve --all
2>3 conflict(s) resolved, 0 remaining
$ bzr conflicts
""")

    def test_resolve_from_subdir(self):
        self.run_script("""\
$ mkdir branch/subdir
$ cd branch/subdir
$ bzr resolve ../myfile
2>1 conflict(s) resolved, 2 remaining
""")

    def test_resolve_via_directory_option(self):
        self.run_script("""\
$ bzr resolve -d branch myfile
2>1 conflict(s) resolved, 2 remaining
""")

    def test_resolve_all_via_directory_option(self):
        self.run_script("""\
$ bzr resolve -d branch --all
2>3 conflict(s) resolved, 0 remaining
$ bzr conflicts -d branch
""")


class TestResolveAuto(tests.TestCaseWithTransport):

    def test_auto_resolve(self):
        """Text conflicts can be resolved automatically"""
        tree = self.make_branch_and_tree('tree')
        self.build_tree_contents([('tree/file',
            '<<<<<<<\na\n=======\n>>>>>>>\n')])
        tree.add('file', 'file_id')
        self.assertEqual(tree.kind('file_id'), 'file')
        file_conflict = conflicts.TextConflict('file', file_id='file_id')
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
        note = self.run_bzr('resolve', retcode=1, working_dir='tree')[1]
        self.assertContainsRe(note, '0 conflict\\(s\\) auto-resolved.')
        self.assertContainsRe(note,
            'Remaining conflicts:\nText conflict in file')
        self.build_tree_contents([('tree/file', 'a\n')])
        note = self.run_bzr('resolve', working_dir='tree')[1]
        self.assertContainsRe(note, 'All conflicts resolved.')


class TestResolveSilentlyIgnore(script.TestCaseWithTransportAndScript):

    def test_bug_646961(self):
        self.run_script("""\
            $ bzr init base
            Created a standalone tree (format: 2a)
            $ cd base
            $ echo >file1
            $ bzr add
            adding file1
            $ bzr ci -m "stuff"
            2>Committing to: .../base/
            2>added file1
            2>Committed revision 1.
            $ cd ..
            $ bzr branch base branch
            2>Branched 1 revision(s).
            $ cd base
            $ echo "1" >> file1
            $ bzr ci -m "branch 1"
            2>Committing to: .../base/
            2>modified file1
            2>Committed revision 2.
            $ cd ../branch
            $ echo "2" >> file1
            $ bzr ci -m "branch 2"
            2>Committing to: .../branch/
            2>modified file1
            2>Committed revision 2.
            $ cd ../base
            $ bzr merge ../branch
            2> M  file1
            2>Text conflict in file1
            2>1 conflicts encountered.
            # The following succeeds silently without resolving the conflict
            $ bzr resolve file1 --take-other
            2>0 conflict(s) resolved, 1 remaining
            # The following wil fail when --take-other is implemented
            # for text conflicts
            $ bzr conflicts
            Text conflict in file1
            """)