/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
24
from bzrlib.branch import Branch
1551.6.16 by Aaron Bentley
Merge from bzr.dev
25
from bzrlib.bzrdir import BzrDir
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
26
from bzrlib.conflicts import ConflictList, ContentsConflict
27
from bzrlib.osutils import abspath, file_kind
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
28
from bzrlib.tests.blackbox import ExternalBase
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
29
import bzrlib.urlutils as urlutils
1551.6.16 by Aaron Bentley
Merge from bzr.dev
30
from bzrlib.workingtree import WorkingTree
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
31
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
32
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
33
class TestMerge(ExternalBase):
34
1551.6.16 by Aaron Bentley
Merge from bzr.dev
35
    def example_branch(test):
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
36
        test.run_bzr('init')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
37
        file('hello', 'wt').write('foo')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
38
        test.run_bzr('add hello')
39
        test.run_bzr('commit -m setup hello')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
40
        file('goodbye', 'wt').write('baz')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
41
        test.run_bzr('add goodbye')
42
        test.run_bzr('commit -m setup goodbye')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
43
44
    def test_merge_reprocess(self):
45
        d = BzrDir.create_standalone_workingtree('.')
46
        d.commit('h')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
47
        self.run_bzr('merge . --reprocess --merge-type weave')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
48
49
    def test_merge(self):
50
        from bzrlib.branch import Branch
51
        
52
        os.mkdir('a')
53
        os.chdir('a')
54
        self.example_branch()
1907.4.4 by Matthieu Moy
Explain the error messages in the code.
55
        ancestor = Branch.open('.').revno()
1551.6.16 by Aaron Bentley
Merge from bzr.dev
56
        os.chdir('..')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
57
        self.run_bzr('branch a b')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
58
        os.chdir('b')
59
        file('goodbye', 'wt').write('quux')
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
60
        self.run_bzr(['commit',  '-m',  "more u's are always good"])
1551.6.16 by Aaron Bentley
Merge from bzr.dev
61
62
        os.chdir('../a')
63
        file('hello', 'wt').write('quuux')
64
        # 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
65
        self.run_bzr('merge ../b', retcode=3)
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
66
        a = WorkingTree.open('.')
67
        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
68
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type blooof',
1551.6.16 by Aaron Bentley
Merge from bzr.dev
69
                    retcode=3)
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
70
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type merge3')
71
        self.run_bzr('revert --no-backup')
72
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type weave')
73
        self.run_bzr('revert --no-backup')
74
        self.run_bzr('merge ../b -r last:1..last:1 --reprocess')
75
        self.run_bzr('revert --no-backup')
76
        self.run_bzr('merge ../b -r last:1')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
77
        self.check_file_contents('goodbye', 'quux')
78
        # Merging a branch pulls its revision into the tree
79
        b = Branch.open('../b')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
80
        b_tip = b.last_revision()
81
        self.failUnless(a.branch.repository.has_revision(b_tip))
82
        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
83
        self.run_bzr('revert --no-backup')
84
        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.
85
        self.assertTrue("Not a branch" in err)
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
86
        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.
87
                    %(ancestor,b.revno()))
1551.8.25 by Aaron Bentley
Fix deprecated use of pending_merges
88
        self.assertEquals(a.get_parent_ids(), 
89
                          [a.branch.last_revision(), b.last_revision()])
1907.4.12 by Matthieu Moy
Made merge work with two revisions in different branches.
90
        self.check_file_contents('goodbye', 'quux')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
91
        self.run_bzr('revert --no-backup')
92
        self.run_bzr('merge -r revno:%d:../b'%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()])
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
95
        a_tip = a.commit('merged')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
96
        self.run_bzr('merge ../b -r last:1')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
97
        self.assertEqual([a_tip], a.get_parent_ids())
1551.6.16 by Aaron Bentley
Merge from bzr.dev
98
99
    def test_merge_with_missing_file(self):
100
        """Merge handles missing file conflicts"""
101
        os.mkdir('a')
102
        os.chdir('a')
103
        os.mkdir('sub')
104
        print >> file('sub/a.txt', 'wb'), "hello"
105
        print >> file('b.txt', 'wb'), "hello"
106
        print >> file('sub/c.txt', 'wb'), "hello"
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
107
        self.run_bzr('init')
