/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
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
import os
22
from cStringIO import StringIO
23
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
24
from bzrlib.tests import TestCaseWithTransport
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
25
from bzrlib.branch import Branch
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
26
from bzrlib.bzrdir import (BzrDir,
27
                           BzrDirFormat,
28
                           BzrDirFormat6,
29
                           BzrDirMetaFormat1,
30
                           )
1551.2.43 by abentley
Fix bound branch tests
31
from bzrlib.osutils import getcwd
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
32
from bzrlib.workingtree import WorkingTree
33
34
35
class TestLegacyFormats(TestCaseWithTransport):
36
    
37
    def setUp(self):
38
        super(TestLegacyFormats, self).setUp()
39
        self.build_tree(['master/', 'child/'])
40
        self.run_bzr('init', 'master')
41
        old_format = BzrDirFormat.get_default_format()
42
        BzrDirFormat.set_default_format(BzrDirFormat6())
43
        try:
44
            self.run_bzr('init', 'child')
45
        finally:
46
            BzrDirFormat.set_default_format(old_format)
47
        os.chdir('child')
48
    
49
    def test_bind_format_6_bzrdir(self):
50
        # bind on a format 6 bzrdir should error
51
        out,err = self.run_bzr('bind', '../master', retcode=3)
52
        self.assertEqual('', out)
53
        self.assertEqual('bzr: ERROR: To use this feature you must '
1551.2.43 by abentley
Fix bound branch tests
54
                         'upgrade your branch at %s/.\n' % getcwd(), err)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
55
    
56
    def test_unbind_format_6_bzrdir(self):
57
        # bind on a format 6 bzrdir should error
58
        out,err = self.run_bzr('unbind', retcode=3)
59
        self.assertEqual('', out)
60
        self.assertEqual('bzr: ERROR: To use this feature you must '
1551.2.43 by abentley
Fix bound branch tests
61
                         'upgrade your branch at %s/.\n' % getcwd(), err)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
62
63
64
class TestBoundBranches(TestCaseWithTransport):
65
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
66
    def create_branches(self):
1505.1.6 by John Arbash Meinel
Cleaned up tests and code, all bound branch tests succeed.
67
        bzr = self.run_bzr
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
68
        self.build_tree(['base/', 'base/a', 'base/b'])
