/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
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
16
17
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
18
"""Tests of bound branches (binding, unbinding, commit, etc) command."""
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
19
20
import os
21
from cStringIO import StringIO
22
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
23
from bzrlib import (
24
    bzrdir,
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
25
    errors
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
26
    )
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
27
from bzrlib.branch import Branch
1694.2.6 by Martin Pool
[merge] bzr.dev
28
from bzrlib.bzrdir import (BzrDir, BzrDirFormat, BzrDirMetaFormat1)
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
29
from bzrlib.osutils import getcwd
30
from bzrlib.tests import TestCaseWithTransport
31
import bzrlib.urlutils as urlutils
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
32
from bzrlib.workingtree import WorkingTree
33
34
35
class TestLegacyFormats(TestCaseWithTransport):
36
    
37
    def setUp(self):
38
        super(TestLegacyFormats, self).setUp()
39
        self.build_tree(['master/', 'child/'])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
40
        self.make_branch_and_tree('master')
41
        self.make_branch_and_tree('child',
42
                        format=bzrdir.format_registry.make_bzrdir('weave'))
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
43
        os.chdir('child')
44
    
45
    def test_bind_format_6_bzrdir(self):
46
        # bind on a format 6 bzrdir should error
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
47
        out,err = self.run_bzr('bind ../master', retcode=3)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
48
        self.assertEqual('', out)
1685.1.34 by John Arbash Meinel
Another test which assumed the output was a local path not a url
49
        # TODO: jam 20060427 Probably something like this really should
50
        #       print out the actual path, rather than the URL
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
51
        cwd = urlutils.local_path_to_url(getcwd())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
52
        self.assertEqual('bzr: ERROR: To use this feature you must '
1685.1.34 by John Arbash Meinel
Another test which assumed the output was a local path not a url
53
                         'upgrade your branch at %s/.\n' % cwd, err)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
54
    
55
    def test_unbind_format_6_bzrdir(self):
56
        # bind on a format 6 bzrdir should error
57
        out,err = self.run_bzr('unbind', retcode=3)
58
        self.assertEqual('', out)
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
59
        cwd = urlutils.local_path_to_url(getcwd())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
60
        self.assertEqual('bzr: ERROR: To use this feature you must '
1685.1.34 by John Arbash Meinel
Another test which assumed the output was a local path not a url
61
                         'upgrade your branch at %s/.\n' % cwd, err)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
62
63
64
class TestBoundBranches(TestCaseWithTransport):
65
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
66
    def create_branches(self):
67
        self.build_tree(['base/', 'base/a', 'base/b'])
68
1607.1.14 by Robert Collins
Reduce lock thrashing somewhat - drops bound branch tests lock count from 6554 to 4456 locks.
69
        branch = self.init_meta_branch('base')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
70
        base_tree = branch.bzrdir.open_workingtree()
71
        base_tree.lock_write()
72
        base_tree.add(['a', 'b'])
73
        base_tree.commit('init')
74
        base_tree.unlock()
1607.1.14 by Robert Collins
Reduce lock thrashing somewhat - drops bound branch tests lock count from 6554 to 4456 locks.
75
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
76
        child_tree = branch.create_checkout('child')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
77
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
78
        self.check_revno(1, 'child')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
79
        d = BzrDir.open('child')
80
        self.assertNotEqual(None, d.open_branch().get_master_branch())
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
81
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
82
        return base_tree, child_tree
83
1607.1.14 by Robert Collins
Reduce lock thrashing somewhat - drops bound branch tests lock count from 6554 to 4456 locks.
84
    def check_revno(self, val, loc='.'):
85
        self.assertEqual(
86
            val, len(BzrDir.open(loc).open_branch().revision_history()))
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
87
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
88
    def test_simple_binding(self):
89
        self.build_tree(['base/', 'base/a', 'base/b'])
90
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
91
        branch = self.init_meta_branch('base')
92
        tree = branch.bzrdir.open_workingtree()
