/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1551.6.16 by Aaron Bentley
Merge from bzr.dev
1
# Copyright (C) 2006 Canonical Ltd
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
1185.82.141 by Aaron Bentley
Ensure bzr works when you merge an already-merged bundle
26
from bzrlib.conflicts import ConflictList
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
27
from bzrlib.osutils import abspath
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):
36
        test.runbzr('init')
37
        file('hello', 'wt').write('foo')
38
        test.runbzr('add hello')
39
        test.runbzr('commit -m setup hello')
40
        file('goodbye', 'wt').write('baz')
41
        test.runbzr('add goodbye')
42
        test.runbzr('commit -m setup goodbye')
43
44
    def test_merge_reprocess(self):
45
        d = BzrDir.create_standalone_workingtree('.')
46
        d.commit('h')
1857.1.20 by Aaron Bentley
Strip out all the EnumOption stuff
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()
55
        os.chdir('..')
56
        self.runbzr('branch a b')
57
        os.chdir('b')
58
        file('goodbye', 'wt').write('quux')
59
        self.runbzr(['commit',  '-m',  "more u's are always good"])
60
61
        os.chdir('../a')
62
        file('hello', 'wt').write('quuux')
63
        # We can't merge when there are in-tree changes
64
        self.runbzr('merge ../b', retcode=3)
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
65
        a = WorkingTree.open('.')
66
        a_tip = a.commit("Like an epidemic of u's")
1857.1.20 by Aaron Bentley
Strip out all the EnumOption stuff
67
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
1551.6.16 by Aaron Bentley
Merge from bzr.dev
68
                    retcode=3)
1857.1.20 by Aaron Bentley
Strip out all the EnumOption stuff
69
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
70
        self.runbzr('revert --no-backup')
1857.1.20 by Aaron Bentley
Strip out all the EnumOption stuff
71
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
72
        self.runbzr('revert --no-backup')
73
        self.runbzr('merge ../b -r last:1..last:1 --reprocess')
74
        self.runbzr('revert --no-backup')
75
        self.runbzr('merge ../b -r last:1')
76
        self.check_file_contents('goodbye', 'quux')
77
        # Merging a branch pulls its revision into the tree
78
        b = Branch.open('../b')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
79
        b_tip = b.last_revision()
80
        self.failUnless(a.branch.repository.has_revision(b_tip))
81
        self.assertEqual([a_tip, b_tip], a.get_parent_ids())
82
        a_tip = a.commit('merged')
1551.6.16 by Aaron Bentley
Merge from bzr.dev
83
        self.runbzr('merge ../b -r last:1')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
84
        self.assertEqual([a_tip], a.get_parent_ids())
1551.6.16 by Aaron Bentley
Merge from bzr.dev
85
86
    def test_merge_with_missing_file(self):
87
        """Merge handles missing file conflicts"""
88
        os.mkdir('a')
89
        os.chdir('a')
90
        os.mkdir('sub')
91
        print >> file('sub/a.txt', 'wb'), "hello"
92
        print >> file('b.txt', 'wb'), "hello"
93
        print >> file('sub/c.txt', 'wb'), "hello"
94
        self.runbzr('init')
95
        self.runbzr('add')
96
        self.runbzr(('commit', '-m', 'added a'))
97
        self.runbzr('branch . ../b')
98
        print >> file('sub/a.txt', 'ab'), "there"
99
        print >> file('b.txt', 'ab'), "there"
100
        print >> file('sub/c.txt', 'ab'), "there"
101
        self.runbzr(('commit', '-m', 'Added there'))
102
        os.unlink('sub/a.txt')
103
        os.unlink('sub/c.txt')
104
        os.rmdir('sub')
105
        os.unlink('b.txt')
106
        self.runbzr(('commit', '-m', 'Removed a.txt'))
107
        os.chdir('../b')
108
        print >> file('sub/a.txt', 'ab'), "something"
109
        print >> file('b.txt', 'ab'), "something"
110
        print >> file('sub/c.txt', 'ab'), "something"
111
        self.runbzr(('commit', '-m', 'Modified a.txt'))
112
        self.runbzr('merge ../a/', retcode=1)
113
        self.assert_(os.path.exists('sub/a.txt.THIS'))
114
        self.assert_(os.path.exists('sub/a.txt.BASE'))
115
        os.chdir('../a')
116
        self.runbzr('merge ../b/', retcode=1)
117
        self.assert_(os.path.exists('sub/a.txt.OTHER'))
118
        self.assert_(os.path.exists('sub/a.txt.BASE'))
119
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
120
    def test_merge_remember(self):
