~bzr-pqm/bzr/bzr.dev

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