~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-11-08 13:45:51 UTC
  • mfrom: (5532.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20101108134551-sxvk77ehmegkrwmm
(vila) Fix news entry

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
 
 
51
 
 
52
 
class TestConflicts(script.TestCaseWithTransportAndScript):
 
24
 
 
25
# FIXME: These don't really look at the output of the conflict commands, just
 
26
# the number of lines - there should be more examination.
 
27
 
 
28
class TestConflictsBase(tests.TestCaseWithTransport):
53
29
 
54
30
    def setUp(self):
55
 
        super(TestConflicts, self).setUp()
56
 
        make_tree_with_conflicts(self, 'branch', 'other')
 
31
        super(TestConflictsBase, self).setUp()
 
32
        self.make_tree_with_conflicts()
 
33
 
 
34
    def make_tree_with_conflicts(self):
 
35
        a_tree = self.make_branch_and_tree('a')
 
36
        self.build_tree_contents([
 
37
            ('a/myfile', 'contentsa\n'),
 
38
            ('a/my_other_file', 'contentsa\n'),
 
39
            ('a/mydir/',),
 
40
            ])
 
41
        a_tree.add('myfile')
 
42
        a_tree.add('my_other_file')
 
43
        a_tree.add('mydir')
 
44
        a_tree.commit(message="new")
 
45
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
46
        self.build_tree_contents([
 
47
            ('b/myfile', 'contentsb\n'),
 
48
            ('b/my_other_file', 'contentsb\n'),
 
49
            ])
 
50
        b_tree.rename_one('mydir', 'mydir2')
 
51
        b_tree.commit(message="change")
 
52
        self.build_tree_contents([
 
53
            ('a/myfile', 'contentsa2\n'),
 
54
            ('a/my_other_file', 'contentsa2\n'),
 
55
            ])
 
56
        a_tree.rename_one('mydir', 'mydir3')
 
57
        a_tree.commit(message='change')
 
58
        a_tree.merge_from_branch(b_tree.branch)
 
59
 
 
60
    def run_bzr(self, cmd, working_dir='a', **kwargs):
 
61
        return super(TestConflictsBase, self).run_bzr(
 
62
            cmd, working_dir=working_dir, **kwargs)
 
63
 
 
64
 
 
65
class TestConflicts(TestConflictsBase):
57
66
 
58
67
    def test_conflicts(self):
59
 
        self.run_script("""\
60
 
$ cd branch
61
 
$ bzr conflicts
62
 
Text conflict in my_other_file
63
 
Path conflict: mydir3 / mydir2
64
 
Text conflict in myfile
65
 
""")
 
68
        out, err = self.run_bzr('conflicts')
 
69
        self.assertEqual(3, len(out.splitlines()))
66
70
 
67
71
    def test_conflicts_text(self):
68
 
        self.run_script("""\
69
 
$ cd branch
70
 
$ bzr conflicts --text
71
 
my_other_file
72
 
myfile
73
 
""")
 
72
        out, err = self.run_bzr('conflicts --text')
 
73
        self.assertEqual(['my_other_file', 'myfile'], out.splitlines())
74
74
 
75
75
    def test_conflicts_directory(self):
 
76
        """Test --directory option"""
 
77
        out, err = self.run_bzr('conflicts --directory a', working_dir='.')
 
78
        self.assertEqual(3, len(out.splitlines()))
 
79
        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):
76
140
        self.run_script("""\
77
 
$ bzr conflicts  -d branch
78
 
Text conflict in my_other_file
79
 
Path conflict: mydir3 / mydir2
80
 
Text conflict in myfile
81
 
""")
 
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