/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2012, 2016 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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy import (
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
21
    branch,
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
22
    controldir,
4988.7.2 by Vincent Ladeuil
Fix imports.
23
    errors,
24
    tests,
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
25
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
26
from breezy.tests import script
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
27
28
4988.7.2 by Vincent Ladeuil
Fix imports.
29
class TestBoundBranches(tests.TestCaseWithTransport):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
30
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
31
    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.
32
        base_tree = self.make_branch_and_tree('base')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
33
        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.
34
        self.build_tree(['base/a', 'base/b'])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
35
        base_tree.add(['a', 'b'])
36
        base_tree.commit('init')
37
        base_tree.unlock()
1607.1.14 by Robert Collins
Reduce lock thrashing somewhat - drops bound branch tests lock count from 6554 to 4456 locks.
38
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
39
        child_tree = base_tree.branch.create_checkout('child')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
40
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
41
        self.check_revno(1, 'child')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
42
        d = controldir.ControlDir.open('child')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
43
        self.assertNotEqual(None, d.open_branch().get_master_branch())
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
44
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
45
        return base_tree, child_tree
46
1607.1.14 by Robert Collins
Reduce lock thrashing somewhat - drops bound branch tests lock count from 6554 to 4456 locks.
47
    def check_revno(self, val, loc='.'):
48
        self.assertEqual(
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
49
            val, controldir.ControlDir.open(loc).open_branch().last_revision_info()[0])
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
50
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
51
    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.
52
        tree = self.make_branch_and_tree('base')
53
        self.build_tree(['base/a', 'base/b'])
7045.1.14 by Jelmer Vernooij
More fixes.
54
        tree.add('a', b'b')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
55
        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
56
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
57
        tree.controldir.sprout('child')
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
58
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
59
        self.run_bzr('bind ../base', working_dir='child')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
60
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
61
        d = controldir.ControlDir.open('child')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
62
        self.assertNotEqual(None, d.open_branch().get_master_branch())
63
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
64
        self.run_bzr('unbind', working_dir='child')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
65
        self.assertEqual(None, d.open_branch().get_master_branch())
66
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
67
        self.run_bzr('unbind', retcode=3, working_dir='child')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
68
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
69
    def test_bind_branch6(self):
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
70
        branch1 = self.make_branch('branch1', format='dirstate-tags')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
71
        error = self.run_bzr('bind', retcode=3, working_dir='branch1')[1]
72
        self.assertEndsWith(
73
            error, 'No location supplied and no previous location known\n')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
74
75
    def setup_rebind(self, format):
76
        branch1 = self.make_branch('branch1')
77
        branch2 = self.make_branch('branch2', format=format)
78
        branch2.bind(branch1)
79
        branch2.unbind()
80
81
    def test_rebind_branch6(self):
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
82
        self.setup_rebind('dirstate-tags')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
83
        self.run_bzr('bind', working_dir='branch2')
84
        b = branch.Branch.open('branch2')
85
        self.assertEndsWith(b.get_bound_location(), '/branch1/')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
86
87
    def test_rebind_branch5(self):
88
        self.setup_rebind('knit')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
89
        error = self.run_bzr('bind', retcode=3, working_dir='branch2')[1]
90
        self.assertEndsWith(
91
            error, 'No location supplied.  This format does not remember'
92
            ' old locations.\n')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
93
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
94
    def test_bound_commit(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
95
        child_tree = self.create_branches()[1]
96
6855.4.1 by Jelmer Vernooij
Yet more bees.
97
        self.build_tree_contents([('child/a', b'new contents')])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
98
        child_tree.commit(message='child')
99
100
        self.check_revno(2, 'child')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
101
102
        # Make sure it committed on the parent
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
103
        self.check_revno(2, 'base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
104
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
105
    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.
106
        # Make sure commit fails if out of date.
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
107
        base_tree, child_tree = self.create_branches()
108
109
        self.build_tree_contents([
7143.15.2 by Jelmer Vernooij
Run autopep8.
110
            ('base/a', b'new base contents\n'),
6855.4.1 by Jelmer Vernooij
Yet more bees.
111
            ('child/b', b'new b child contents\n')])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
112
        base_tree.commit(message='base')
113
        self.check_revno(2, 'base')
114
115
        self.check_revno(1, 'child')
116
        self.assertRaises(errors.BoundBranchOutOfDate, child_tree.commit,
7143.15.2 by Jelmer Vernooij
Run autopep8.
117
                          message='child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
118
        self.check_revno(1, 'child')
119
120
        child_tree.update()
121
        self.check_revno(2, 'child')
122
123
        child_tree.commit(message='child')
124
        self.check_revno(3, 'child')
125
        self.check_revno(3, 'base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
126
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
127
    def test_double_binding(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
128
        child_tree = self.create_branches()[1]
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
129
        child_tree.controldir.sprout('child2')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
130
1505.1.6 by John Arbash Meinel
Cleaned up tests and code, all bound branch tests succeed.
131
        # Double binding succeeds, but committing to child2 should fail
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
132
        self.run_bzr('bind ../child', working_dir='child2')
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
133
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
134
        # Refresh the child tree object as 'unbind' modified it
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
135
        child2_tree = controldir.ControlDir.open('child2').open_workingtree()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
136
        self.assertRaises(errors.CommitToDoubleBoundBranch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
137
                          child2_tree.commit, message='child2', allow_pointless=True)
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
138
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
139
    def test_unbinding(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
140
        base_tree, child_tree = self.create_branches()
141
142
        self.build_tree_contents([
7143.15.2 by Jelmer Vernooij
Run autopep8.
143
            ('base/a', b'new base contents\n'),
6855.4.1 by Jelmer Vernooij
Yet more bees.
144
            ('child/b', b'new b child contents\n')])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
145
146
        base_tree.commit(message='base')
147
        self.check_revno(2, 'base')
148
149
        self.check_revno(1, 'child')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
150
        self.run_bzr("commit -m child", retcode=3, working_dir='child')
151
        self.check_revno(1, 'child')
152
        self.run_bzr('unbind', working_dir='child')
6404.6.6 by Vincent Ladeuil
Use idioms coherently and add comments to make their purpose clearer.
153
        # Refresh the child tree/branch objects as 'unbind' modified them
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
154
        child_tree = child_tree.controldir.open_workingtree()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
155
        child_tree.commit(message='child')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
156
        self.check_revno(2, 'child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
157
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
158
    def test_commit_remote_bound(self):
159
        # It is not possible to commit to a branch
160
        # 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.
161
        base_tree, child_tree = self.create_branches()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
162
        base_tree.controldir.sprout('newbase')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
163
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
164
        # There is no way to know that B has already
165
        # been bound by someone else, otherwise it
166
        # might be nice if this would fail
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
167
        self.run_bzr('bind ../newbase', working_dir='base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
168
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
169
        self.run_bzr('commit -m failure --unchanged', retcode=3,
170
                     working_dir='child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
171
172
    def test_pull_updates_both(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
173
        base_tree = self.create_branches()[0]
7143.15.2 by Jelmer Vernooij
Run autopep8.
174
        newchild_tree = base_tree.controldir.sprout(
175
            'newchild').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
176
        self.build_tree_contents([('newchild/b', b'newchild b contents\n')])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
177
        newchild_tree.commit(message='newchild')
178
        self.check_revno(2, 'newchild')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
179
180
        # The pull should succeed, and update
181
        # the bound parent branch
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
182
        self.run_bzr('pull ../newchild', working_dir='child')
183
        self.check_revno(2, 'child')
184
        self.check_revno(2, 'base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
185
4056.6.2 by Gary van der Merwe
Implement test for pull --local
186
    def test_pull_local_updates_local(self):
187
        base_tree = self.create_branches()[0]
7143.15.2 by Jelmer Vernooij
Run autopep8.
188
        newchild_tree = base_tree.controldir.sprout(
189
            'newchild').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
190
        self.build_tree_contents([('newchild/b', b'newchild b contents\n')])
4056.6.2 by Gary van der Merwe
Implement test for pull --local
191
        newchild_tree.commit(message='newchild')
192
        self.check_revno(2, 'newchild')
193
194
        # The pull should succeed, and update
195
        # the bound parent branch
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
196
        self.run_bzr('pull ../newchild --local', working_dir='child')
197
        self.check_revno(2, 'child')
198
        self.check_revno(1, 'base')
4056.6.2 by Gary van der Merwe
Implement test for pull --local
199
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
200
    def test_bind_diverged(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
201
        base_tree, child_tree = self.create_branches()
202
        base_branch = base_tree.branch
203
        child_branch = child_tree.branch
204
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
205
        self.run_bzr('unbind', working_dir='child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
206
6404.6.6 by Vincent Ladeuil
Use idioms coherently and add comments to make their purpose clearer.
207
        # Refresh the child tree/branch objects as 'unbind' modified them
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
208
        child_tree = child_tree.controldir.open_workingtree()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
209
        child_tree.commit(message='child', allow_pointless=True)
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
210
        self.check_revno(2, 'child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
211
212
        self.check_revno(1, 'base')
213
        base_tree.commit(message='base', allow_pointless=True)
214
        self.check_revno(2, 'base')
215
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
216
        # These branches have diverged, but bind should succeed anyway
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
217
        self.run_bzr('bind ../base', working_dir='child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
218
6404.6.6 by Vincent Ladeuil
Use idioms coherently and add comments to make their purpose clearer.
219
        # Refresh the child tree/branch objects as 'bind' modified them
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
220
        child_tree = child_tree.controldir.open_workingtree()
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
221
        # This should turn the local commit into a merge
222
        child_tree.update()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
223
        child_tree.commit(message='merged')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
224
        self.check_revno(3, 'child')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
225
        self.assertEqual(child_tree.branch.last_revision(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
226
                         base_tree.branch.last_revision())
6165.2.3 by Jelmer Vernooij
Reintroduce check of history.
227
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
228
    def test_bind_parent_ahead(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
229
        base_tree = self.create_branches()[0]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
230
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
231
        self.run_bzr('unbind', working_dir='child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
232
233
        base_tree.commit(message='base', allow_pointless=True)
234
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
235
        self.check_revno(1, 'child')
236
        self.run_bzr('bind ../base', working_dir='child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
237
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
238
        # binding does not pull data:
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
239
        self.check_revno(1, 'child')
240
        self.run_bzr('unbind', working_dir='child')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
241
242
        # 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.
243
        base_tree.commit(message='base 3', allow_pointless=True)
244
        base_tree.commit(message='base 4', allow_pointless=True)
245
        base_tree.commit(message='base 5', allow_pointless=True)
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
246
        self.check_revno(5, 'base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
247
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
248
        self.check_revno(1, 'child')
249
        self.run_bzr('bind ../base', working_dir='child')
250
        self.check_revno(1, 'child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
251
252
    def test_bind_child_ahead(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
253
        # 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
254
        # childs - it should bind ok but the revision histories should not
255
        # be altered
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
256
        child_tree = self.create_branches()[1]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
257
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
258
        self.run_bzr('unbind', working_dir='child')
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
259
        # Refresh the child tree/branch objects as 'bind' modified them
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
260
        child_tree = child_tree.controldir.open_workingtree()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
261
        child_tree.commit(message='child', allow_pointless=True)
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
262
        self.check_revno(2, 'child')
263
        self.check_revno(1, 'base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
264
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
265
        self.run_bzr('bind ../base', working_dir='child')
266
        self.check_revno(1, 'base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
267
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
268
        # Check and make sure it also works if child is ahead multiple
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
269
        self.run_bzr('unbind', working_dir='child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
270
        child_tree.commit(message='child 3', allow_pointless=True)
271
        child_tree.commit(message='child 4', allow_pointless=True)
272
        child_tree.commit(message='child 5', allow_pointless=True)
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
273
        self.check_revno(5, 'child')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
274
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
275
        self.check_revno(1, 'base')
276
        self.run_bzr('bind ../base', working_dir='child')
277
        self.check_revno(1, 'base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
278
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
279
    def test_bind_fail_if_missing(self):
280
        """We should not be able to bind to a missing branch."""
281
        tree = self.make_branch_and_tree('tree_1')
282
        tree.commit('dummy commit')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
283
        self.run_bzr_error(['Not a branch.*no-such-branch/'],
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
284
                           ['bind', '../no-such-branch'],
285
                           working_dir='tree_1')
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
286
        self.assertIs(None, tree.branch.get_bound_location())
287
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
288
    def test_commit_after_merge(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
289
        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
290
291
        # We want merge to be able to be a local only
292
        # operation, because it can be without violating
293
        # the binding invariants.
294
        # But we can't fail afterwards
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
295
        other_tree = child_tree.controldir.sprout('other').open_workingtree()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
296
        other_branch = other_tree.branch
297
6855.4.1 by Jelmer Vernooij
Yet more bees.
298
        self.build_tree_contents([('other/c', b'file c\n')])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
299
        other_tree.add('c')
300
        other_tree.commit(message='adding c')
6165.4.2 by Jelmer Vernooij
Deprecate revision_history.
301
        new_rev_id = other_branch.last_revision()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
302
303
        child_tree.merge_from_branch(other_branch)
304
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
305
        self.assertPathExists('child/c')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
306
        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
307
308
        # 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.
309
        self.assertTrue(child_tree.branch.repository.has_revision(new_rev_id))
310
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
311
        # 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.
312
        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
313
314
        # Commit should succeed, and cause merged revisions to
315
        # be pulled into base
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
316
        self.run_bzr(['commit', '-m', 'merge other'], working_dir='child')
317
        self.check_revno(2, 'child')
318
        self.check_revno(2, 'base')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
319
        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
320
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
321
    def test_pull_overwrite(self):
322
        # 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.
323
        child_tree = self.create_branches()[1]
324
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
325
        other_tree = child_tree.controldir.sprout('other').open_workingtree()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
326
6855.4.1 by Jelmer Vernooij
Yet more bees.
327
        self.build_tree_contents([('other/a', b'new contents\n')])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
328
        other_tree.commit(message='changed a')
329
        self.check_revno(2, 'other')
330
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
331
            ('other/a', b'new contents\nand then some\n')])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
332
        other_tree.commit(message='another a')
333
        self.check_revno(3, 'other')
334
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
335
            ('other/a', b'new contents\nand then some\nand some more\n')])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
336
        other_tree.commit('yet another a')
337
        self.check_revno(4, 'other')
338
6855.4.1 by Jelmer Vernooij
Yet more bees.
339
        self.build_tree_contents([('child/a', b'also changed a\n')])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
340
        child_tree.commit(message='child modified a')
341
342
        self.check_revno(2, 'child')
343
        self.check_revno(2, 'base')
344
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
345
        self.run_bzr('pull --overwrite ../other', working_dir='child')
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
346
347
        # both the local and master should have been updated.
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
348
        self.check_revno(4, 'child')
349
        self.check_revno(4, 'base')
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
350
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
351
    def test_bind_directory(self):
352
        """Test --directory option"""
353
        tree = self.make_branch_and_tree('base')
354
        self.build_tree(['base/a', 'base/b'])
7045.1.14 by Jelmer Vernooij
More fixes.
355
        tree.add('a', b'b')
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
356
        tree.commit(message='init')
357
        branch = tree.branch
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
358
        tree.controldir.sprout('child')
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
359
        self.run_bzr('bind --directory=child base')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
360
        d = controldir.ControlDir.open('child')
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
361
        self.assertNotEqual(None, d.open_branch().get_master_branch())
362
        self.run_bzr('unbind -d child')
363
        self.assertEqual(None, d.open_branch().get_master_branch())
364
        self.run_bzr('unbind --directory child', retcode=3)
365
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
366
367
class TestBind(script.TestCaseWithTransportAndScript):
368
369
    def test_bind_when_bound(self):
370
        self.run_script("""
6622.1.29 by Jelmer Vernooij
Fix some more tests.
371
$ brz init trunk
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
372
...
6622.1.29 by Jelmer Vernooij
Fix some more tests.
373
$ brz init copy
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
374
...
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
375
$ cd copy
6622.1.29 by Jelmer Vernooij
Fix some more tests.
376
$ brz bind ../trunk
377
$ brz bind
378
2>brz: ERROR: Branch is already bound
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
379
""")
380
381
    def test_bind_before_bound(self):
382
        self.run_script("""
6622.1.29 by Jelmer Vernooij
Fix some more tests.
383
$ brz init trunk
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
384
...
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
385
$ cd trunk
6622.1.29 by Jelmer Vernooij
Fix some more tests.
386
$ brz bind
387
2>brz: ERROR: No location supplied and no previous location known
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
388
""")