/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_update.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
"""Tests for the update command of bzr."""
19
19
 
20
20
import os
 
21
import re
21
22
 
22
 
from breezy import (
 
23
from bzrlib import (
23
24
    branch,
 
25
    bzrdir,
24
26
    osutils,
25
27
    tests,
 
28
    urlutils,
26
29
    workingtree,
27
30
    )
28
 
from breezy.bzr import (
29
 
    bzrdir,
30
 
    )
31
 
from breezy.tests.script import ScriptRunner
 
31
from bzrlib.tests.script import ScriptRunner
32
32
 
33
33
 
34
34
class TestUpdate(tests.TestCaseWithTransport):
69
69
        self.run_bzr('checkout branch checkout')
70
70
        sr = ScriptRunner()
71
71
        sr.run_script(self, '''
72
 
$ brz update checkout
 
72
$ bzr update checkout
73
73
2>Tree is up to date at revision 0 of branch .../branch
74
74
''')
75
75
 
83
83
        self.run_bzr('add checkout/file')
84
84
        self.run_bzr('commit -m add-file checkout')
85
85
        # now branch should be out of date
86
 
        out, err = self.run_bzr('update branch')
 
86
        out,err = self.run_bzr('update branch')
87
87
        self.assertEqual('', out)
88
88
        self.assertEqualDiff("""+N  file
89
89
All changes applied successfully.
90
90
Updated to revision 1 of branch %s
91
91
""" % osutils.pathjoin(self.test_dir, 'branch',),
92
 
            err)
93
 
        self.assertPathExists('branch/file')
 
92
                         err)
 
93
        self.failUnlessExists('branch/file')
94
94
 
95
95
    def test_update_out_of_date_light_checkout(self):
96
96
        self.make_branch_and_tree('branch')
101
101
        self.run_bzr('add checkout/file')
102
102
        self.run_bzr('commit -m add-file checkout')
103
103
        # now checkout2 should be out of date
104
 
        out, err = self.run_bzr('update checkout2')
 
104
        out,err = self.run_bzr('update checkout2')
105
105
        self.assertEqualDiff('''+N  file
106
106
All changes applied successfully.
107
107
Updated to revision 1 of branch %s
108
108
''' % osutils.pathjoin(self.test_dir, 'branch',),
109
 
            err)
 
109
                         err)
110
110
        self.assertEqual('', out)
111
111
 
112
112
    def test_update_conflicts_returns_2(self):
118
118
        self.run_bzr('commit -m add-file checkout')
119
119
        self.run_bzr('checkout --lightweight branch checkout2')
120
120
        # now alter file in checkout
121
 
        with open('checkout/file', 'wt') as a_file:
122
 
            a_file.write('Foo')
 
121
        a_file = file('checkout/file', 'wt')
 
122
        a_file.write('Foo')
 
123
        a_file.close()
123
124
        self.run_bzr('commit -m checnge-file checkout')
124
125
        # now checkout2 should be out of date
125
126
        # make a local change to file
126
 
        with open('checkout2/file', 'wt') as a_file:
127
 
            a_file.write('Bar')
128
 
        out, err = self.run_bzr('update checkout2', retcode=1)
 
127
        a_file = file('checkout2/file', 'wt')
 
128
        a_file.write('Bar')
 
129
        a_file.close()
 
130
        out,err = self.run_bzr('update checkout2', retcode=1)
129
131
        self.assertEqualDiff(''' M  file
130
132
Text conflict in file
131
133
1 conflicts encountered.
132
134
Updated to revision 2 of branch %s
133
135
''' % osutils.pathjoin(self.test_dir, 'branch',),
134
 
            err)
 
136
                         err)
135
137
        self.assertEqual('', out)
136
138
 
137
139
    def test_smoke_update_checkout_bound_branch_local_commits(self):
138
140
        # smoke test for doing an update of a checkout of a bound
139
141
        # branch with local commits.
140
142
        master = self.make_branch_and_tree('master')
141
 
        master.commit('first commit')
142
143
        # make a bound branch
143
144
        self.run_bzr('checkout master child')
 
145
        # get an object form of child
 
