~bzr-pqm/bzr/bzr.dev

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
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
201
    def test_commit_remote_bound(self):
202
        # It is not possible to commit to a branch
203
        # 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.
204
        base_tree, child_tree = self.create_branches()
205
        base_tree.bzrdir.sprout('newbase')
206
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
207
        os.chdir('base')
208
        # There is no way to know that B has already
209
        # been bound by someone else, otherwise it
210
        # might be nice if this would fail
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
211
        self.run_bzr('bind ../newbase')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
212
213
        os.chdir('../child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
214
        self.run_bzr('commit -m failure --unchanged', retcode=3)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
215
216
    def test_pull_updates_both(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
217
        base_tree = self.create_branches()[0]
218
        newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
219
        self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
220
        newchild_tree.commit(message='newchild')
221
        self.check_revno(2, 'newchild')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
222
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
223
        os.chdir('child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
224
        # The pull should succeed, and update
225
        # the bound parent branch
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
226
        self.run_bzr('pull ../newchild')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
227
        self.check_revno(2)
228
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
229
        self.check_revno(2, '../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
230
231
    def test_bind_diverged(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
232
        base_tree, child_tree = self.create_branches()
233
        base_branch = base_tree.branch
234
        child_branch = child_tree.branch
235
236
        os.chdir('child')
237
        self.run_bzr('unbind')
238
239
        child_tree.commit(message='child', allow_pointless=True)
240
        self.check_revno(2)
241
242
        os.chdir('..')
243
        self.check_revno(1, 'base')
244
        base_tree.commit(message='base', allow_pointless=True)
245
        self.check_revno(2, 'base')
246
247
        os.chdir('child')
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
248
        # These branches have diverged, but bind should succeed anyway
249
        self.run_bzr('bind ../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
250
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
251
        # This should turn the local commit into a merge
252
        child_tree.update()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
253
        child_tree.commit(message='merged')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
254
        self.check_revno(3)
255
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
256
        # After binding, the revision history should be unaltered
257
        # take a copy before
258
        base_history = base_branch.revision_history()
259
        child_history = child_branch.revision_history()
260
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
261
    def test_bind_parent_ahead(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
262
        base_tree = self.create_branches()[0]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
263
264
        os.chdir('child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
265
        self.run_bzr('unbind')
266
267
        base_tree.commit(message='base', allow_pointless=True)
268
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
269
        self.check_revno(1)
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
270
        self.run_bzr('bind ../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
271
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
272
        # binding does not pull data:
273
        self.check_revno(1)
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
274
        self.run_bzr('unbind')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
275
276
        # 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.
277
        base_tree.commit(message='base 3', allow_pointless=True)
278
        base_tree.commit(message='base 4', allow_pointless=True)
279
        base_tree.commit(message='base 5', allow_pointless=True)
280
        self.check_revno(5, '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
281
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
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')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
284
        self.check_revno(1)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
285
286
    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.
287
        # 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
288
        # childs - it should bind ok but the revision histories should not
289
        # be altered
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
290
        child_tree = self.create_branches()[1]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
291
292
        os.chdir('child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
293
        self.run_bzr('unbind')
294
        child_tree.commit(message='child', allow_pointless=True)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
295
        self.check_revno(2)
296
        self.check_revno(1, '../base')
297
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
298
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
299
        self.check_revno(1, '../base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
300
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
301
        # 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.
302
        self.run_bzr('unbind')
303
        child_tree.commit(message='child 3', allow_pointless=True)
304
        child_tree.commit(message='child 4', allow_pointless=True)
305
        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.
306
        self.check_revno(5)
307
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
308
        self.check_revno(1, '../base')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
309
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
310
        self.check_revno(1, '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
311
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
312
    def test_bind_fail_if_missing(self):
313
        """We should not be able to bind to a missing branch."""
314
        tree = self.make_branch_and_tree('tree_1')
315
        tree.commit('dummy commit')
316
        self.run_bzr_error(['Not a branch.*no-such-branch/'], ['bind', '../no-such-branch'],
317
                            working_dir='tree_1')
318
        self.assertIs(None, tree.branch.get_bound_location())
319
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
320
    def test_commit_after_merge(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
321
        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
322
323
        # We want merge to be able to be a local only
324
        # operation, because it can be without violating
325
        # the binding invariants.
326
        # But we can't fail afterwards
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
327
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
328
        other_branch = other_tree.branch
329
330
        self.build_tree_contents([('other/c', 'file c\n')])
331
        other_tree.add('c')
332
        other_tree.commit(message='adding c')
333
        new_rev_id = other_branch.revision_history()[-1]
334
335
        child_tree.merge_from_branch(other_branch)
336
337
        self.failUnlessExists('child/c')
338
        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
339
340
        # 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.
341
        self.assertTrue(child_tree.branch.repository.has_revision(new_rev_id))
342
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
343
        # 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.
344
        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
345
346
        # Commit should succeed, and cause merged revisions to
347
        # be pulled into base
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
348
        os.chdir('child')
349
        self.run_bzr(['commit', '-m', 'merge other'])
350
351
        self.check_revno(2)
352
353
        self.check_revno(2, '../base')
354
355
        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
356
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
357
    def test_pull_overwrite(self):
358
        # 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.
359
        child_tree = self.create_branches()[1]
360
361
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
362
363
        self.build_tree_contents([('other/a', 'new contents\n')])
364
        other_tree.commit(message='changed a')
365
        self.check_revno(2, 'other')
366
        self.build_tree_contents([
367
            ('other/a', 'new contents\nand then some\n')])
368
        other_tree.commit(message='another a')
369
        self.check_revno(3, 'other')
370
        self.build_tree_contents([
371
            ('other/a', 'new contents\nand then some\nand some more\n')])
372
        other_tree.commit('yet another a')
373
        self.check_revno(4, 'other')
374
375
        self.build_tree_contents([('child/a', 'also changed a\n')])
376
        child_tree.commit(message='child modified a')
377
378
        self.check_revno(2, 'child')
379
        self.check_revno(2, 'base')
380
381
        os.chdir('child')
382
        self.run_bzr('pull --overwrite ../other')
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
383
384
        # both the local and master should have been updated.
385
        self.check_revno(4)
386
        self.check_revno(4, '../base')