/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):
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
4056.6.2 by Gary van der Merwe
Implement test for pull --local
231
    def test_pull_local_updates_local(self):
232
        base_tree = self.create_branches()[0]
233
        newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
234
        self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
235
        newchild_tree.commit(message='newchild')
236
        self.check_revno(2, 'newchild')
237
238
        os.chdir('child')
239
        # The pull should succeed, and update
240
        # the bound parent branch
241
        self.run_bzr('pull ../newchild --local')
242
        self.check_revno(2)
243
244
        self.check_revno(1, '../base')
245
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
246
    def test_bind_diverged(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
247
        base_tree, child_tree = self.create_branches()
248
        base_branch = base_tree.branch
249
        child_branch = child_tree.branch
250
251
        os.chdir('child')
252
        self.run_bzr('unbind')
253
254
        child_tree.commit(message='child', allow_pointless=True)
255
        self.check_revno(2)
256
257
        os.chdir('..')
258
        self.check_revno(1, 'base')
259
        base_tree.commit(message='base', allow_pointless=True)
260
        self.check_revno(2, 'base')
261
262
        os.chdir('child')
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
263
        # These branches have diverged, but bind should succeed anyway
264
        self.run_bzr('bind ../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
265
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
266
        # This should turn the local commit into a merge
267
        child_tree.update()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
268
        child_tree.commit(message='merged')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
269
        self.check_revno(3)
270
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
271
        # After binding, the revision history should be unaltered
272
        # take a copy before
273
        base_history = base_branch.revision_history()
274
        child_history = child_branch.revision_history()
275
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
276
    def test_bind_parent_ahead(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
277
        base_tree = self.create_branches()[0]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
278
279
        os.chdir('child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
280
        self.run_bzr('unbind')
281
282
        base_tree.commit(message='base', allow_pointless=True)
283
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
284
        self.check_revno(1)
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
285
        self.run_bzr('bind ../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
286
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
287
        # binding does not pull data:
288
        self.check_revno(1)
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
289
        self.run_bzr('unbind')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
290
291
        # 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.
292
        base_tree.commit(message='base 3', allow_pointless=True)
293
        base_tree.commit(message='base 4', allow_pointless=True)
294
        base_tree.commit(message='base 5', allow_pointless=True)
295
        self.check_revno(5, '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
296
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
297
        self.check_revno(1)
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)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
300
301
    def test_bind_child_ahead(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
302
        # 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
303
        # childs - it should bind ok but the revision histories should not
304
        # be altered
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
305
        child_tree = self.create_branches()[1]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
306
307
        os.chdir('child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
308
        self.run_bzr('unbind')
309
        child_tree.commit(message='child', allow_pointless=True)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
310
        self.check_revno(2)
311
        self.check_revno(1, '../base')
312
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
313
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
314
        self.check_revno(1, '../base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
315
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
316
        # 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.
317
        self.run_bzr('unbind')
318
        child_tree.commit(message='child 3', allow_pointless=True)
319
        child_tree.commit(message='child 4', allow_pointless=True)
320
        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.
321
        self.check_revno(5)
322
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
323
        self.check_revno(1, '../base')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
324
        self.run_bzr('bind ../base')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
325
        self.check_revno(1, '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
326
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
327
    def test_bind_fail_if_missing(self):
328
        """We should not be able to bind to a missing branch."""
329
        tree = self.make_branch_and_tree('tree_1')
330
        tree.commit('dummy commit')
331
        self.run_bzr_error(['Not a branch.*no-such-branch/'], ['bind', '../no-such-branch'],
332
                            working_dir='tree_1')
333
        self.assertIs(None, tree.branch.get_bound_location())
334
3565.6.11 by Marius Kruger
Bind now updates explicit nicks
335
    def test_bind_nick(self):
336
        """Bind should not update implicit nick."""
337
        base = self.make_branch_and_tree('base')
338
        child = self.make_branch_and_tree('child')
339
        os.chdir('child')
340
        self.assertEqual(child.branch.nick, 'child')
341
        self.assertEqual(child.branch.get_config().has_explicit_nickname(),
342
            False)
343
        self.run_bzr('bind ../base')
344
        self.assertEqual(child.branch.nick, base.branch.nick)
345
        self.assertEqual(child.branch.get_config().has_explicit_nickname(),
346
            False)
347
348
    def test_bind_explicit_nick(self):
349
        """Bind should update explicit nick."""
350
        base = self.make_branch_and_tree('base')
351
        child = self.make_branch_and_tree('child')
352
        os.chdir('child')
353
        child.branch.nick = "explicit_nick"
354
        self.assertEqual(child.branch.nick, "explicit_nick")
355
        self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
356
            "explicit_nick")
357
        self.run_bzr('bind ../base')
358
        self.assertEqual(child.branch.nick, base.branch.nick)
359
        self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
360
            base.branch.nick)
361
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
362
    def test_commit_after_merge(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
363
        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
364
365
        # We want merge to be able to be a local only
366
        # operation, because it can be without violating
367
        # the binding invariants.
368
        # But we can't fail afterwards
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
369
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
370
        other_branch = other_tree.branch
371
372
        self.build_tree_contents([('other/c', 'file c\n')])
373
        other_tree.add('c')
374
        other_tree.commit(message='adding c')
375
        new_rev_id = other_branch.revision_history()[-1]
376
377
        child_tree.merge_from_branch(other_branch)
378
379
        self.failUnlessExists('child/c')
380
        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
381
382
        # 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.
383
        self.assertTrue(child_tree.branch.repository.has_revision(new_rev_id))
384
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
385
        # 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.
386
        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
387
388
        # Commit should succeed, and cause merged revisions to
389
        # be pulled into base
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
390
        os.chdir('child')
391
        self.run_bzr(['commit', '-m', 'merge other'])
392
393
        self.check_revno(2)
394
395
        self.check_revno(2, '../base')
396
397
        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
398
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
399
    def test_pull_overwrite(self):
400
        # 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.
401
        child_tree = self.create_branches()[1]
402
403
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
404
405
        self.build_tree_contents([('other/a', 'new contents\n')])
406
        other_tree.commit(message='changed a')
407
        self.check_revno(2, 'other')
408
        self.build_tree_contents([
409
            ('other/a', 'new contents\nand then some\n')])
410
        other_tree.commit(message='another a')
411
        self.check_revno(3, 'other')
412
        self.build_tree_contents([
413
            ('other/a', 'new contents\nand then some\nand some more\n')])
414
        other_tree.commit('yet another a')
415
        self.check_revno(4, 'other')
416
417
        self.build_tree_contents([('child/a', 'also changed a\n')])
418
        child_tree.commit(message='child modified a')
419
420
        self.check_revno(2, 'child')
421
        self.check_revno(2, 'base')
422
423
        os.chdir('child')
424
        self.run_bzr('pull --overwrite ../other')
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
425
426
        # both the local and master should have been updated.
427
        self.check_revno(4)
428
        self.check_revno(4, '../base')