/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2279.3.1 by mbp at sourcefrog
Add a -d option to push, pull, merge (ported from tags branch)
1
# Copyright (C) 2006, 2007 Canonical Ltd
1551.6.16 by Aaron Bentley
Merge from bzr.dev
2
#
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
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.
1551.6.16 by Aaron Bentley
Merge from bzr.dev
7
#
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
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.
1551.6.16 by Aaron Bentley
Merge from bzr.dev
12
#
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1551.6.16 by Aaron Bentley
Merge from bzr.dev
16
#
17
# Author: Aaron Bentley <aaron.bentley@utoronto.ca>
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
18
19
"""Black-box tests for bzr merge.
20
"""
21
22
import os
23
2520.4.109 by Aaron Bentley
start work on directive cherry-picking
24
from bzrlib import merge_directive
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
25
from bzrlib.branch import Branch
1551.6.16 by Aaron Bentley
Merge from bzr.dev
26
from bzrlib.bzrdir import BzrDir
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
27
from bzrlib.conflicts import ConflictList, ContentsConflict
28
from bzrlib.osutils import abspath, file_kind
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
29
from bzrlib.tests.blackbox import ExternalBase
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
30
import bzrlib.urlutils as urlutils
1551.6.16 by Aaron Bentley
Merge from bzr.dev
31
from bzrlib.workingtree import WorkingTree
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
32
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
33
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
34
class TestMerge(ExternalBase):
35
1551.6.16 by Aaron Bentley
Merge from bzr.dev
36
    def example_branch(test):
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
37
        test.run_bzr('init')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
38
        file('hello', 'wt').write('foo')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
39
        test.run_bzr('add hello')
40
        test.run_bzr('commit -m setup hello')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
41
        file('goodbye', 'wt').write('baz')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
42
        test.run_bzr('add goodbye')
43
        test.run_bzr('commit -m setup goodbye')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
44
45
    def test_merge_reprocess(self):
46
        d = BzrDir.create_standalone_workingtree('.')
47
        d.commit('h')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
48
        self.run_bzr('merge . --reprocess --merge-type weave')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
49
50
    def test_merge(self):
51
        from bzrlib.branch import Branch
52
        
53
        os.mkdir('a')
54
        os.chdir('a')
55
        self.example_branch()
1907.4.4 by Matthieu Moy
Explain the error messages in the code.
56
        ancestor = Branch.open('.').revno()
1551.6.16 by Aaron Bentley
Merge from bzr.dev
57
        os.chdir('..')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
58
        self.run_bzr('branch a b')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
59
        os.chdir('b')
60
        file('goodbye', 'wt').write('quux')
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
61
        self.run_bzr(['commit',  '-m',  "more u's are always good"])
1551.6.16 by Aaron Bentley
Merge from bzr.dev
62
63
        os.chdir('../a')
64
        file('hello', 'wt').write('quuux')
65
        # We can't merge when there are in-tree changes
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
66
        self.run_bzr('merge ../b', retcode=3)
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
67
        a = WorkingTree.open('.')
68
        a_tip = a.commit("Like an epidemic of u's")
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
69
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type blooof',
1551.6.16 by Aaron Bentley
Merge from bzr.dev
70
                    retcode=3)
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
71
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type merge3')
72
        self.run_bzr('revert --no-backup')
73
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type weave')
74
        self.run_bzr('revert --no-backup')
2665.2.1 by Michael Hudson
test and fix for a NameError in merge --weave --show-base
75
        self.run_bzr_error(['Show-base is not supported for this merge type'],
76
                           'merge ../b -r last:1..last:1 --merge-type weave'
77
                           ' --show-base')
78
        self.run_bzr('revert --no-backup')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
79
        self.run_bzr('merge ../b -r last:1..last:1 --reprocess')
80
        self.run_bzr('revert --no-backup')
81
        self.run_bzr('merge ../b -r last:1')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
82
        self.check_file_contents('goodbye', 'quux')
83
        # Merging a branch pulls its revision into the tree
84
        b = Branch.open('../b')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
85
        b_tip = b.last_revision()
86
        self.failUnless(a.branch.repository.has_revision(b_tip))
87
        self.assertEqual([a_tip, b_tip], a.get_parent_ids())
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
88
        self.run_bzr('revert --no-backup')
