~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_resolve.py

Merge bzr.dev to resolve news conflict

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
from bzrlib import (
 
18
    conflicts,
 
19
    tests,
 
20
    )
 
21
from bzrlib.tests import script
 
22
from bzrlib.tests.blackbox import test_conflicts
 
23
 
 
24
 
 
25
class TestResolve(script.TestCaseWithTransportAndScript):
 
26
 
 
27
    def setUp(self):
 
28
        super(TestResolve, self).setUp()
 
29
        test_conflicts.make_tree_with_conflicts(self, 'branch', 'other')
 
30
 
 
31
    def test_resolve_one_by_one(self):
 
32
        self.run_script("""\
 
33
$ cd branch
 
34
$ bzr conflicts
 
35
Text conflict in my_other_file
 
36
Path conflict: mydir3 / mydir2
 
37
Text conflict in myfile
 
38
$ bzr resolve myfile
 
39
2>1 conflict(s) resolved, 2 remaining
 
40
$ bzr resolve my_other_file
 
41
2>1 conflict(s) resolved, 1 remaining
 
42
$ bzr resolve mydir2
 
43
2>1 conflict(s) resolved, 0 remaining
 
44
""")
 
45
 
 
46
    def test_resolve_all(self):
 
47
        self.run_script("""\
 
48
$ cd branch
 
49
$ bzr resolve --all
 
50
2>3 conflict(s) resolved, 0 remaining
 
51
$ bzr conflicts
 
52
""")
 
53
 
 
54
    def test_resolve_from_subdir(self):
 
55
        self.run_script("""\
 
56
$ mkdir branch/subdir
 
57
$ cd branch/subdir
 
58
$ bzr resolve ../myfile
 
59
2>1 conflict(s) resolved, 2 remaining
 
60
""")
 
61
 
 
62
    def test_resolve_via_directory_option(self):
 
63
        self.run_script("""\
 
64
$ bzr resolve -d branch myfile
 
65
2>1 conflict(s) resolved, 2 remaining
 
66
""")
 
67
 
 
68
    def test_resolve_all_via_directory_option(self):
 
69
        self.run_script("""\
 
70
$ bzr resolve -d branch --all
 
71
2>3 conflict(s) resolved, 0 remaining
 
72
$ bzr conflicts -d branch
 
73
""")
 
74
 
 
75
 
 
76
class TestResolveAuto(tests.TestCaseWithTransport):
 
77
 
 
78
    def test_auto_resolve(self):
 
79
        """Text conflicts can be resolved automatically"""
 
80
        tree = self.make_branch_and_tree('tree')
 
81
        self.build_tree_contents([('tree/file',
 
82
            '<<<<<<<\na\n=======\n>>>>>>>\n')])
 
83
        tree.add('file', 'file_id')
 
84
        self.assertEqual(tree.kind('file_id'), 'file')
 
85
        file_conflict = conflicts.TextConflict('file', file_id='file_id')
 
86
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
 
87
        note = self.run_bzr('resolve', retcode=1, working_dir='tree')[1]
 
88
        self.assertContainsRe(note, '0 conflict\\(s\\) auto-resolved.')
 
89
        self.assertContainsRe(note,
 
90
            'Remaining conflicts:\nText conflict in file')
 
91
        self.build_tree_contents([('tree/file', 'a\n')])
 
92
        note = self.run_bzr('resolve', working_dir='tree')[1]
 
93
        self.assertContainsRe(note, 'All conflicts resolved.')
 
94
 
 
95
 
 
96
class TestResolveSilentlyIgnore(script.TestCaseWithTransportAndScript):
 
97
 
 
98
    def test_bug_646961(self):
 
99
        self.run_script("""\
 
100
            $ bzr init base
 
101
            Created a standalone tree (format: 2a)
 
102
            $ cd base
 
103
            $ echo >file1
 
104
            $ bzr add
 
105
            adding file1
 
106
            $ bzr ci -m "stuff"
 
107
            2>Committing to: .../base/
 
108
            2>added file1
 
109
            2>Committed revision 1.
 
110
            $ cd ..
 
111
            $ bzr branch base branch
 
112
            2>Branched 1 revision(s).
 
113
            $ cd base
 
114
            $ echo "1" >> file1
 
115
            $ bzr ci -m "branch 1"
 
116
            2>Committing to: .../base/
 
117
            2>modified file1
 
118
            2>Committed revision 2.
 
119
            $ cd ../branch
 
120
            $ echo "2" >> file1
 
121
            $ bzr ci -m "branch 2"
 
122
            2>Committing to: .../branch/
 
123
            2>modified file1
 
124
            2>Committed revision 2.
 
125
            $ cd ../base
 
126
            $ bzr merge ../branch
 
127
            2> M  file1
 
128
            2>Text conflict in file1
 
129
            2>1 conflicts encountered.
 
130
            # The following succeeds silently without resolving the conflict
 
131
            $ bzr resolve file1 --take-other
 
132
            2>0 conflict(s) resolved, 1 remaining
 
133
            # The following wil fail when --take-other is implemented
 
134
            # for text conflicts
 
135
            $ bzr conflicts
 
136
            Text conflict in file1
 
137
            """)
 
138