108
        self.run_bzr('add')
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
109
        self.run_bzr(['commit', '-m', 'added a'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
110
        self.run_bzr('branch . ../b')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
111
        print >> file('sub/a.txt', 'ab'), "there"
112
        print >> file('b.txt', 'ab'), "there"
113
        print >> file('sub/c.txt', 'ab'), "there"
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
114
        self.run_bzr(['commit', '-m', 'Added there'])
1551.6.16 by Aaron Bentley
Merge from bzr.dev
115
        os.unlink('sub/a.txt')
116
        os.unlink('sub/c.txt')
117
        os.rmdir('sub')
118
        os.unlink('b.txt')
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
119
        self.run_bzr(['commit', '-m', 'Removed a.txt'])
1551.6.16 by Aaron Bentley
Merge from bzr.dev
120
        os.chdir('../b')
121
        print >> file('sub/a.txt', 'ab'), "something"
122
        print >> file('b.txt', 'ab'), "something"
123
        print >> file('sub/c.txt', 'ab'), "something"
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
124
        self.run_bzr(['commit', '-m', 'Modified a.txt'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
125
        self.run_bzr('merge ../a/', retcode=1)
1551.6.16 by Aaron Bentley
Merge from bzr.dev
126
        self.assert_(os.path.exists('sub/a.txt.THIS'))
127
        self.assert_(os.path.exists('sub/a.txt.BASE'))
128
        os.chdir('../a')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
129
        self.run_bzr('merge ../b/', retcode=1)
1551.6.16 by Aaron Bentley
Merge from bzr.dev
130
        self.assert_(os.path.exists('sub/a.txt.OTHER'))
131
        self.assert_(os.path.exists('sub/a.txt.BASE'))
132
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
133
    def test_merge_remember(self):
134
        """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.
135
        tree_a = self.make_branch_and_tree('branch_a')
136
        branch_a = tree_a.branch
137
        self.build_tree(['branch_a/a'])
138
        tree_a.add('a')
139
        tree_a.commit('commit a')
140
        branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
141
        tree_b = branch_b.bzrdir.open_workingtree()
142
        branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
143
        tree_c = branch_c.bzrdir.open_workingtree()
144
        self.build_tree(['branch_a/b'])
145
        tree_a.add('b')
146
        tree_a.commit('commit b')
147
        self.build_tree(['branch_c/c'])
148
        tree_c.add('c')
149
        tree_c.commit('commit c')
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
150
        # reset parent
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
151
        parent = branch_b.get_parent()
152
        branch_b.set_parent(None)
153
        self.assertEqual(None, branch_b.get_parent())
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
154
        # test merge for failure without parent set
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
155
        os.chdir('branch_b')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
156
        out = self.run_bzr('merge', retcode=3)
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
157
        self.assertEquals(out,
1685.1.59 by Martin Pool
[broken] Fix up & refactor display of remembered urls to unescape properly
158
                ('','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
159
        # test implicit --remember when no parent set, this merge conflicts
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
160
        self.build_tree(['d'])
161
        tree_b.add('d')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
162
        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
163
        self.assertEquals(out,
164
                ('','bzr: ERROR: Working tree has uncommitted changes.\n'))
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
165
        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
166
        # test implicit --remember after resolving conflict
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
167
        tree_b.commit('commit d')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
168
        out, err = self.run_bzr('merge')
1685.1.38 by John Arbash Meinel
Fix merge_remember to use a complete path.
169
        
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
170
        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
171
        self.assertEquals(out, 'Merging from remembered location %s\n' % (base,))
1551.11.11 by Aaron Bentley
Get tests passing
172
        self.assertEquals(err, '+N  b\nAll changes applied successfully.\n')
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
173
        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
174
        # re-open tree as external run_bzr modified it
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
175
        tree_b = branch_b.bzrdir.open_workingtree()
176
        tree_b.commit('merge branch_a')
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
177
        # test explicit --remember
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
178
        out, err = self.run_bzr('merge ../branch_c --remember')
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
179
        self.assertEquals(out, '')
1551.11.11 by Aaron Bentley
Get tests passing
180
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
181
        self.assertEquals(abspath(branch_b.get_parent()),
182
                          abspath(branch_c.bzrdir.root_transport.base))
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
183
        # re-open tree as external run_bzr modified it
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
184
        tree_b = branch_b.bzrdir.open_workingtree()
185
        tree_b.commit('merge branch_c')
1185.82.22 by Aaron Bentley
Start getting changeset merging under test
186
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
187
    def test_merge_bundle(self):
1185.82.33 by Aaron Bentley
Strengthen tests
188
        from bzrlib.testament import Testament
1185.82.22 by Aaron Bentley
Start getting changeset merging under test
189
        tree_a = self.make_branch_and_tree('branch_a')
190
        f = file('branch_a/a', 'wb')
191
        f.write('hello')
192
        f.close()
193
        tree_a.add('a')
194
        tree_a.commit('message')
195
196
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
1185.82.23 by Aaron Bentley
Switch the fetcher
197
        f = file('branch_a/a', 'wb')
198
        f.write('hey there')
199
        f.close()
200
        tree_a.commit('message')
201
1185.82.22 by Aaron Bentley
Start getting changeset merging under test
202
        f = file('branch_b/a', 'wb')
203
        f.write('goodbye')
204
        f.close()
205
        tree_b.commit('message')
206
        os.chdir('branch_b')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
207
        file('../bundle', 'wb').write(self.run_bzr('bundle ../branch_a')[0])
1185.82.26 by Aaron Bentley
Get changeset merges closer to working
208
        os.chdir('../branch_a')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
209
        self.run_bzr('merge ../bundle', retcode=1)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
210
        testament_a = Testament.from_revision(tree_a.branch.repository,
211
                                              tree_b.get_parent_ids()[0])
1185.82.33 by Aaron Bentley
Strengthen tests
212
        testament_b = Testament.from_revision(tree_b.branch.repository,
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
213
                                              tree_b.get_parent_ids()[0])
1185.82.33 by Aaron Bentley
Strengthen tests
214
        self.assertEqualDiff(testament_a.as_text(),
215
                         testament_b.as_text())
1185.82.141 by Aaron Bentley
Ensure bzr works when you merge an already-merged bundle
216
        tree_a.set_conflicts(ConflictList())
217
        tree_a.commit('message')
218
        # 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
219
        output = self.run_bzr('merge ../bundle')[1]
1185.82.141 by Aaron Bentley
Ensure bzr works when you merge an already-merged bundle
220
        # but it does nothing
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
221
        self.assertFalse(tree_a.changes_from(tree_a.basis_tree()).has_changed())
1185.82.142 by Aaron Bentley
Update for review comments
222
        self.assertEqual('Nothing to do.\n', output)
1910.1.1 by Aaron Bentley
Merge takes --uncommitted parameter
223
224
    def test_merge_uncommitted(self):
225
        """Check that merge --uncommitted behaves properly"""
226
        tree_a = self.make_branch_and_tree('a')
227
        self.build_tree(['a/file_1', 'a/file_2'])
228
        tree_a.add(['file_1', 'file_2'])
229
        tree_a.commit('commit 1')
230
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
231
        self.failUnlessExists('b/file_1')
232
        tree_a.rename_one('file_1', 'file_i')
233
        tree_a.commit('commit 2')
234
        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)
235
        ## os.chdir('b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
236
        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)
237
        self.failUnlessExists('b/file_1')
238
        self.failUnlessExists('b/file_ii')
1910.1.1 by Aaron Bentley
Merge takes --uncommitted parameter
239
        tree_b.revert([])
2279.3.1 by mbp at sourcefrog
Add a -d option to push, pull, merge (ported from tags branch)
240
        self.run_bzr_error(('Cannot use --uncommitted and --revision',),
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
241
                           'merge /a --uncommitted -r1 -d b')
2149.2.1 by Jan Hudec
Option --pull for merge command.
242
243
    def pullable_branch(self):
244
        os.mkdir('a')
245
        os.chdir('a')
246
        self.example_branch()
247
        os.chdir('..')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
248
        self.run_bzr('branch a b')
2149.2.1 by Jan Hudec
Option --pull for merge command.
249
        os.chdir('b')
250
        file('goodbye', 'wt').write('quux')
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
251
        self.run_bzr(['commit', '-m', "mode u's are always good"])
2149.2.1 by Jan Hudec
Option --pull for merge command.
252
        os.chdir('../a')
253
254
    def pullable_branch(self):
255
        tree_a = self.make_branch_and_tree('a')
256
        self.build_tree(['a/file'])
257
        tree_a.add(['file'])
258
        self.id1 = tree_a.commit('commit 1')
259
        
260
        tree_b = self.make_branch_and_tree('b')
261
        tree_b.pull(tree_a.branch)
262
        file('b/file', 'wb').write('foo')
263
        self.id2 = tree_b.commit('commit 2')
264
265
    def test_merge_pull(self):
266
        self.pullable_branch()
267
        os.chdir('a')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
268
        (out, err) = self.run_bzr('merge --pull ../b')
2297.1.1 by Martin Pool
Pull now returns a PullResult rather than just an integer.
269
        self.assertContainsRe(err, 'Now on revision 2\\.')
2149.2.1 by Jan Hudec
Option --pull for merge command.
270
        tree_a = WorkingTree.open('.')
271
        self.assertEqual([self.id2], tree_a.get_parent_ids())
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
272
273
    def test_merge_kind_change(self):
274
        tree_a = self.make_branch_and_tree('tree_a')
275
        self.build_tree_contents([('tree_a/file', 'content_1')])
276
        tree_a.add('file', 'file-id')
277
        tree_a.commit('added file')
278
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
279
        os.unlink('tree_a/file')
280
        self.build_tree(['tree_a/file/'])
281
        tree_a.commit('changed file to directory')
282
        os.chdir('tree_b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
283
        self.run_bzr('merge ../tree_a')
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
284
        self.assertEqual('directory', file_kind('file'))
285
        tree_b.revert([])
286
        self.assertEqual('file', file_kind('file'))
287
        self.build_tree_contents([('file', 'content_2')])
288
        tree_b.commit('content change')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
289
        self.run_bzr('merge ../tree_a', retcode=1)
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
290
        self.assertEqual(tree_b.conflicts(),
291
                         [ContentsConflict('file', file_id='file-id')])