69
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
70
        self.init_meta_branch('base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
71
        os.chdir('base')
1505.1.6 by John Arbash Meinel
Cleaned up tests and code, all bound branch tests succeed.
72
        bzr('add')
73
        bzr('commit', '-m', 'init')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
74
75
        os.chdir('..')
76
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
77
        bzr('checkout', 'base', 'child')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
78
79
        self.failUnlessExists('child')
80
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
81
        self.check_revno(1, 'child')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
82
        d = BzrDir.open('child')
83
        self.assertNotEqual(None, d.open_branch().get_master_branch())
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
84
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
85
    def check_revno(self, val, loc=None):
86
        if loc is not None:
87
            cwd = os.getcwd()
88
            os.chdir(loc)
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
89
        self.assertEquals(str(val), self.run_bzr('revno')[0].strip())
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
90
        if loc is not None:
91
            os.chdir(cwd)
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
92
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
93
    def test_simple_binding(self):
94
        self.build_tree(['base/', 'base/a', 'base/b'])
95
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
96
        self.init_meta_branch('base')
97
        self.run_bzr('add', 'base')
98
        self.run_bzr('commit', '-m', 'init', 'base')
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
99
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
100
        self.run_bzr('branch', 'base', 'child')
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
101
102
        os.chdir('child')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
103
        self.run_bzr('bind', '../base')
104
105
        d = BzrDir.open('')
106
        self.assertNotEqual(None, d.open_branch().get_master_branch())
107
108
        self.run_bzr('unbind')
109
        self.assertEqual(None, d.open_branch().get_master_branch())
110
111
        self.run_bzr('unbind', retcode=3)
112
113
    def init_meta_branch(self, path):
114
        old_format = BzrDirFormat.get_default_format()
115
        BzrDirFormat.set_default_format(BzrDirMetaFormat1())
116
        try:
117
            self.run_bzr('init', path)
118
        finally:
119
            BzrDirFormat.set_default_format(old_format)
1505.1.5 by John Arbash Meinel
Added a test for the unbind command.
120
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
121
    def test_bound_commit(self):
122
        bzr = self.run_bzr
123
        self.create_branches()
124
125
        os.chdir('child')
126
        open('a', 'wb').write('new contents\n')
127
        bzr('commit', '-m', 'child')
128
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
129
        self.check_revno(2)
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
130
131
        # Make sure it committed on the parent
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
132
        self.check_revno(2, '../base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
133
1505.1.4 by John Arbash Meinel
Wrote a simple test which actually makes a branch become bound, and made it work
134
    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.
135
        # Make sure commit fails if out of date.
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
136
        bzr = self.run_bzr
137
        self.create_branches()
138
139
        os.chdir('base')
140
        open('a', 'wb').write('new base contents\n')
141
        bzr('commit', '-m', 'base')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
142
        self.check_revno(2)
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
143
144
        os.chdir('../child')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
145
        self.check_revno(1)
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
146
        open('b', 'wb').write('new b child contents\n')
1505.1.16 by John Arbash Meinel
[merge] robertc's integration, updated tests to check for retcode=3
147
        bzr('commit', '-m', 'child', retcode=3)
1587.1.11 by Robert Collins
Local commits appear to be working properly.
148
        self.check_revno(1)
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
149
1505.1.13 by John Arbash Meinel
Adding the bzr update command, to update checkouts and bound branches.
150
        bzr('update')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
151
        self.check_revno(2)
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
152
153
        bzr('commit', '-m', 'child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
154
        self.check_revno(3)
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
155
        self.check_revno(3, '../base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
156
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
157
    def test_double_binding(self):
158
        bzr = self.run_bzr
159
        self.create_branches()
160
161
        bzr('branch', 'child', 'child2')
162
        os.chdir('child2')
163
1505.1.6 by John Arbash Meinel
Cleaned up tests and code, all bound branch tests succeed.
164
        # Double binding succeeds, but committing to child2 should fail
165
        bzr('bind', '../child')
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
166
1505.1.16 by John Arbash Meinel
[merge] robertc's integration, updated tests to check for retcode=3
167
        bzr('commit', '-m', 'child2', '--unchanged', retcode=3)
1505.1.2 by John Arbash Meinel
(broken) working on implementing bound branches.
168
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
169
    def test_unbinding(self):
170
        bzr = self.run_bzr
171
        self.create_branches()
172
173
        os.chdir('base')
174
        open('a', 'wb').write('new base contents\n')
175
        bzr('commit', '-m', 'base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
176
        self.check_revno(2)
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
177
178
        os.chdir('../child')
179
        open('b', 'wb').write('new b child contents\n')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
180
        self.check_revno(1)
1505.1.16 by John Arbash Meinel
[merge] robertc's integration, updated tests to check for retcode=3
181
        bzr('commit', '-m', 'child', retcode=3)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
182
        self.check_revno(1)
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
183
        bzr('unbind')
184
        bzr('commit', '-m', 'child')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
185
        self.check_revno(2)
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
186
1505.1.16 by John Arbash Meinel
[merge] robertc's integration, updated tests to check for retcode=3
187
        bzr('bind', retcode=3)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
188
189
    def test_commit_remote_bound(self):
190
        # It is not possible to commit to a branch
191
        # which is bound to a branch which is bound
192
        bzr = self.run_bzr
1505.1.6 by John Arbash Meinel
Cleaned up tests and code, all bound branch tests succeed.
193
        self.create_branches()
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
194
        bzr('branch', 'base', 'newbase')
195
        os.chdir('base')
196
        
197
        # There is no way to know that B has already
198
        # been bound by someone else, otherwise it
199
        # might be nice if this would fail
200
        bzr('bind', '../newbase')
201
202
        os.chdir('../child')
1505.1.16 by John Arbash Meinel
[merge] robertc's integration, updated tests to check for retcode=3
203
        bzr('commit', '-m', 'failure', '--unchanged', retcode=3)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
204
205
    def test_pull_updates_both(self):
206
        bzr = self.run_bzr
207
        self.create_branches()
208
        bzr('branch', 'base', 'newchild')
209
        os.chdir('newchild')
210
        open('b', 'wb').write('newchild b contents\n')
211
        bzr('commit', '-m', 'newchild')
212
        self.check_revno(2)
213
214
        os.chdir('../child')
215
        # The pull should succeed, and update
216
        # the bound parent branch
217
        bzr('pull', '../newchild')
218
        self.check_revno(2)
219
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
220
        self.check_revno(2, '../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
221
222
    def test_bind_diverged(self):
223
        bzr = self.run_bzr
224
        self.create_branches()
225
226
        os.chdir('child')
227
        bzr('unbind')
228
229
        bzr('commit', '-m', 'child', '--unchanged')
230
        self.check_revno(2)
231
232
        os.chdir('../base')
233
        self.check_revno(1)
234
        bzr('commit', '-m', 'base', '--unchanged')
235
        self.check_revno(2)
236
237
        os.chdir('../child')
238
        # These branches have diverged
1505.1.16 by John Arbash Meinel
[merge] robertc's integration, updated tests to check for retcode=3
239
        bzr('bind', '../base', retcode=3)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
240
241
        # TODO: In the future, this might require actual changes
242
        # to have occurred, rather than just a new revision entry
243
        bzr('merge', '../base')
244
        bzr('commit', '-m', 'merged')
245
        self.check_revno(3)
246
1505.1.13 by John Arbash Meinel
Adding the bzr update command, to update checkouts and bound branches.
247
        # After a merge, trying to bind again should succeed
248
        # by pushing the new change to base
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
249
        bzr('bind', '../base')
1505.1.13 by John Arbash Meinel
Adding the bzr update command, to update checkouts and bound branches.
250
        self.check_revno(3)
251
        self.check_revno(3, '../base')
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
252
253
        # After binding, the revision history should be identical
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
254
        child_rh = bzr('revision-history')[0]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
255
        os.chdir('../base')
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
256
        base_rh = bzr('revision-history')[0]
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
257
        self.assertEquals(child_rh, base_rh)
258
259
    def test_bind_parent_ahead(self):
260
        bzr = self.run_bzr
261
        self.create_branches()
262
263
        os.chdir('child')
264
        bzr('unbind')
265
266
        os.chdir('../base')
267
        bzr('commit', '-m', 'base', '--unchanged')
268
269
        os.chdir('../child')
270
        self.check_revno(1)
271
        bzr('bind', '../base')
272
273
        self.check_revno(2)
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
274
        bzr('unbind')
275
276
        # Check and make sure it also works if parent is ahead multiple
277
        os.chdir('../base')
278
        bzr('commit', '-m', 'base 3', '--unchanged')
279
        bzr('commit', '-m', 'base 4', '--unchanged')
280
        bzr('commit', '-m', 'base 5', '--unchanged')
281
        self.check_revno(5)
282
283
        os.chdir('../child')
284
        self.check_revno(2)
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
285
        bzr('bind', '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
286
        self.check_revno(5)
1505.1.3 by John Arbash Meinel
(broken) Adding more tests, and some functionality
287
288
    def test_bind_child_ahead(self):
289
        bzr = self.run_bzr
290
        self.create_branches()
291
292
        os.chdir('child')
293
        bzr('unbind')
294
        bzr('commit', '-m', 'child', '--unchanged')
295
        self.check_revno(2)
296
        self.check_revno(1, '../base')
297
298
        bzr('bind', '../base')
299
        self.check_revno(2, '../base')
1505.1.1 by John Arbash Meinel
Adding test for bound behavior
300
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
301
        # Check and make sure it also works if child is ahead multiple
302
        bzr('unbind')
303
        bzr('commit', '-m', 'child 3', '--unchanged')
304
        bzr('commit', '-m', 'child 4', '--unchanged')
305
        bzr('commit', '-m', 'child 5', '--unchanged')
306
        self.check_revno(5)
307
308
        self.check_revno(2, '../base')
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
309
        bzr('bind', '../base')
1505.1.11 by John Arbash Meinel
Adding a little bit more to the test suite.
310
        self.check_revno(5, '../base')
311
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
312
    def test_commit_after_merge(self):
313
        bzr = self.run_bzr
314
        self.create_branches()
315
316
        # We want merge to be able to be a local only
317
        # operation, because it can be without violating
318
        # the binding invariants.
319
        # But we can't fail afterwards
320
321
        bzr('branch', 'child', 'other')
322
323
        os.chdir('other')
324
        open('c', 'wb').write('file c\n')
325
        bzr('add', 'c')
326
        bzr('commit', '-m', 'adding c')
327
        new_rev_id = bzr('revision-history')[0].strip().split('\n')[-1]
328
329
        os.chdir('../child')
330
        bzr('merge', '../other')
331
332
        self.failUnlessExists('c')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
333
        tree = WorkingTree.open('.')
334
        self.assertEqual([new_rev_id], tree.pending_merges())
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
335
336
        # Make sure the local branch has the installed revision
337
        bzr('cat-revision', new_rev_id)
338
        
339
        # And make sure that the base tree does not
340
        os.chdir('../base')
341
        bzr('cat-revision', new_rev_id, retcode=3)
342
343
        # Commit should succeed, and cause merged revisions to
344
        # be pulled into base
345
        os.chdir('../child')
346
        bzr('commit', '-m', 'merge other')
347
348
        self.check_revno(2)
349
350
        os.chdir('../base')
351
        self.check_revno(2)
352
353
        bzr('cat-revision', new_rev_id)
354
1505.1.25 by John Arbash Meinel
Updated pull. Now all paths which call set_revision_history maintain the branch invariant. All tests pass.
355
    def test_pull_overwrite_fails(self):
356
        bzr = self.run_bzr
357
        self.create_branches()
358
359
        bzr('branch', 'child', 'other')
360
        
361
        os.chdir('other')
362
        open('a', 'wb').write('new contents\n')
363
        bzr('commit', '-m', 'changed a')
364
        self.check_revno(2)
365
        open('a', 'ab').write('and then some\n')
366
        bzr('commit', '-m', 'another a')
367
        self.check_revno(3)
368
        open('a', 'ab').write('and some more\n')
369
        bzr('commit', '-m', 'yet another a')
370
        self.check_revno(4)
371
372
        os.chdir('../child')
373
        open('a', 'wb').write('also changed a\n')
374
        bzr('commit', '-m', 'child modified a')
375
376
        self.check_revno(2)
377
        self.check_revno(2, '../base')
378
379
        # It might be possible that we want pull --overwrite to
380
        # actually succeed.
381
        # If we want it, just change this test to make sure that 
382
        # both base and child are updated properly
383
        bzr('pull', '--overwrite', '../other', retcode=3)
384
385
        # It should fail without changing the local revision
386
        self.check_revno(2)
387
        self.check_revno(2, '../base')
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
388
1505.1.28 by John Arbash Meinel
todo
389
    # TODO: jam 20051230 Test that commit & pull fail when the branch we 
390
    #       are bound to is not available
391
392