146
        child = workingtree.WorkingTree.open('child')
144
147
        # check that out
145
148
        self.run_bzr('checkout --lightweight child checkout')
146
149
        # get an object form of the checkout to manipulate
147
150
        wt = workingtree.WorkingTree.open('checkout')
148
151
        # change master
149
 
        with open('master/file', 'wt') as a_file:
150
 
            a_file.write('Foo')
 
152
        a_file = file('master/file', 'wt')
 
153
        a_file.write('Foo')
 
154
        a_file.close()
151
155
        master.add(['file'])
152
156
        master_tip = master.commit('add file')
153
157
        # change child
154
 
        with open('child/file_b', 'wt') as a_file:
155
 
            a_file.write('Foo')
156
 
        # get an object form of child
157
 
        child = workingtree.WorkingTree.open('child')
 
158
        a_file = file('child/file_b', 'wt')
 
159
        a_file.write('Foo')
 
160
        a_file.close()
158
161
        child.add(['file_b'])
159
162
        child_tip = child.commit('add file_b', local=True)
160
163
        # check checkout
161
 
        with open('checkout/file_c', 'wt') as a_file:
162
 
            a_file.write('Foo')
 
164
        a_file = file('checkout/file_c', 'wt')
 
165
        a_file.write('Foo')
 
166
        a_file.close()
163
167
        wt.add(['file_c'])
164
168
 
165
169
        # now, update checkout ->
170
174
All changes applied successfully.
171
175
+N  file
172
176
All changes applied successfully.
173
 
Updated to revision 2 of branch %s
174
 
Your local commits will now show as pending merges with 'brz status', and can be committed with 'brz commit'.
 
177
Updated to revision 1 of branch %s
 