93
        tree.add('a', 'b')
94
        tree.commit(message='init')
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
95
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
96
        tree.bzrdir.sprout('child')
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
97
98
        os.chdir('child')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
99
        self.run_bzr('bind ../base')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
100
101
        d = BzrDir.open('')
102
        self.assertNotEqual(None, d.open_branch().get_master_branch())
103
104
        self.run_bzr('unbind')
105
        self.assertEqual(None, d.open_branch().get_master_branch())
106
107
        self.run_bzr('unbind', retcode=3)
108
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
109
    def test_bind_branch6(self):
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
110
        branch1 = self.make_branch('branch1', format='dirstate-tags')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
111
        os.chdir('branch1')
112
        error = self.run_bzr('bind', retcode=3)[1]
2230.3.48 by Aaron Bentley
Update blackbox test to handle new error message
113
        self.assertContainsRe(error, 'no previous location known')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
114
115
    def setup_rebind(self, format):
116
        branch1 = self.make_branch('branch1')
117
        branch2 = self.make_branch('branch2', format=format)
118
        branch2.bind(branch1)
119
        branch2.unbind()
120
121
    def test_rebind_branch6(self):
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
122
        self.setup_rebind('dirstate-tags')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
123
        os.chdir('branch2')
124
        self.run_bzr('bind')
125
        b = Branch.open('.')
126
        self.assertContainsRe(b.get_bound_location(), '\/branch1\/$')
127
128
    def test_rebind_branch5(self):
129
        self.setup_rebind('knit')
130
        os.chdir('branch2')
131
        error = self.run_bzr('bind', retcode=3)[1]
132
        self.assertContainsRe(error, 'old locations')
133
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
134
    def init_meta_branch(self, path):
2323.6.3 by Martin Pool
bound-branch ui tests should now use the default branch format
135
        format = bzrdir.format_registry.make_bzrdir('default')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
136
        return BzrDir.create_branch_convenience(path, format=format)
