~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_bound_branches.py

[merge] robertc's integration, updated tests to check for retcode=3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
"""Tests of bound branches (binding, unbinding, commit, etc) command.
 
19
 
 
20
"""
 
21
 
 
22
import os
 
23
from cStringIO import StringIO
 
24
 
 
25
from bzrlib.selftest import TestCaseInTempDir
 
26
from bzrlib.branch import Branch
 
27
 
 
28
class TestBoundBranches(TestCaseInTempDir):
 
29
    
 
30
    def create_branches(self):
 
31
        bzr = self.run_bzr
 
32
        self.build_tree(['base/', 'base/a', 'base/b'])
 
33
 
 
34
        os.chdir('base')
 
35
        bzr('init')
 
36
        bzr('add')
 
37
        bzr('commit', '-m', 'init')
 
38
 
 
39
        os.chdir('..')
 
40
 
 
41
        bzr('get', '--bound', 'base', 'child')
 
42
 
 
43
        self.failUnlessExists('child')
 
44
 
 
45
        os.chdir('child')
 
46
        self.check_revno(1)
 
47
        self.failUnlessExists('.bzr/bound')
 
48
        os.chdir('..')
 
49
 
 
50
    def check_revno(self, val, loc=None):
 
51
        if loc is not None:
 
52
            cwd = os.getcwd()
 
53
            os.chdir(loc)
 
54
        self.assertEquals(self.capture('revno').strip(), str(val))
 
55
        if loc is not None:
 
56
            os.chdir(cwd)
 
57
 
 
58
    def test_simple_binding(self):
 
59
        bzr = self.run_bzr
 
60
        self.build_tree(['base/', 'base/a', 'base/b'])
 
61
 
 
62
        os.chdir('base')
 
63
        bzr('init')
 
64
        bzr('add')
 
65
        bzr('commit', '-m', 'init')
 
66
 
 
67
        os.chdir('..')
 
68
        bzr('branch', 'base', 'child')
 
69
 
 
70
        os.chdir('child')
 
71
        bzr('bind', '../base')
 
72
 
 
73
        self.failUnlessExists('.bzr/bound')
 
74
 
 
75
        bzr('unbind')
 
76
        self.failIf(os.path.lexists('.bzr/bound'))
 
77
 
 
78
        # TODO: Should unbinding a non-bound branch fail?
 
79
        #bzr('unbind')
 
80
 
 
81
    def test_bound_commit(self):
 
82
        bzr = self.run_bzr
 
83
        self.create_branches()
 
84
 
 
85
        os.chdir('child')
 
86
        open('a', 'wb').write('new contents\n')
 
87
        bzr('commit', '-m', 'child')
 
88
 
 
89
        self.check_revno(2)
 
90
 
 
91
        # Make sure it committed on the parent
 
92
        os.chdir('../base')
 
93
        self.check_revno(2)
 
94
 
 
95
    def test_bound_fail(self):
 
96
        """Make sure commit fails if out of date."""
 
97
        bzr = self.run_bzr
 
98
        self.create_branches()
 
99
 
 
100
        os.chdir('base')
 
101
        open('a', 'wb').write('new base contents\n')
 
102
        bzr('commit', '-m', 'base')
 
103
 
 
104
        os.chdir('../child')
 
105
        open('b', 'wb').write('new b child contents\n')
 
106
        bzr('commit', '-m', 'child', retcode=3)
 
107
 
 
108
        bzr('update')
 
109
        self.check_revno(2)
 
110
 
 
111
        bzr('commit', '-m', 'child')
 
112
        self.check_revno(3)
 
113
        os.chdir('../base')
 
114
        self.check_revno(3)
 
115
 
 
116
    def test_double_binding(self):
 
117
        bzr = self.run_bzr
 
118
        self.create_branches()
 
119
 
 
120
        bzr('branch', 'child', 'child2')
 
121
        os.chdir('child2')
 
122
 
 
123
        # Double binding succeeds, but committing to child2 should fail
 
124
        bzr('bind', '../child')
 
125
 
 
126
        bzr('commit', '-m', 'child2', '--unchanged', retcode=3)
 
127
 
 
128
    def test_unbinding(self):
 
129
        bzr = self.run_bzr
 
130
        self.create_branches()
 
131
 
 
132
        os.chdir('base')
 
133
        open('a', 'wb').write('new base contents\n')
 
134
        bzr('commit', '-m', 'base')
 
135
        self.check_revno(2)
 
136
 
 
137
        os.chdir('../child')
 
138
        open('b', 'wb').write('new b child contents\n')
 
139
        self.check_revno(1)
 
140
        bzr('commit', '-m', 'child', retcode=3)
 
141
        self.check_revno(1)
 
142
        bzr('unbind')
 
143
        bzr('commit', '-m', 'child')
 
144
        self.check_revno(2)
 
145
 
 
146
        bzr('bind', retcode=3)
 
147
 
 
148
    def test_commit_remote_bound(self):
 