178
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
175
179
""" % osutils.pathjoin(self.test_dir, 'master',),
176
 
            err)
 
180
                         err)
177
181
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
178
 
        self.assertPathExists('checkout/file')
179
 
        self.assertPathExists('checkout/file_b')
180
 
        self.assertPathExists('checkout/file_c')
 
182
        self.failUnlessExists('checkout/file')
 
183
        self.failUnlessExists('checkout/file_b')
 
184
        self.failUnlessExists('checkout/file_c')
181
185
        self.assertTrue(wt.has_filename('file_c'))
182
186
 
183
187
    def test_update_with_merges(self):
184
 
        # Test that 'brz update' works correctly when you have
 
188
        # Test that 'bzr update' works correctly when you have
185
189
        # an update in the master tree, and a lightweight checkout
186
190
        # which has merged another branch
187
191
        master = self.make_branch_and_tree('master')
188
192
        self.build_tree(['master/file'])
189
193
        master.add(['file'])
190
 
        master.commit('one', rev_id=b'm1')
 
194
        master.commit('one', rev_id='m1')
191
195
 
192
196
        self.build_tree(['checkout1/'])
193
197
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
194
 
        checkout_dir.set_branch_reference(master.branch)
195
 
        checkout1 = checkout_dir.create_workingtree(b'm1')
 
198
        branch.BranchReferenceFormat().initialize(checkout_dir,
 
199
            target_branch=master.branch)
 
200
        checkout1 = checkout_dir.create_workingtree('m1')
196
201
 
197
202
        # Create a second branch, with an extra commit
198
 
        other = master.controldir.sprout('other').open_workingtree()
 
203
        other = master.bzrdir.sprout('other').open_workingtree()
199
204
        self.build_tree(['other/file2'])
200
205
        other.add(['file2'])
201
 
        other.commit('other2', rev_id=b'o2')
 
206
        other.commit('other2', rev_id='o2')
202
207
 
203
208
        # Create a new commit in the master branch
204
209
        self.build_tree(['master/file3'])
205
210
        master.add(['file3'])
206
 
        master.commit('f3', rev_id=b'm2')
 
211
        master.commit('f3', rev_id='m2')
207
212
 
208
213
        # Merge the other branch into checkout
209
214
        os.chdir('checkout1')
210
215
        self.run_bzr('merge ../other')
211
216
 
212
 
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
 
217
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
213
218
 
214
219
        # At this point, 'commit' should fail, because we are out of date
215
 
        self.run_bzr_error(["please run 'brz update'"],
 
220
        self.run_bzr_error(["please run 'bzr update'"],
216
221
                           'commit -m merged')
217
222
 
218
223
        # This should not report about local commits being pending
223
228
All changes applied successfully.
224
229
Updated to revision 2 of branch %s
225
230
''' % osutils.pathjoin(self.test_dir, 'master',),
226
 
            err)
 
231
                         err)
227
232
        # The pending merges should still be there
228
 
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
 
233
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
229
234
 
230
235
    def test_readonly_lightweight_update(self):
231
236
        """Update a light checkout of a readonly branch"""
237
242
        self.run_bzr('update checkout')
238
243
 
239
244
    def test_update_with_merge_merged_to_master(self):
240
 
        # Test that 'brz update' works correctly when you have
 
245
        # Test that 'bzr update' works correctly when you have
241
246
        # an update in the master tree, and a [lightweight or otherwise]
242
247
        # checkout which has merge a revision merged to master already.
243
248
        master = self.make_branch_and_tree('master')
244
249
        self.build_tree(['master/file'])
245
250
        master.add(['file'])
246
 
        master.commit('one', rev_id=b'm1')
 
251
        master.commit('one', rev_id='m1')
247
252
 
248
253
        self.build_tree(['checkout1/'])
249
254
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
250
 
        checkout_dir.set_branch_reference(master.branch)
251
 
        checkout1 = checkout_dir.create_workingtree(b'm1')
 
255
        branch.BranchReferenceFormat().initialize(checkout_dir,
 
256
            target_branch=master.branch)
 
257
        checkout1 = checkout_dir.create_workingtree('m1')
252
258
 
253
259
        # Create a second branch, with an extra commit
254
 
        other = master.controldir.sprout('other').open_workingtree()
 
260
        other = master.bzrdir.sprout('other').open_workingtree()
255
261
        self.build_tree(['other/file2'])
256
262
        other.add(['file2'])
257
 
        other.commit('other2', rev_id=b'o2')
 
263
        other.commit('other2', rev_id='o2')
258
264
 
259
265
        # Merge the other branch into checkout -  'start reviewing a patch'
260
266
        checkout1.merge_from_branch(other.branch)
261
 
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
 
267
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
262
268
 
263
269
        # Create a new commit in the master branch - 'someone else lands its'
264
270
        master.merge_from_branch(other.branch)
265
 
        master.commit('f3', rev_id=b'm2')
 
271
        master.commit('f3', rev_id='m2')
266
272
 
267
273
        # This should not report about local commits being pending
268
274
        # merges, because they were real merges (but are now gone).
272
278
        self.assertEqualDiff('''All changes applied successfully.
273
279
Updated to revision 2 of branch %s
274
280
''' % osutils.pathjoin(self.test_dir, 'master',),
275
 
            err)
 
281
                         err)
276
282
        # The pending merges should still be there
277
283
        self.assertEqual([], checkout1.get_parent_ids()[1:])
278
284
 
281
287
        os.chdir('master')
282
288
        self.build_tree(['./file1'])
283
289
        master.add(['file1'])
284
 
        master.commit('one', rev_id=b'm1')
 
290
        master.commit('one', rev_id='m1')
285
291
        self.build_tree(['./file2'])
286
292
        master.add(['file2'])
287
 
        master.commit('two', rev_id=b'm2')
 
293
        master.commit('two', rev_id='m2')
288
294
 
289
295
        sr = ScriptRunner()
290
296
        sr.run_script(self, '''
291
 
$ brz update -r 1
 
297
$ bzr update -r 1
292
298
2>-D  file2
293
299
2>All changes applied successfully.
294
300
2>Updated to revision 1 of .../master
295
301
''')
296
 
        self.assertPathExists('./file1')
297
 
        self.assertPathDoesNotExist('./file2')
298
 
        self.assertEqual([b'm1'], master.get_parent_ids())
 
302
        self.failUnlessExists('./file1')
 
303
        self.failIfExists('./file2')
 
304
        self.assertEquals(['m1'], master.get_parent_ids())
299
305
 
300
306
    def test_update_dash_r_outside_history(self):
301
307
        """Ensure that we can update -r to dotted revisions.