1505.1.5 by John Arbash Meinel
Added a test for the unbind command.
137
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
138
    def test_bound_commit(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
139
        child_tree = self.create_branches()[1]
140
141
        self.build_tree_contents([('child/a', 'new contents')])
142
        child_tree.commit(message='child')
143
144
        self.check_revno(2, 'child')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
145
146
        # Make sure it committed on the parent
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
147
        self.check_revno(2, 'base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
148
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
149
    def test_bound_fail(self):
1505.1.26 by John Arbash Meinel
Created a set of tests which bind to an sftp branch. Found some bugs, need to fix commit.
150
        # Make sure commit fails if out of date.
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
151
        base_tree, child_tree = self.create_branches()
152
153
        self.build_tree_contents([
154
            ('base/a',  'new base contents\n'   ),
155
            ('child/b', 'new b child contents\n')])
156
        base_tree.commit(message='base')
157
        self.check_revno(2, 'base')
158
159
        self.check_revno(1, 'child')
160
        self.assertRaises(errors.BoundBranchOutOfDate, child_tree.commit,
161
                                                            message='child')
162
        self.check_revno(1, 'child')
163
164
        child_tree.update()
165
        self.check_revno(2, 'child')
166
167
        child_tree.commit(message='child')
168
        self.check_revno(3, 'child')
169
        self.check_revno(3, 'base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
170
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
171
    def test_double_binding(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
172
        child_tree = self.create_branches()[1]
173
174
        child2_tree = child_tree.bzrdir.sprout('child2').open_workingtree()
175
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
176
        os.chdir('child2')
1505.1.6 by John Arbash Meinel
Cleaned up tests and code, all bound branch tests succeed.
177
        # Double binding succeeds, but committing to child2 should fail
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
178
        self.run_bzr('bind ../child')
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
179
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
180
        self.assertRaises(errors.CommitToDoubleBoundBranch,
181
                child2_tree.commit, message='child2', allow_pointless=True)
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
182
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
183
    def test_unbinding(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
184
        base_tree, child_tree = self.create_branches()
185
186
        self.build_tree_contents([
187
            ('base/a',  'new base contents\n'   ),
188
            ('child/b', 'new b child contents\n')])
189
190
        base_tree.commit(message='base')
191
        self.check_revno(2, 'base')
192
193
        self.check_revno(1, 'child')
194
        os.chdir('child')
195
        self.run_bzr("commit -m child", retcode=3)
196
        self.check_revno(1)
197
        self.run_bzr('unbind')
198
        child_tree.commit(message='child')
199
        self.check_revno(2)
200
201
        self.run_bzr('bind', retcode=3)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
202
203
    def test_commit_remote_bound(self):
204
        # It is not possible to commit to a branch
205
        # which is bound to a branch which is bound
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
206
        base_tree, child_tree = self.create_branches()
207
        base_tree.bzrdir.sprout('newbase')
208
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
209
        os.chdir('base')
210
        # There is no way to know that B has already
211
        # been bound by someone else, otherwise it
212
        # might be nice if this would fail
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
213
        self.run_bzr('bind ../newbase')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
214
215
        os.chdir('../child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
216
        self.run_bzr('commit -m failure --unchanged', retcode=3)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
217
218
    def test_pull_updates_both(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
219
        base_tree = self.create_branches()[0]
220
        newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
221
        self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
222
        newchild_tree.commit(message='newchild')
223
        self.check_revno(2, 'newchild')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
224
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
225
        os.chdir('child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
226
        # The pull should succeed, and update
227
        # the bound parent branch
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
228
        self.run_bzr('pull ../newchild')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
229
        self.check_revno(2)
230
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
231
        self.check_revno(2, '../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
232
233
    def test_bind_diverged(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
234
        base_tree, child_tree = self.create_branches()
235
        base_branch = base_tree.branch
236
        child_branch = child_tree.branch
237
238
        os.chdir('child')
239
        self.run_bzr('unbind')
240
241
        child_tree.commit(message='child', allow_pointless=True)
242
        self.check_revno(2)
243
244
        os.chdir('..')
245
        self.check_revno(1, 'base')
246
        base_tree.commit(message='base', allow_pointless=True)
247
        self.check_revno(2, 'base')
248
249
        os.chdir('child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
250
        # These branches have diverged
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
251
        self.run_bzr('bind ../base', retcode=3)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
252
253
        # TODO: In the future, this might require actual changes
254
        # to have occurred, rather than just a new revision entry
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
255
        child_tree.merge_from_branch(base_branch)
256
        child_tree.commit(message='merged')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
257
        self.check_revno(3)
258
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
259
        # After binding, the revision history should be unaltered
260
        # take a copy before
261
        base_history = base_branch.revision_history()
262
        child_history = child_branch.revision_history()
263
1505.1.13 by John Arbash Meinel
Adding the bzr update command, to update checkouts and bound branches.
264
        # After a merge, trying to bind again should succeed
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
265
        # keeping the new change as a local commit.
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
266
        self.run_bzr('bind ../base')
1505.1.13 by John Arbash Meinel
Adding the bzr update command, to update checkouts and bound branches.
267
        self.check_revno(3)
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
268
        self.check_revno(2, '../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
269
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
270
        # and compare the revision history now
271
        self.assertEqual(base_history, base_branch.revision_history())
272
        self.assertEqual(child_history, child_branch.revision_history())
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
273
274
    def test_bind_parent_ahead(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
275
        base_tree = self.create_branches()[0]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
276
277
        os.chdir('child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
278
        self.run_bzr('unbind')
279
280
        base_tree.commit(message='base', allow_pointless=True)
281
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
282
        self.check_revno(1)
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
283
        self.run_bzr('bind ../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
284
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
285
        # binding does not pull data:
286
        self.check_revno(1)
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
287
        self.run_bzr('unbind')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
288
289
        # Check and make sure it also works if parent is ahead multiple
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
290
        base_tree.commit(message='base 3', allow_pointless=True)
291
        base_tree.commit(message='base 4', allow_pointless=True)
292
        base_tree.commit(message='base 5', allow_pointless=True)
293
        self.check_revno(5, '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
294
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
295
        self.check_revno(1)
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
296
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
297
        self.check_revno(1)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
298
299
    def test_bind_child_ahead(self):
1607.1.14 by Robert Collins
Reduce lock thrashing somewhat - drops bound branch tests lock count from 6554 to 4456 locks.
300
        # test binding when the master branches history is a prefix of the 
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
301
        # childs - it should bind ok but the revision histories should not
302
        # be altered
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
303
        child_tree = self.create_branches()[1]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
304
305
        os.chdir('child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
306
        self.run_bzr('unbind')
307
        child_tree.commit(message='child', allow_pointless=True)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
308
        self.check_revno(2)
309
        self.check_revno(1, '../base')
310
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
311
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
312
        self.check_revno(1, '../base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
313
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
314
        # Check and make sure it also works if child is ahead multiple
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
315
        self.run_bzr('unbind')
316
        child_tree.commit(message='child 3', allow_pointless=True)
317
        child_tree.commit(message='child 4', allow_pointless=True)
318
        child_tree.commit(message='child 5', allow_pointless=True)
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
319
        self.check_revno(5)
320
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
321
        self.check_revno(1, '../base')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
322
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
323
        self.check_revno(1, '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
324
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
325
    def test_commit_after_merge(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
326
        base_tree, child_tree = self.create_branches()
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
327
328
        # We want merge to be able to be a local only
329
        # operation, because it can be without violating
330
        # the binding invariants.
331
        # But we can't fail afterwards
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
332
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
333
        other_branch = other_tree.branch
334
335
        self.build_tree_contents([('other/c', 'file c\n')])
336
        other_tree.add('c')
337
        other_tree.commit(message='adding c')
338
        new_rev_id = other_branch.revision_history()[-1]
339
340
        child_tree.merge_from_branch(other_branch)
341
342
        self.failUnlessExists('child/c')
343
        self.assertEqual([new_rev_id], child_tree.get_parent_ids()[1:])
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
344
345
        # Make sure the local branch has the installed revision
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
346
        self.assertTrue(child_tree.branch.repository.has_revision(new_rev_id))
347
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
348
        # And make sure that the base tree does not
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
349
        self.assertFalse(base_tree.branch.repository.has_revision(new_rev_id))
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
350
351
        # Commit should succeed, and cause merged revisions to
352
        # be pulled into base
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
353
        os.chdir('child')
354
        self.run_bzr(['commit', '-m', 'merge other'])
355
356
        self.check_revno(2)
357
358
        self.check_revno(2, '../base')
359
360
        self.assertTrue(base_tree.branch.repository.has_revision(new_rev_id))
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
361
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
362
    def test_pull_overwrite(self):
363
        # XXX: This test should be moved to branch-implemenations/test_pull
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
364
        child_tree = self.create_branches()[1]
365
366
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
367
368
        self.build_tree_contents([('other/a', 'new contents\n')])
369
        other_tree.commit(message='changed a')
370
        self.check_revno(2, 'other')
371
        self.build_tree_contents([
372
            ('other/a', 'new contents\nand then some\n')])
373
        other_tree.commit(message='another a')
374
        self.check_revno(3, 'other')
375
        self.build_tree_contents([
376
            ('other/a', 'new contents\nand then some\nand some more\n')])
377
        other_tree.commit('yet another a')
378
        self.check_revno(4, 'other')
379
380
        self.build_tree_contents([('child/a', 'also changed a\n')])
381
        child_tree.commit(message='child modified a')
382
383
        self.check_revno(2, 'child')
384
        self.check_revno(2, 'base')
385
386
        os.chdir('child')
387
        self.run_bzr('pull --overwrite ../other')
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
388
389
        # both the local and master should have been updated.
390
        self.check_revno(4)
391
        self.check_revno(4, '../base')