149
        # It is not possible to commit to a branch
 
150
        # which is bound to a branch which is bound
 
151
        bzr = self.run_bzr
 
152
        self.create_branches()
 
153
        bzr('branch', 'base', 'newbase')
 
154
        os.chdir('base')
 
155
        
 
156
        # There is no way to know that B has already
 
157
        # been bound by someone else, otherwise it
 
158
        # might be nice if this would fail
 
159
        bzr('bind', '../newbase')
 
160
 
 
161
        os.chdir('../child')
 
162
        bzr('commit', '-m', 'failure', '--unchanged', retcode=3)
 
163
        
 
164
 
 
165
    def test_pull_updates_both(self):
 
166
        bzr = self.run_bzr
 
167
        self.create_branches()
 
168
        bzr('branch', 'base', 'newchild')
 
169
        os.chdir('newchild')
 
170
        open('b', 'wb').write('newchild b contents\n')
 
171
        bzr('commit', '-m', 'newchild')
 
172
        self.check_revno(2)
 
173
 
 
174
        os.chdir('../child')
 
175
        # The pull should succeed, and update
 
176
        # the bound parent branch
 
177
        bzr('pull', '../newchild')
 
178
        self.check_revno(2)
 
179
 
 
180
        os.chdir('../base')
 
181
        self.check_revno(2)
 
182
 
 
183
    def test_bind_diverged(self):
 
184
        bzr = self.run_bzr
 
185
        self.create_branches()
 
186
 
 
187
        os.chdir('child')
 
188
        bzr('unbind')
 
189
 
 
190
        bzr('commit', '-m', 'child', '--unchanged')
 
191
        self.check_revno(2)
 
192
 
 
193
        os.chdir('../base')
 
194
        self.check_revno(1)
 
195
        bzr('commit', '-m', 'base', '--unchanged')
 
196
        self.check_revno(2)
 
197
 
 
198
        os.chdir('../child')
 
199
        # These branches have diverged
 
200
        bzr('bind', '../base', retcode=3)
 
201
 
 
202
        # TODO: In the future, this might require actual changes
 
203
        # to have occurred, rather than just a new revision entry
 
204
        bzr('merge', '../base')
 
205
        bzr('commit', '-m', 'merged')
 
206
        self.check_revno(3)
 
207
 
 
208
        # After a merge, trying to bind again should succeed
 
209
        # by pushing the new change to base
 
210
        bzr('bind', '../base')
 
211
        self.check_revno(3)
 
212
        self.check_revno(3, '../base')
 
213
 
 
214
        # After binding, the revision history should be identical
 
215
        child_rh = self.capture('revision-history')
 
216
        os.chdir('../base')
 
217
        base_rh = self.capture('revision-history')
 
218
        self.assertEquals(child_rh, base_rh)
 
219
 
 
220
    def test_bind_parent_ahead(self):
 
221
        bzr = self.run_bzr
 
222
        self.create_branches()
 
223
 
 
224
        os.chdir('child')
 
225
        bzr('unbind')
 
226
 
 
227
        os.chdir('../base')
 
228
        bzr('commit', '-m', 'base', '--unchanged')
 
229
 
 
230
        os.chdir('../child')
 
231
        self.check_revno(1)
 
232
        bzr('bind', '../base')
 
233
 
 
234
        self.check_revno(2)
 
235
        bzr('unbind')
 
236
 
 
237
        # Check and make sure it also works if parent is ahead multiple
 
238
        os.chdir('../base')
 
239
        bzr('commit', '-m', 'base 3', '--unchanged')
 
240
        bzr('commit', '-m', 'base 4', '--unchanged')
 
241
        bzr('commit', '-m', 'base 5', '--unchanged')
 
242
        self.check_revno(5)
 
243
 
 
244
        os.chdir('../child')
 
245
        self.check_revno(2)
 
246
        bzr('bind')
 
247
        self.check_revno(5)
 
248
 
 
249
    def test_bind_child_ahead(self):
 
250
        bzr = self.run_bzr
 
251
        self.create_branches()
 
252
 
 
253
        os.chdir('child')
 
254
        bzr('unbind')
 
255
        bzr('commit', '-m', 'child', '--unchanged')
 
256
        self.check_revno(2)
 
257
        self.check_revno(1, '../base')
 
258
 
 
259
        bzr('bind', '../base')
 
260
        self.check_revno(2, '../base')
 
261
 
 
262
        # Check and make sure it also works if child is ahead multiple
 
263
        bzr('unbind')
 
264
        bzr('commit', '-m', 'child 3', '--unchanged')
 
265
        bzr('commit', '-m', 'child 4', '--unchanged')
 
266
        bzr('commit', '-m', 'child 5', '--unchanged')
 
267
        self.check_revno(5)
 
268
 
 
269
        self.check_revno(2, '../base')
 
270
        bzr('bind')
 
271
        self.check_revno(5, '../base')
 
272