303
309
        master = self.make_branch_and_tree('master')
304
310
        self.build_tree(['master/file1'])
305
311
        master.add(['file1'])
306
 
        master.commit('one', rev_id=b'm1')
 
312
        master.commit('one', rev_id='m1')
307
313
 
308
314
        # Create a second branch, with extra commits
309
 
        other = master.controldir.sprout('other').open_workingtree()
 
315
        other = master.bzrdir.sprout('other').open_workingtree()
310
316
        self.build_tree(['other/file2', 'other/file3'])
311
317
        other.add(['file2'])
312
 
        other.commit('other2', rev_id=b'o2')
 
318
        other.commit('other2', rev_id='o2')
313
319
        other.add(['file3'])
314
 
        other.commit('other3', rev_id=b'o3')
 
320
        other.commit('other3', rev_id='o3')
315
321
 
316
322
        os.chdir('master')
317
323
        self.run_bzr('merge ../other')
318
 
        master.commit('merge', rev_id=b'merge')
 
324
        master.commit('merge', rev_id='merge')
319
325
 
320
326
        # Switch to o2. file3 was added only in o3 and should be deleted.
321
327
        out, err = self.run_bzr('update -r revid:o2')
322
 
        self.assertContainsRe(err, '-D\\s+file3')
323
 
        self.assertContainsRe(err, 'All changes applied successfully\\.')
 
328
        self.assertContainsRe(err, '-D\s+file3')
 
329
        self.assertContainsRe(err, 'All changes applied successfully\.')
324
330
        self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
325
331
 
326
332
        # Switch back to latest
327
333
        out, err = self.run_bzr('update')
328
 
        self.assertContainsRe(err, '\\+N\\s+file3')
329
 
        self.assertContainsRe(err, 'All changes applied successfully\\.')
 
334
        self.assertContainsRe(err, '\+N\s+file3')
 
335
        self.assertContainsRe(err, 'All changes applied successfully\.')
330
336
        self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
331
337
 
332
338
    def test_update_dash_r_in_master(self):
333
 
        # Test that 'brz update' works correctly when you have
 
339
        # Test that 'bzr update' works correctly when you have
334
340
        # an update in the master tree,
335
341
        master = self.make_branch_and_tree('master')
336
342
        self.build_tree(['master/file1'])
337
343
        master.add(['file1'])
338
 
        master.commit('one', rev_id=b'm1')
 
344
        master.commit('one', rev_id='m1')
339
345
 
340
346
        self.run_bzr('checkout master checkout')
341
347
 
342
348
        # add a revision in the master.
343
349
        self.build_tree(['master/file2'])
344
350
        master.add(['file2'])
345
 
        master.commit('two', rev_id=b'm2')
 
351
        master.commit('two', rev_id='m2')
346
352
 
347
353
        os.chdir('checkout')
348
354
        sr = ScriptRunner()
349
355
        sr.run_script(self, '''
350
 
$ brz update -r revid:m2
 
356
$ bzr update -r revid:m2
351
357
2>+N  file2
352
358
2>All changes applied successfully.
353
359
2>Updated to revision 2 of branch .../master
354
360
''')
355
361
 
356
 
    def test_update_show_base(self):
357
 
        """brz update support --show-base
358
 
 
359
 
        see https://bugs.launchpad.net/bzr/+bug/202374"""
360
 
 
361
 
        tree = self.make_branch_and_tree('.')
362
 
 
363
 
        with open('hello', 'wt') as f:
364
 
            f.write('foo')
365
 
        tree.add('hello')
366
 
        tree.commit('fie')
367
 
 
368
 
        with open('hello', 'wt') as f:
369
 
            f.write('fee')
370
 
        tree.commit('fee')
371
 
 
372
 
        # tree.update() gives no such revision, so ...
373
 
        self.run_bzr(['update', '-r1'])
374
 
 
375
 
        # create conflict
376
 
        with open('hello', 'wt') as f:
377
 
            f.write('fie')
