/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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
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):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
36
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
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')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
44
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
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)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
54
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
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):
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
67
        base_tree = self.make_branch_and_tree('base')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
68
        base_tree.lock_write()
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
69
        self.build_tree(['base/a', 'base/b'])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
70
        base_tree.add(['a', 'b'])
71
        base_tree.commit('init')
72
        base_tree.unlock()
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
73
        branch = base_tree.branch
1607.1.14 by Robert Collins
Reduce lock thrashing somewhat - drops bound branch tests lock count from 6554 to 4456 locks.
74
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
75
        child_tree = branch.create_checkout('child')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
76
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
77
        self.check_revno(1, 'child')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
78
        d = BzrDir.open('child')
79
        self.assertNotEqual(None, d.open_branch().get_master_branch())
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
80
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
81
        return base_tree, child_tree
82
1607.1.14 by Robert Collins
Reduce lock thrashing somewhat - drops bound branch tests lock count from 6554 to 4456 locks.
83
    def check_revno(self, val, loc='.'):
84
        self.assertEqual(
85
            val, len(BzrDir.open(loc).open_branch().revision_history()))
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
86
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
87
    def test_simple_binding(self):
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
88
        tree = self.make_branch_and_tree('base')
89
        self.build_tree(['base/a', 'base/b'])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
90
        tree.add('a', 'b')
91
        tree.commit(message='init')
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
92
        branch = tree.branch
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
93
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
94
        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
95
96
        os.chdir('child')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
97
        self.run_bzr('bind ../base')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
98
99
        d = BzrDir.open('')
100
        self.assertNotEqual(None, d.open_branch().get_master_branch())
101
102
        self.run_bzr('unbind')
103
        self.assertEqual(None, d.open_branch().get_master_branch())
104
105
        self.run_bzr('unbind', retcode=3)
106
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
107
    def test_bind_branch6(self):
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
108
        branch1 = self.make_branch('branch1', format='dirstate-tags')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
109
        os.chdir('branch1')
110
        error = self.run_bzr('bind', retcode=3)[1]
2230.3.48 by Aaron Bentley
Update blackbox test to handle new error message
111
        self.assertContainsRe(error, 'no previous location known')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
112
113
    def setup_rebind(self, format):
114
        branch1 = self.make_branch('branch1')
115
        branch2 = self.make_branch('branch2', format=format)
116
        branch2.bind(branch1)
117
        branch2.unbind()
118
119
    def test_rebind_branch6(self):
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
120
        self.setup_rebind('dirstate-tags')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
121
        os.chdir('branch2')
122
        self.run_bzr('bind')
123
        b = Branch.open('.')
124
        self.assertContainsRe(b.get_bound_location(), '\/branch1\/$')
125
126
    def test_rebind_branch5(self):
127
        self.setup_rebind('knit')
128
        os.chdir('branch2')
129
        error = self.run_bzr('bind', retcode=3)[1]
130
        self.assertContainsRe(error, 'old locations')
