~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2010-11-07 16:09:43 UTC
  • mto: (4597.14.1 638451-malformed)
  • mto: This revision was merged to the branch mainline in revision 5537.
  • Revision ID: v.ladeuil+lp@free.fr-20101107160943-qkz45h4pb748117i
resolve now reports conflicts resolved/remaining.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    )
22
22
from bzrlib.tests import script
23
23
 
 
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,),),
 
30
        ])
 
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'),
 
39
        ])
 
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'),
 
45
        ])
 
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
 
50
 
24
51
 
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)
80
 
 
81
 
 
82
 
class TestResolve(TestConflictsBase):
83
 
 
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()))
92
 
 
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()))
97
 
 
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)
107
 
 
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")
112
 
 
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.')
129
 
 
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()))
136
 
 
137
 
class TestResolveSilentlyIgnore(script.TestCaseWithTransportAndScript):
138
 
 
139
 
    def test_bug_646961(self):
140
 
        self.run_script("""\
141
 
            $ bzr init base
142
 
            Created a standalone tree (format: 2a)
143
 
            $ cd base
144
 
            $ echo >file1
145
 
            $ bzr add
146
 
            adding file1
147
 
            $ bzr ci -m "stuff"
148
 
            2>Committing to: .../base/
149
 
            2>added file1
150
 
            2>Committed revision 1.
151
 
            $ cd ..
152
 
            $ bzr branch base branch
153
 
            2>Branched 1 revision(s).
154
 
            $ cd base
155
 
            $ echo "1" >> file1
156
 
            $ bzr ci -m "branch 1"
157
 
            2>Committing to: .../base/
158
 
            2>modified file1
159
 
            2>Committed revision 2.
160
 
            $ cd ../branch
161
 
            $ echo "2" >> file1
162
 
            $ bzr ci -m "branch 2"
163
 
            2>Committing to: .../branch/
164
 
            2>modified file1
165
 
            2>Committed revision 2.
166
 
            $ cd ../base
167
 
            $ bzr merge ../branch
168
 
            2> M  file1
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
174
 
            # for text conflicts
175
 
            $ bzr conflicts
176
 
            Text conflict in file1
177
 
            """)
178