378
 
 
379
 
        out, err = self.run_bzr(['update', '--show-base'], retcode=1)
380
 
 
381
 
        # check for conflict notification
382
 
        self.assertContainsString(err,
383
 
                                  ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
384
 
        with open('hello', 'rb') as f:
385
 
            self.assertEqualDiff(b'<<<<<<< TREE\n'
386
 
                                 b'fie||||||| BASE-REVISION\n'
387
 
                                 b'foo=======\n'
388
 
                                 b'fee>>>>>>> MERGE-SOURCE\n',
389
 
                                 f.read())
390
 
 
391
362
    def test_update_checkout_prevent_double_merge(self):
392
 
        """"Launchpad bug 113809 in brz "update performs two merges"
 
363
        """"Launchpad bug 113809 in bzr "update performs two merges"
393
364
        https://launchpad.net/bugs/113809"""
394
365
        master = self.make_branch_and_tree('master')
395
 
        self.build_tree_contents([('master/file', b'initial contents\n')])
 
366
        self.build_tree_contents([('master/file', 'initial contents\n')])
396
367
        master.add(['file'])
397
 
        master.commit('one', rev_id=b'm1')
 
368
        master.commit('one', rev_id='m1')
398
369
 
399
370
        checkout = master.branch.create_checkout('checkout')
400
371
        lightweight = checkout.branch.create_checkout('lightweight',
402
373
 
403
374
        # time to create a mess
404
375
        # add a commit to the master
405
 
        self.build_tree_contents([('master/file', b'master\n')])
406
 
        master.commit('two', rev_id=b'm2')
407
 
        self.build_tree_contents([('master/file', b'master local changes\n')])
 
376
        self.build_tree_contents([('master/file', 'master\n')])
 
377
        master.commit('two', rev_id='m2')
 
378
        self.build_tree_contents([('master/file', 'master local changes\n')])
408
379
 
409
380
        # local commit on the checkout
410
 
        self.build_tree_contents([('checkout/file', b'checkout\n')])
411
 
        checkout.commit('tree', rev_id=b'c2', local=True)
 
381
        self.build_tree_contents([('checkout/file', 'checkout\n')])
 
382
        checkout.commit('tree', rev_id='c2', local=True)
412
383
        self.build_tree_contents([('checkout/file',
413
 
                                   b'checkout local changes\n')])
 
384
                                   'checkout local changes\n')])
414
385
 
415
 
        # lightweight
 
386
        # lightweight 
416
387
        self.build_tree_contents([('lightweight/file',
417
 
                                   b'lightweight local changes\n')])
 
388
                                   'lightweight local changes\n')])
418
389
 
419
390
        # now update (and get conflicts)
420
391
        out, err = self.run_bzr('update lightweight', retcode=1)
431
402
 
432
403
        # resolve it
433
404
        self.build_tree_contents([('lightweight/file',
434
 
                                   b'lightweight+checkout\n')])
 
405
                                   'lightweight+checkout\n')])
435
406
        self.run_bzr('resolve lightweight/file')
436
407
 
437
408
        # check we get the second conflict
446
417
>>>>>>> MERGE-SOURCE
447
418
''',
448
419
                             'lightweight/file')
449
 
 
450
 
    def test_no_upgrade_single_file(self):
451
 
        """There's one basis revision per tree.
452
 
 
453
 
        Since you can't actually change the basis for a single file at the
454
 
        moment, we don't let you think you can.
455
 
 
456
 
        See bug 557886.
457
 
        """
458
 
        self.make_branch_and_tree('.')
459
 
        self.build_tree_contents([('a/',),
460
 
                                  ('a/file', b'content')])
461
 
        sr = ScriptRunner()
462
 
        sr.run_script(self, '''
463
 
            $ brz update ./a
464
 
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
465
 
            $ brz update ./a/file
466
 
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
467
 
            $ brz update .
468
 
            2>Tree is up to date at revision 0 of branch ...
469
 
            $ cd a
470
 
            $ brz update .
471
 
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
472
 
            # however, you can update the whole tree from a subdirectory
473
 
            $ brz update
474
 
            2>Tree is up to date at revision 0 of branch ...
475
 
            ''')