89
        out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3)
1907.4.13 by Matthieu Moy
Better testcase for revno:N:branch/path error.
90
        self.assertTrue("Not a branch" in err)
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
91
        self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
1907.4.12 by Matthieu Moy
Made merge work with two revisions in different branches.
92
                    %(ancestor,b.revno()))
1551.8.25 by Aaron Bentley
Fix deprecated use of pending_merges
93
        self.assertEquals(a.get_parent_ids(), 
94
                          [a.branch.last_revision(), b.last_revision()])
1907.4.12 by Matthieu Moy
Made merge work with two revisions in different branches.
95
        self.check_file_contents('goodbye', 'quux')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
96
        self.run_bzr('revert --no-backup')
97
        self.run_bzr('merge -r revno:%d:../b'%b.revno())
1551.8.25 by Aaron Bentley
Fix deprecated use of pending_merges
98
        self.assertEquals(a.get_parent_ids(),
99
                          [a.branch.last_revision(), b.last_revision()])
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
100
        a_tip = a.commit('merged')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
101
        self.run_bzr('merge ../b -r last:1')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
102
        self.assertEqual([a_tip], a.get_parent_ids())
1551.6.16 by Aaron Bentley
Merge from bzr.dev
103
104
    def test_merge_with_missing_file(self):
105
        """Merge handles missing file conflicts"""
106
        os.mkdir('a')
107
        os.chdir('a')
108
        os.mkdir('sub')
109
        print >> file('sub/a.txt', 'wb'), "hello"
110
        print >> file('b.txt', 'wb'), "hello"
111
        print >> file('sub/c.txt', 'wb'), "hello"
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
112
        self.run_bzr('init')