121
        """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.
122
        tree_a = self.make_branch_and_tree('branch_a')
123
        branch_a = tree_a.branch
124
        self.build_tree(['branch_a/a'])
125
        tree_a.add('a')
126
        tree_a.commit('commit a')
127
        branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
128
        tree_b = branch_b.bzrdir.open_workingtree()
129
        branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
130
        tree_c = branch_c.bzrdir.open_workingtree()
131
        self.build_tree(['branch_a/b'])
132
        tree_a.add('b')
133
        tree_a.commit('commit b')
134
        self.build_tree(['branch_c/c'])
135
        tree_c.add('c')
136
        tree_c.commit('commit c')
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
137
        # reset parent
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
138
        parent = branch_b.get_parent()
139
        branch_b.set_parent(None)
140
        self.assertEqual(None, branch_b.get_parent())
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
141
        # test merge for failure without parent set
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
142
        os.chdir('branch_b')
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
143
        out = self.runbzr('merge', retcode=3)
144
        self.assertEquals(out,
1685.1.59 by Martin Pool
[broken] Fix up & refactor display of remembered urls to unescape properly
145
                ('','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
146
        # test implicit --remember when no parent set, this merge conflicts
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
147
        self.build_tree(['d'])
148
        tree_b.add('d')
149
        out = self.runbzr('merge ../branch_a', retcode=3)
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
150
        self.assertEquals(out,
151
                ('','bzr: ERROR: Working tree has uncommitted changes.\n'))
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
152
        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
153
        # test implicit --remember after resolving conflict
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
154
        tree_b.commit('commit d')
155
        out, err = self.runbzr('merge')
1685.1.38 by John Arbash Meinel
Fix merge_remember to use a complete path.
156
        
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
157
        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
158
        self.assertEquals(out, 'Merging from remembered location %s\n' % (base,))
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
159
        self.assertEquals(err, 'All changes applied successfully.\n')
160
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
161
        # re-open tree as external runbzr modified it
162
        tree_b = branch_b.bzrdir.open_workingtree()
163
        tree_b.commit('merge branch_a')
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
164
        # test explicit --remember
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
165
        out, err = self.runbzr('merge ../branch_c --remember')
166
        self.assertEquals(out, '')
167
        self.assertEquals(err, 'All changes applied successfully.\n')
168
        self.assertEquals(abspath(branch_b.get_parent()),
169
                          abspath(branch_c.bzrdir.root_transport.base))
170
        # re-open tree as external runbzr modified it
171
        tree_b = branch_b.bzrdir.open_workingtree()
172
        tree_b.commit('merge branch_c')
1185.82.22 by Aaron Bentley
Start getting changeset merging under test
173
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
174
    def test_merge_bundle(self):
1185.82.33 by Aaron Bentley
Strengthen tests
175
        from bzrlib.testament import Testament
1185.82.22 by Aaron Bentley
Start getting changeset merging under test
176
        tree_a = self.make_branch_and_tree('branch_a')
177
        f = file('branch_a/a', 'wb')
178
        f.write('hello')
179
        f.close()
180
        tree_a.add('a')
181
        tree_a.commit('message')
182
183
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
1185.82.23 by Aaron Bentley
Switch the fetcher
184
        f = file('branch_a/a', 'wb')
185
        f.write('hey there')
186
        f.close()
187
        tree_a.commit('message')
188
1185.82.22 by Aaron Bentley
Start getting changeset merging under test
189
        f = file('branch_b/a', 'wb')
190
        f.write('goodbye')
191
        f.close()
192
        tree_b.commit('message')
193
        os.chdir('branch_b')
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
194
        file('../bundle', 'wb').write(self.runbzr('bundle ../branch_a')[0])
1185.82.26 by Aaron Bentley
Get changeset merges closer to working
195
        os.chdir('../branch_a')
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
196
        self.runbzr('merge ../bundle', retcode=1)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
197
        testament_a = Testament.from_revision(tree_a.branch.repository,
198
                                              tree_b.get_parent_ids()[0])
1185.82.33 by Aaron Bentley
Strengthen tests
199
        testament_b = Testament.from_revision(tree_b.branch.repository,
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
200
                                              tree_b.get_parent_ids()[0])
1185.82.33 by Aaron Bentley
Strengthen tests
201
        self.assertEqualDiff(testament_a.as_text(),
202
                         testament_b.as_text())
1185.82.141 by Aaron Bentley
Ensure bzr works when you merge an already-merged bundle
203
        tree_a.set_conflicts(ConflictList())
204
        tree_a.commit('message')
205
        # it is legal to attempt to merge an already-merged bundle
1185.82.142 by Aaron Bentley
Update for review comments
206
        output = self.runbzr('merge ../bundle')[1]
1185.82.141 by Aaron Bentley
Ensure bzr works when you merge an already-merged bundle
207
        # but it does nothing
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
208
        self.assertFalse(tree_a.changes_from(tree_a.basis_tree()).has_changed())
1185.82.142 by Aaron Bentley
Update for review comments
209
        self.assertEqual('Nothing to do.\n', output)
1910.1.1 by Aaron Bentley
Merge takes --uncommitted parameter
210
211
    def test_merge_uncommitted(self):
212
        """Check that merge --uncommitted behaves properly"""
213
        tree_a = self.make_branch_and_tree('a')
214
        self.build_tree(['a/file_1', 'a/file_2'])
215
        tree_a.add(['file_1', 'file_2'])
216
        tree_a.commit('commit 1')
217
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
218
        self.failUnlessExists('b/file_1')
219
        tree_a.rename_one('file_1', 'file_i')
220
        tree_a.commit('commit 2')
221
        tree_a.rename_one('file_2', 'file_ii')
222
        os.chdir('b')
223
        self.run_bzr('merge', '../a', '--uncommitted')
224
        self.failUnlessExists('file_1')
225
        self.failUnlessExists('file_ii')
226
        tree_b.revert([])
227
        self.run_bzr_error(('Cannot use --uncommitted and --revision',), 
228
                           'merge', '../a', '--uncommitted', '-r1')