131
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
132
    def test_bound_commit(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
133
        child_tree = self.create_branches()[1]
134
135
        self.build_tree_contents([('child/a', 'new contents')])
136
        child_tree.commit(message='child')
137
138
        self.check_revno(2, 'child')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
139
140
        # Make sure it committed on the parent
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
141
        self.check_revno(2, 'base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
142
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
143
    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.
144
        # Make sure commit fails if out of date.
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
145
        base_tree, child_tree = self.create_branches()
146
147
        self.build_tree_contents([
148
            ('base/a',  'new base contents\n'   ),
149
            ('child/b', 'new b child contents\n')])
150
        base_tree.commit(message='base')
151
        self.check_revno(2, 'base')
152
153
        self.check_revno(1, 'child')
154
        self.assertRaises(errors.BoundBranchOutOfDate, child_tree.commit,
155
                                                            message='child')
156
        self.check_revno(1, 'child')
157
158
        child_tree.update()
159
        self.check_revno(2, 'child')
160
161
        child_tree.commit(message='child')
162
        self.check_revno(3, 'child')
163
        self.check_revno(3, 'base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
164
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
165
    def test_double_binding(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
166
        child_tree = self.create_branches()[1]
167
168
        child2_tree = child_tree.bzrdir.sprout('child2').open_workingtree()
169
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
170
        os.chdir('child2')
1505.1.6 by John Arbash Meinel
Cleaned up tests and code, all bound branch tests succeed.
171
        # 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.
172
        self.run_bzr('bind ../child')
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
173
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
174
        self.assertRaises(errors.CommitToDoubleBoundBranch,
175
                child2_tree.commit, message='child2', allow_pointless=True)
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
176
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
177
    def test_unbinding(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
178
        base_tree, child_tree = self.create_branches()
179
180
        self.build_tree_contents([
181
            ('base/a',  'new base contents\n'   ),
182
            ('child/b', 'new b child contents\n')])
183
184
        base_tree.commit(message='base')
185
        self.check_revno(2, 'base')
186
187
        self.check_revno(1, 'child')
188
        os.chdir('child')
189
        self.run_bzr("commit -m child", retcode=3)
190
        self.check_revno(1)
191
        self.run_bzr('unbind')
192
        child_tree.commit(message='child')
193
        self.check_revno(2)
194
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
195
    def test_commit_remote_bound(self):
196
        # It is not possible to commit to a branch
197
        # 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.
198
        base_tree, child_tree = self.create_branches()
199
        base_tree.bzrdir.sprout('newbase')
200
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
201
        os.chdir('base')
202
        # There is no way to know that B has already
203
        # been bound by someone else, otherwise it
204
        # might be nice if this would fail
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
205
        self.run_bzr('bind ../newbase')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
206
207
        os.chdir('../child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
208
        self.run_bzr('commit -m failure --unchanged', retcode=3)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
209
210
    def test_pull_updates_both(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
211
        base_tree = self.create_branches()[0]
212
        newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
213
        self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
214
        newchild_tree.commit(message='newchild')
215
        self.check_revno(2, 'newchild')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
216
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
217
        os.chdir('child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
218
        # The pull should succeed, and update
219
        # the bound parent branch
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
220
        self.run_bzr('pull ../newchild')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
221
        self.check_revno(2)
222
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
223
        self.check_revno(2, '../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
224
4056.6.2 by Gary van der Merwe
Implement test for pull --local
225
    def test_pull_local_updates_local(self):
226
        base_tree = self.create_branches()[0]
227
        newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
228
        self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
229
        newchild_tree.commit(message='newchild')
230
        self.check_revno(2, 'newchild')
231
232
        os.chdir('child')
233
        # The pull should succeed, and update
234
        # the bound parent branch
235
        self.run_bzr('pull ../newchild --local')
236
        self.check_revno(2)
237
238
        self.check_revno(1, '../base')
239
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
240
    def test_bind_diverged(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
241
        base_tree, child_tree = self.create_branches()
242
        base_branch = base_tree.branch
243
        child_branch = child_tree.branch
244
245
        os.chdir('child')
246
        self.run_bzr('unbind')
247
248
        child_tree.commit(message='child', allow_pointless=True)
249
        self.check_revno(2)
250
251
        os.chdir('..')
252
        self.check_revno(1, 'base')
253
        base_tree.commit(message='base', allow_pointless=True)
254
        self.check_revno(2, 'base')
255
256
        os.chdir('child')
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
257
        # These branches have diverged, but bind should succeed anyway
258
        self.run_bzr('bind ../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
259
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
260
        # This should turn the local commit into a merge
261
        child_tree.update()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
262
        child_tree.commit(message='merged')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
263
        self.check_revno(3)
264
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
265
        # After binding, the revision history should be unaltered
266
        # take a copy before
267
        base_history = base_branch.revision_history()
268
        child_history = child_branch.revision_history()
269
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
270
    def test_bind_parent_ahead(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
271
        base_tree = self.create_branches()[0]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
272
273
        os.chdir('child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
274
        self.run_bzr('unbind')
275
276
        base_tree.commit(message='base', allow_pointless=True)
277
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
278
        self.check_revno(1)
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
279
        self.run_bzr('bind ../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
280
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
281
        # binding does not pull data:
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('unbind')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
284
285
        # 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.
286
        base_tree.commit(message='base 3', allow_pointless=True)
287
        base_tree.commit(message='base 4', allow_pointless=True)
288
        base_tree.commit(message='base 5', allow_pointless=True)
289
        self.check_revno(5, '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
290
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
291
        self.check_revno(1)
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
292
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
293
        self.check_revno(1)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
294
295
    def test_bind_child_ahead(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
296
        # 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
297
        # childs - it should bind ok but the revision histories should not
298
        # be altered
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
299
        child_tree = self.create_branches()[1]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
300
301
        os.chdir('child')
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', allow_pointless=True)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
304
        self.check_revno(2)
305
        self.check_revno(1, '../base')
306
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
307
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
308
        self.check_revno(1, '../base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
309
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
310
        # 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.
311
        self.run_bzr('unbind')
312
        child_tree.commit(message='child 3', allow_pointless=True)
313
        child_tree.commit(message='child 4', allow_pointless=True)
314
        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.
315
        self.check_revno(5)
316
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
317
        self.check_revno(1, '../base')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
318
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
319
        self.check_revno(1, '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
320
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
321
    def test_bind_fail_if_missing(self):
322
        """We should not be able to bind to a missing branch."""
323
        tree = self.make_branch_and_tree('tree_1')
324
        tree.commit('dummy commit')
325
        self.run_bzr_error(['Not a branch.*no-such-branch/'], ['bind', '../no-such-branch'],
326
                            working_dir='tree_1')
327
        self.assertIs(None, tree.branch.get_bound_location())
328
3565.6.11 by Marius Kruger
Bind now updates explicit nicks
329
    def test_bind_nick(self):
330
        """Bind should not update implicit nick."""
331
        base = self.make_branch_and_tree('base')
332
        child = self.make_branch_and_tree('child')
333
        os.chdir('child')
334
        self.assertEqual(child.branch.nick, 'child')
335
        self.assertEqual(child.branch.get_config().has_explicit_nickname(),
336
            False)
337
        self.run_bzr('bind ../base')
338
        self.assertEqual(child.branch.nick, base.branch.nick)
339
        self.assertEqual(child.branch.get_config().has_explicit_nickname(),
340
            False)
341
342
    def test_bind_explicit_nick(self):
343
        """Bind should update explicit nick."""
344
        base = self.make_branch_and_tree('base')
345
        child = self.make_branch_and_tree('child')
346
        os.chdir('child')
347
        child.branch.nick = "explicit_nick"
348
        self.assertEqual(child.branch.nick, "explicit_nick")
349
        self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
350
            "explicit_nick")
351
        self.run_bzr('bind ../base')
352
        self.assertEqual(child.branch.nick, base.branch.nick)
353
        self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
354
            base.branch.nick)
355
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
356
    def test_commit_after_merge(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
357
        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
358
359
        # We want merge to be able to be a local only
360
        # operation, because it can be without violating
361
        # the binding invariants.
362
        # But we can't fail afterwards
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
363
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
364
        other_branch = other_tree.branch
365
366
        self.build_tree_contents([('other/c', 'file c\n')])
367
        other_tree.add('c')
368
        other_tree.commit(message='adding c')
369
        new_rev_id = other_branch.revision_history()[-1]
370
371
        child_tree.merge_from_branch(other_branch)
372
373
        self.failUnlessExists('child/c')
374
        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
375
376
        # 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.
377
        self.assertTrue(child_tree.branch.repository.has_revision(new_rev_id))
378
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
379
        # 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.
380
        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
381
382
        # Commit should succeed, and cause merged revisions to
383
        # be pulled into base
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
384
        os.chdir('child')
385
        self.run_bzr(['commit', '-m', 'merge other'])
386
387
        self.check_revno(2)
388
389
        self.check_revno(2, '../base')
390
391
        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
392
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
393
    def test_pull_overwrite(self):
394
        # 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.
395
        child_tree = self.create_branches()[1]
396
397
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
398
399
        self.build_tree_contents([('other/a', 'new contents\n')])
400
        other_tree.commit(message='changed a')
401
        self.check_revno(2, 'other')
402
        self.build_tree_contents([
403
            ('other/a', 'new contents\nand then some\n')])
404
        other_tree.commit(message='another a')
405
        self.check_revno(3, 'other')
406
        self.build_tree_contents([
407
            ('other/a', 'new contents\nand then some\nand some more\n')])
408
        other_tree.commit('yet another a')
409
        self.check_revno(4, 'other')
410
411
        self.build_tree_contents([('child/a', 'also changed a\n')])
412
        child_tree.commit(message='child modified a')
413
414
        self.check_revno(2, 'child')
415
        self.check_revno(2, 'base')
416
417
        os.chdir('child')
418
        self.run_bzr('pull --overwrite ../other')
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
419
420
        # both the local and master should have been updated.
421
        self.check_revno(4)
422
        self.check_revno(4, '../base')