113
        self.run_bzr('add')
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
114
        self.run_bzr(['commit', '-m', 'added a'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
115
        self.run_bzr('branch . ../b')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
116
        print >> file('sub/a.txt', 'ab'), "there"
117
        print >> file('b.txt', 'ab'), "there"
118
        print >> file('sub/c.txt', 'ab'), "there"
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
119
        self.run_bzr(['commit', '-m', 'Added there'])
1551.6.16 by Aaron Bentley
Merge from bzr.dev
120
        os.unlink('sub/a.txt')
121
        os.unlink('sub/c.txt')
122
        os.rmdir('sub')
123
        os.unlink('b.txt')
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
124
        self.run_bzr(['commit', '-m', 'Removed a.txt'])
1551.6.16 by Aaron Bentley
Merge from bzr.dev
125
        os.chdir('../b')
126
        print >> file('sub/a.txt', 'ab'), "something"
127
        print >> file('b.txt', 'ab'), "something"
128
        print >> file('sub/c.txt', 'ab'), "something"
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
129
        self.run_bzr(['commit', '-m', 'Modified a.txt'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
130
        self.run_bzr('merge ../a/', retcode=1)
1551.6.16 by Aaron Bentley
Merge from bzr.dev
131
        self.assert_(os.path.exists('sub/a.txt.THIS'))
132
        self.assert_(os.path.exists('sub/a.txt.BASE'))
133
        os.chdir('../a')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
134
        self.run_bzr('merge ../b/', retcode=1)
1551.6.16 by Aaron Bentley
Merge from bzr.dev
135
        self.assert_(os.path.exists('sub/a.txt.OTHER'))
136
        self.assert_(os.path.exists('sub/a.txt.BASE'))
137
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
138
    def test_merge_remember(self):
139
        """Merge changes from one branch to another and test parent location."""
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
140
        tree_a = self.make_branch_and_tree('branch_a')
141
        branch_a = tree_a.branch
142
        self.build_tree(['branch_a/a'])
143
        tree_a.add('a')
144
        tree_a.commit('commit a')
145
        branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
146
        tree_b = branch_b.bzrdir.open_workingtree()
147
        branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
148
        tree_c = branch_c.bzrdir.open_workingtree()
149
        self.build_tree(['branch_a/b'])
150
        tree_a.add('b')
151
        tree_a.commit('commit b')
152
        self.build_tree(['branch_c/c'])
153
        tree_c.add('c')
154
        tree_c.commit('commit c')
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
155
        # reset parent
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
156
        parent = branch_b.get_parent()
157
        branch_b.set_parent(None)
158
        self.assertEqual(None, branch_b.get_parent())
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
159
        # test merge for failure without parent set
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
160
        os.chdir('branch_b')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
161
        out = self.run_bzr('merge', retcode=3)
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
162
        self.assertEquals(out,
1685.1.59 by Martin Pool
[broken] Fix up & refactor display of remembered urls to unescape properly
163
                ('','bzr: ERROR: No location specified or remembered\n'))
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
164
        # test implicit --remember when no parent set, this merge conflicts
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
165
        self.build_tree(['d'])
166
        tree_b.add('d')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
167
        out = self.run_bzr('merge ../branch_a', retcode=3)
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
168
        self.assertEquals(out,
169
                ('','bzr: ERROR: Working tree has uncommitted changes.\n'))
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
170
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
171
        # test implicit --remember after resolving conflict
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
172
        tree_b.commit('commit d')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
173
        out, err = self.run_bzr('merge')
1685.1.38 by John Arbash Meinel
Fix merge_remember to use a complete path.
174
        
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
175
        base = urlutils.local_path_from_url(branch_a.base)
1685.1.59 by Martin Pool
[broken] Fix up & refactor display of remembered urls to unescape properly
176
        self.assertEquals(out, 'Merging from remembered location %s\n' % (base,))
1551.11.11 by Aaron Bentley
Get tests passing
177
        self.assertEquals(err, '+N  b\nAll changes applied successfully.\n')
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
178
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
179
        # re-open tree as external run_bzr modified it
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
180
        tree_b = branch_b.bzrdir.open_workingtree()
181
        tree_b.commit('merge branch_a')
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
182
        # test explicit --remember
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
183
        out, err = self.run_bzr('merge ../branch_c --remember')
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
184
        self.assertEquals(out, '')
1551.11.11 by Aaron Bentley
Get tests passing
185
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
186
        self.assertEquals(abspath(branch_b.get_parent()),
187
                          abspath(branch_c.bzrdir.root_transport.base))
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
188
        # re-open tree as external run_bzr modified it
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
189
        tree_b = branch_b.bzrdir.open_workingtree()
190
        tree_b.commit('merge branch_c')
1185.82.22 by Aaron Bentley
Start getting changeset merging under test
191
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
192
    def test_merge_bundle(self):
1185.82.33 by Aaron Bentley
Strengthen tests
193
        from bzrlib.testament import Testament
1185.82.22 by Aaron Bentley
Start getting changeset merging under test
194
        tree_a = self.make_branch_and_tree('branch_a')
195
        f = file('branch_a/a', 'wb')
196
        f.write('hello')
197
        f.close()
198
        tree_a.add('a')
199
        tree_a.commit('message')
200
201
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
1185.82.23 by Aaron Bentley
Switch the fetcher
202
        f = file('branch_a/a', 'wb')
203
        f.write('hey there')
204
        f.close()
205
        tree_a.commit('message')
206
1185.82.22 by Aaron Bentley
Start getting changeset merging under test
207
        f = file('branch_b/a', 'wb')
208
        f.write('goodbye')
209
        f.close()
210
        tree_b.commit('message')
211
        os.chdir('branch_b')
2654.3.1 by Aaron Bentley
Rename submit to send, make -o required, support -o- for stdout
212
        self.run_bzr('bundle ../branch_a -o ../bundle')
1185.82.26 by Aaron Bentley
Get changeset merges closer to working
213
        os.chdir('../branch_a')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
214
        self.run_bzr('merge ../bundle', retcode=1)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
215
        testament_a = Testament.from_revision(tree_a.branch.repository,
216
                                              tree_b.get_parent_ids()[0])
1185.82.33 by Aaron Bentley
Strengthen tests
217
        testament_b = Testament.from_revision(tree_b.branch.repository,
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
218
                                              tree_b.get_parent_ids()[0])
1185.82.33 by Aaron Bentley
Strengthen tests
219
        self.assertEqualDiff(testament_a.as_text(),
220
                         testament_b.as_text())
1185.82.141 by Aaron Bentley
Ensure bzr works when you merge an already-merged bundle
221
        tree_a.set_conflicts(ConflictList())
222
        tree_a.commit('message')
223
        # it is legal to attempt to merge an already-merged bundle
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
224
        output = self.run_bzr('merge ../bundle')[1]
1185.82.141 by Aaron Bentley
Ensure bzr works when you merge an already-merged bundle
225
        # but it does nothing
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
226
        self.assertFalse(tree_a.changes_from(tree_a.basis_tree()).has_changed())
1185.82.142 by Aaron Bentley
Update for review comments
227
        self.assertEqual('Nothing to do.\n', output)
1910.1.1 by Aaron Bentley
Merge takes --uncommitted parameter
228
229
    def test_merge_uncommitted(self):
230
        """Check that merge --uncommitted behaves properly"""
231
        tree_a = self.make_branch_and_tree('a')
232
        self.build_tree(['a/file_1', 'a/file_2'])
233
        tree_a.add(['file_1', 'file_2'])
234
        tree_a.commit('commit 1')
235
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
236
        self.failUnlessExists('b/file_1')
237
        tree_a.rename_one('file_1', 'file_i')
238
        tree_a.commit('commit 2')
239
        tree_a.rename_one('file_2', 'file_ii')
2279.3.1 by mbp at sourcefrog
Add a -d option to push, pull, merge (ported from tags branch)
240
        ## os.chdir('b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
241
        self.run_bzr('merge a --uncommitted -d b')
2279.3.1 by mbp at sourcefrog
Add a -d option to push, pull, merge (ported from tags branch)
242
        self.failUnlessExists('b/file_1')
243
        self.failUnlessExists('b/file_ii')
1910.1.1 by Aaron Bentley
Merge takes --uncommitted parameter
244
        tree_b.revert([])
2279.3.1 by mbp at sourcefrog
Add a -d option to push, pull, merge (ported from tags branch)
245
        self.run_bzr_error(('Cannot use --uncommitted and --revision',),
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
246
                           'merge /a --uncommitted -r1 -d b')
2149.2.1 by Jan Hudec
Option --pull for merge command.
247
248
    def pullable_branch(self):
249
        os.mkdir('a')
250
        os.chdir('a')
251
        self.example_branch()
252
        os.chdir('..')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
253
        self.run_bzr('branch a b')
2149.2.1 by Jan Hudec
Option --pull for merge command.
254
        os.chdir('b')
255
        file('goodbye', 'wt').write('quux')
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
256
        self.run_bzr(['commit', '-m', "mode u's are always good"])
2149.2.1 by Jan Hudec
Option --pull for merge command.
257
        os.chdir('../a')
258
259
    def pullable_branch(self):
260
        tree_a = self.make_branch_and_tree('a')
261
        self.build_tree(['a/file'])
262
        tree_a.add(['file'])
263
        self.id1 = tree_a.commit('commit 1')
264
        
265
        tree_b = self.make_branch_and_tree('b')
266
        tree_b.pull(tree_a.branch)
267
        file('b/file', 'wb').write('foo')
268
        self.id2 = tree_b.commit('commit 2')
269
270
    def test_merge_pull(self):
271
        self.pullable_branch()
272
        os.chdir('a')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
273
        (out, err) = self.run_bzr('merge --pull ../b')
1551.15.67 by Aaron Bentley
Stop using _merge_helper for merging
274
        self.assertContainsRe(out, 'Now on revision 2\\.')
2149.2.1 by Jan Hudec
Option --pull for merge command.
275
        tree_a = WorkingTree.open('.')
276
        self.assertEqual([self.id2], tree_a.get_parent_ids())
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
277
278
    def test_merge_kind_change(self):
279
        tree_a = self.make_branch_and_tree('tree_a')
280
        self.build_tree_contents([('tree_a/file', 'content_1')])
281
        tree_a.add('file', 'file-id')
282
        tree_a.commit('added file')
283
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
284
        os.unlink('tree_a/file')
285
        self.build_tree(['tree_a/file/'])
286
        tree_a.commit('changed file to directory')
287
        os.chdir('tree_b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
288
        self.run_bzr('merge ../tree_a')
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
289
        self.assertEqual('directory', file_kind('file'))
290
        tree_b.revert([])
291
        self.assertEqual('file', file_kind('file'))
292
        self.build_tree_contents([('file', 'content_2')])
293
        tree_b.commit('content change')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
294
        self.run_bzr('merge ../tree_a', retcode=1)
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
295
        self.assertEqual(tree_b.conflicts(),
296
                         [ContentsConflict('file', file_id='file-id')])
2520.4.109 by Aaron Bentley
start work on directive cherry-picking
297
298
    def test_directive_cherrypick(self):
299
        source = self.make_branch_and_tree('source')
300
        self.build_tree(['source/a'])
301
        source.add('a')
302
        source.commit('Added a', rev_id='rev1')
303
        self.build_tree(['source/b'])
304
        source.add('b')
305
        source.commit('Added b', rev_id='rev2')
306
        target = self.make_branch_and_tree('target')
307
        target.commit('empty commit')
2520.4.111 by Aaron Bentley
Ensure that damaged preview patches produce a warning in merge
308
        self.write_directive('directive', source.branch, 'target', 'rev2',
309
                             'rev1')
2520.4.110 by Aaron Bentley
Implement cherrypick support for merge directives
310
        self.run_bzr('merge -d target directive')
311
        self.failIfExists('target/a')
312
        self.failUnlessExists('target/b')
2520.4.111 by Aaron Bentley
Ensure that damaged preview patches produce a warning in merge
313
314
    def write_directive(self, filename, source, target, revision_id,
315
                        base_revision_id=None, mangle_patch=False):
316
        md = merge_directive.MergeDirective2.from_objects(
2520.4.112 by Aaron Bentley
Make cherry-pick merge directives possible
317
            source.repository, revision_id, 0, 0, target,
318
            base_revision_id=base_revision_id)
2520.4.111 by Aaron Bentley
Ensure that damaged preview patches produce a warning in merge
319
        if mangle_patch:
320
            md.patch = 'asdf\n'
321
        self.build_tree_contents([(filename, ''.join(md.to_lines()))])
322
323
    def test_directive_verify_warning(self):
324
        source = self.make_branch_and_tree('source')
325
        self.build_tree(['source/a'])
326
        source.add('a')
327
        source.commit('Added a', rev_id='rev1')
328
        target = self.make_branch_and_tree('target')
329
        target.commit('empty commit')
330
        self.write_directive('directive', source.branch, 'target', 'rev1')
331
        err = self.run_bzr('merge -d target directive')[1]
332
        self.assertNotContainsRe(err, 'Preview patch does not match changes')
333
        target.revert([])
334
        self.write_directive('directive', source.branch, 'target', 'rev1',
335
                             mangle_patch=True)
336
        err = self.run_bzr('merge -d target directive')[1]
2694.3.1 by Aaron Bentley
Disable patch verification (broken for CRLF files)
337
        self.expectFailure('Patch verification is disabled',
338
                           self.assertContainsRe, err,
339
                           'Preview patch does not match changes')
1551.15.66 by Aaron Bentley
Improve behavior with revision ids
340
341
    def test_merge_arbitrary(self):
342
        target = self.make_branch_and_tree('target')
343
        target.commit('empty')
344
        # We need a revision that has no integer revno
345
        branch_a = target.bzrdir.sprout('branch_a').open_workingtree()
346
        self.build_tree(['branch_a/file1'])
347
        branch_a.add('file1')
348
        branch_a.commit('added file1', rev_id='rev2a')
349
        branch_b = target.bzrdir.sprout('branch_b').open_workingtree()
350
        self.build_tree(['branch_b/file2'])
351
        branch_b.add('file2')
352
        branch_b.commit('added file2', rev_id='rev2b')
353
        branch_b.merge_from_branch(branch_a.branch)
354
        self.failUnlessExists('branch_b/file1')
355
        branch_b.commit('merged branch_a', rev_id='rev3b')
356
357
        # It works if the revid has an interger revno
358
        self.run_bzr('merge -d target -r revid:rev2a branch_a')
359
        self.failUnlessExists('target/file1')
360
        self.failIfExists('target/file2')
361
        target.revert([])
362
363
        # It should work if the revid has no integer revno
364
        self.run_bzr('merge -d target -r revid:rev2a branch_b')
365
        self.failUnlessExists('target/file1')
366
        self.failIfExists('target/file2')