~bzr-pqm/bzr/bzr.dev

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
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,
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
    )
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()
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'])
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
54
        tree.add('a', 'b')
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
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
57
        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
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
97
        self.build_tree_contents([('child/a', 'new contents')])
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([
110
            ('base/a',  'new base contents\n'   ),
111
            ('child/b', 'new b child contents\n')])
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,
117
                                                            message='child')
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]
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.
129
        child_tree.bzrdir.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,
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([
143
            ('base/a',  'new base contents\n'   ),
144
            ('child/b', 'new b child contents\n')])
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
154
        child_tree = child_tree.bzrdir.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()
162
        base_tree.bzrdir.sprout('newbase')
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]
174
        newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
175
        self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
176
        newchild_tree.commit(message='newchild')
177
        self.check_revno(2, 'newchild')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
178
179
        # The pull should succeed, and update
180
        # 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.
181
        self.run_bzr('pull ../newchild', working_dir='child')
182
        self.check_revno(2, 'child')
183
        self.check_revno(2, 'base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
184
4056.6.2 by Gary van der Merwe
Implement test for pull --local
185
    def test_pull_local_updates_local(self):
186
        base_tree = self.create_branches()[0]
187
        newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
188
        self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
189
        newchild_tree.commit(message='newchild')
190
        self.check_revno(2, 'newchild')
191
192
        # The pull should succeed, and update
193
        # 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.
194
        self.run_bzr('pull ../newchild --local', working_dir='child')
195
        self.check_revno(2, 'child')
196
        self.check_revno(1, 'base')
4056.6.2 by Gary van der Merwe
Implement test for pull --local
197
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
198
    def test_bind_diverged(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
199
        base_tree, child_tree = self.create_branches()
200
        base_branch = base_tree.branch
201
        child_branch = child_tree.branch
202
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.
203
        self.run_bzr('unbind', working_dir='child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
204
6404.6.6 by Vincent Ladeuil
Use idioms coherently and add comments to make their purpose clearer.
205
        # Refresh the child tree/branch objects as 'unbind' modified them
206
        child_tree = child_tree.bzrdir.open_workingtree()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
207
        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.
208
        self.check_revno(2, 'child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
209
210
        self.check_revno(1, 'base')
211
        base_tree.commit(message='base', allow_pointless=True)
212
        self.check_revno(2, 'base')
213
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
214
        # 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.
215
        self.run_bzr('bind ../base', working_dir='child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
216
6404.6.6 by Vincent Ladeuil
Use idioms coherently and add comments to make their purpose clearer.
217
        # Refresh the child tree/branch objects as 'bind' modified them
218
        child_tree = child_tree.bzrdir.open_workingtree()
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
219
        # This should turn the local commit into a merge
220
        child_tree.update()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
221
        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.
222
        self.check_revno(3, 'child')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
223
        self.assertEqual(child_tree.branch.last_revision(),
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
                          base_tree.branch.last_revision())
6165.2.3 by Jelmer Vernooij
Reintroduce check of history.
225
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
226
    def test_bind_parent_ahead(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
227
        base_tree = self.create_branches()[0]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
228
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.
229
        self.run_bzr('unbind', working_dir='child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
230
231
        base_tree.commit(message='base', allow_pointless=True)
232
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.
233
        self.check_revno(1, 'child')
234
        self.run_bzr('bind ../base', working_dir='child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
235
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
236
        # 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.
237
        self.check_revno(1, 'child')
238
        self.run_bzr('unbind', working_dir='child')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
239
240
        # 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.
241
        base_tree.commit(message='base 3', allow_pointless=True)
242
        base_tree.commit(message='base 4', allow_pointless=True)
243
        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.
244
        self.check_revno(5, 'base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
245
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(1, 'child')
247
        self.run_bzr('bind ../base', working_dir='child')
248
        self.check_revno(1, 'child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
249
250
    def test_bind_child_ahead(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
251
        # 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
252
        # childs - it should bind ok but the revision histories should not
253
        # be altered
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
254
        child_tree = self.create_branches()[1]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
255
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.
256
        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.
257
        # 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.
258
        child_tree = child_tree.bzrdir.open_workingtree()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
259
        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.
260
        self.check_revno(2, 'child')
261
        self.check_revno(1, 'base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
262
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.
263
        self.run_bzr('bind ../base', working_dir='child')
264
        self.check_revno(1, 'base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
265
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
266
        # 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.
267
        self.run_bzr('unbind', working_dir='child')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
268
        child_tree.commit(message='child 3', allow_pointless=True)
269
        child_tree.commit(message='child 4', allow_pointless=True)
270
        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.
271
        self.check_revno(5, 'child')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
272
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(1, 'base')
274
        self.run_bzr('bind ../base', working_dir='child')
275
        self.check_revno(1, 'base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
276
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
277
    def test_bind_fail_if_missing(self):
278
        """We should not be able to bind to a missing branch."""
279
        tree = self.make_branch_and_tree('tree_1')
280
        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.
281
        self.run_bzr_error(['Not a branch.*no-such-branch/'],
282
                           ['bind', '../no-such-branch'],
283
                           working_dir='tree_1')
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
284
        self.assertIs(None, tree.branch.get_bound_location())
285
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
286
    def test_commit_after_merge(self):
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
287
        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
288
289
        # We want merge to be able to be a local only
290
        # operation, because it can be without violating
291
        # the binding invariants.
292
        # But we can't fail afterwards
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
293
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
294
        other_branch = other_tree.branch
295
296
        self.build_tree_contents([('other/c', 'file c\n')])
297
        other_tree.add('c')
298
        other_tree.commit(message='adding c')
6165.4.2 by Jelmer Vernooij
Deprecate revision_history.
299
        new_rev_id = other_branch.last_revision()
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
300
301
        child_tree.merge_from_branch(other_branch)
302
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
303
        self.assertPathExists('child/c')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
304
        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
305
306
        # 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.
307
        self.assertTrue(child_tree.branch.repository.has_revision(new_rev_id))
308
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
309
        # 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.
310
        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
311
312
        # Commit should succeed, and cause merged revisions to
313
        # 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.
314
        self.run_bzr(['commit', '-m', 'merge other'], working_dir='child')
315
        self.check_revno(2, 'child')
316
        self.check_revno(2, 'base')
2664.8.1 by Daniel Watkins
tests.blackbox.test_bound_branches now uses internals where appropriate.
317
        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
318
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
319
    def test_pull_overwrite(self):
320
        # 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.
321
        child_tree = self.create_branches()[1]
322
323
        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
324
325
        self.build_tree_contents([('other/a', 'new contents\n')])
326
        other_tree.commit(message='changed a')
327
        self.check_revno(2, 'other')
328
        self.build_tree_contents([
329
            ('other/a', 'new contents\nand then some\n')])
330
        other_tree.commit(message='another a')
331
        self.check_revno(3, 'other')
332
        self.build_tree_contents([
333
            ('other/a', 'new contents\nand then some\nand some more\n')])
334
        other_tree.commit('yet another a')
335
        self.check_revno(4, 'other')
336
337
        self.build_tree_contents([('child/a', 'also changed a\n')])
338
        child_tree.commit(message='child modified a')
339
340
        self.check_revno(2, 'child')
341
        self.check_revno(2, 'base')
342
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.
343
        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
344
345
        # 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.
346
        self.check_revno(4, 'child')
347
        self.check_revno(4, 'base')
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
348
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
349
    def test_bind_directory(self):
350
        """Test --directory option"""
351
        tree = self.make_branch_and_tree('base')
352
        self.build_tree(['base/a', 'base/b'])
353
        tree.add('a', 'b')
354
        tree.commit(message='init')
355
        branch = tree.branch
356
        tree.bzrdir.sprout('child')
357
        self.run_bzr('bind --directory=child base')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
358
        d = controldir.ControlDir.open('child')
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
359
        self.assertNotEqual(None, d.open_branch().get_master_branch())
360
        self.run_bzr('unbind -d child')
361
        self.assertEqual(None, d.open_branch().get_master_branch())
362
        self.run_bzr('unbind --directory child', retcode=3)
363
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
364
365
class TestBind(script.TestCaseWithTransportAndScript):
366
367
    def test_bind_when_bound(self):
368
        self.run_script("""
369
$ bzr init trunk
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
370
...
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
371
$ bzr init copy
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
372
...
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
373
$ cd copy
374
$ bzr bind ../trunk
375
$ bzr bind
376
2>bzr: ERROR: Branch is already bound
377
""")
378
379
    def test_bind_before_bound(self):
380
        self.run_script("""
381
$ bzr init trunk
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
382
...
4988.7.1 by Neil Martinsen-Burrell
better error message for bzr bind on and already bound branch
383
$ cd trunk
384
$ bzr bind
385
2>bzr: ERROR: No location supplied and no previous location known
386
""")