/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 breezy/tests/blackbox/test_update.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-09 23:53:11 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180509235311-k1zk8mwcb09b8vm0
Update TODO.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 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
22
21
 
23
 
from bzrlib import (
 
22
from breezy import (
24
23
    branch,
25
 
    bzrdir,
26
24
    osutils,
27
25
    tests,
28
 
    urlutils,
29
26
    workingtree,
30
27
    )
31
 
from bzrlib.tests.script import ScriptRunner
 
28
from breezy.bzr import (
 
29
    bzrdir,
 
30
    )
 
31
from breezy.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
 
$ bzr update checkout
 
72
$ brz 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
92
                         err)
93
 
        self.failUnlessExists('branch/file')
 
93
        self.assertPathExists('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
127
127
        a_file = file('checkout2/file', 'wt')
128
128
        a_file.write('Bar')
129
129
        a_file.close()
130
 
        out,err = self.run_bzr('update checkout2', retcode=1)
 
130
        out, err = self.run_bzr('update checkout2', retcode=1)
131
131
        self.assertEqualDiff(''' M  file
132
132
Text conflict in file
133
133
1 conflicts encountered.
140
140
        # smoke test for doing an update of a checkout of a bound
141
141
        # branch with local commits.
142
142
        master = self.make_branch_and_tree('master')
 
143
        master.commit('first commit')
143
144
        # make a bound branch
144
145
        self.run_bzr('checkout master child')
145
 
        # get an object form of child
146
 
        child = workingtree.WorkingTree.open('child')
147
146
        # check that out
148
147
        self.run_bzr('checkout --lightweight child checkout')
149
148
        # get an object form of the checkout to manipulate
158
157
        a_file = file('child/file_b', 'wt')
159
158
        a_file.write('Foo')
160
159
        a_file.close()
 
160
        # get an object form of child
 
161
        child = workingtree.WorkingTree.open('child')
161
162
        child.add(['file_b'])
162
163
        child_tip = child.commit('add file_b', local=True)
163
164
        # check checkout
174
175
All changes applied successfully.
175
176
+N  file
176
177
All changes applied successfully.
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'.
 
178
Updated to revision 2 of branch %s
 
179
Your local commits will now show as pending merges with 'brz status', and can be committed with 'brz commit'.
179
180
""" % osutils.pathjoin(self.test_dir, 'master',),
180
181
                         err)
181
182
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
182
 
        self.failUnlessExists('checkout/file')
183
 
        self.failUnlessExists('checkout/file_b')
184
 
        self.failUnlessExists('checkout/file_c')
 
183
        self.assertPathExists('checkout/file')
 
184
        self.assertPathExists('checkout/file_b')
 
185
        self.assertPathExists('checkout/file_c')
185
186
        self.assertTrue(wt.has_filename('file_c'))
186
187
 
187
188
    def test_update_with_merges(self):
188
 
        # Test that 'bzr update' works correctly when you have
 
189
        # Test that 'brz update' works correctly when you have
189
190
        # an update in the master tree, and a lightweight checkout
190
191
        # which has merged another branch
191
192
        master = self.make_branch_and_tree('master')
192
193
        self.build_tree(['master/file'])
193
194
        master.add(['file'])
194
 
        master.commit('one', rev_id='m1')
 
195
        master.commit('one', rev_id=b'm1')
195
196
 
196
197
        self.build_tree(['checkout1/'])
197
198
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
198
 
        branch.BranchReferenceFormat().initialize(checkout_dir,
199
 
            target_branch=master.branch)
 
199
        checkout_dir.set_branch_reference(master.branch)
200
200
        checkout1 = checkout_dir.create_workingtree('m1')
201
201
 
202
202
        # Create a second branch, with an extra commit
203
 
        other = master.bzrdir.sprout('other').open_workingtree()
 
203
        other = master.controldir.sprout('other').open_workingtree()
204
204
        self.build_tree(['other/file2'])
205
205
        other.add(['file2'])
206
 
        other.commit('other2', rev_id='o2')
 
206
        other.commit('other2', rev_id=b'o2')
207
207
 
208
208
        # Create a new commit in the master branch
209
209
        self.build_tree(['master/file3'])
210
210
        master.add(['file3'])
211
 
        master.commit('f3', rev_id='m2')
 
211
        master.commit('f3', rev_id=b'm2')
212
212
 
213
213
        # Merge the other branch into checkout
214
214
        os.chdir('checkout1')
217
217
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
218
218
 
219
219
        # At this point, 'commit' should fail, because we are out of date
220
 
        self.run_bzr_error(["please run 'bzr update'"],
 
220
        self.run_bzr_error(["please run 'brz update'"],
221
221
                           'commit -m merged')
222
222
 
223
223
        # This should not report about local commits being pending
242
242
        self.run_bzr('update checkout')
243
243
 
244
244
    def test_update_with_merge_merged_to_master(self):
245
 
        # Test that 'bzr update' works correctly when you have
 
245
        # Test that 'brz update' works correctly when you have
246
246
        # an update in the master tree, and a [lightweight or otherwise]
247
247
        # checkout which has merge a revision merged to master already.
248
248
        master = self.make_branch_and_tree('master')
249
249
        self.build_tree(['master/file'])
250
250
        master.add(['file'])
251
 
        master.commit('one', rev_id='m1')
 
251
        master.commit('one', rev_id=b'm1')
252
252
 
253
253
        self.build_tree(['checkout1/'])
254
254
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
255
 
        branch.BranchReferenceFormat().initialize(checkout_dir,
256
 
            target_branch=master.branch)
 
255
        checkout_dir.set_branch_reference(master.branch)
257
256
        checkout1 = checkout_dir.create_workingtree('m1')
258
257
 
259
258
        # Create a second branch, with an extra commit
260
 
        other = master.bzrdir.sprout('other').open_workingtree()
 
259
        other = master.controldir.sprout('other').open_workingtree()
261
260
        self.build_tree(['other/file2'])
262
261
        other.add(['file2'])
263
 
        other.commit('other2', rev_id='o2')
 
262
        other.commit('other2', rev_id=b'o2')
264
263
 
265
264
        # Merge the other branch into checkout -  'start reviewing a patch'
266
265
        checkout1.merge_from_branch(other.branch)
268
267
 
269
268
        # Create a new commit in the master branch - 'someone else lands its'
270
269
        master.merge_from_branch(other.branch)
271
 
        master.commit('f3', rev_id='m2')
 
270
        master.commit('f3', rev_id=b'm2')
272
271
 
273
272
        # This should not report about local commits being pending
274
273
        # merges, because they were real merges (but are now gone).
287
286
        os.chdir('master')
288
287
        self.build_tree(['./file1'])
289
288
        master.add(['file1'])
290
 
        master.commit('one', rev_id='m1')
 
289
        master.commit('one', rev_id=b'm1')
291
290
        self.build_tree(['./file2'])
292
291
        master.add(['file2'])
293
 
        master.commit('two', rev_id='m2')
 
292
        master.commit('two', rev_id=b'm2')
294
293
 
295
294
        sr = ScriptRunner()
296
295
        sr.run_script(self, '''
297
 
$ bzr update -r 1
 
296
$ brz update -r 1
298
297
2>-D  file2
299
298
2>All changes applied successfully.
300
299
2>Updated to revision 1 of .../master
301
300
''')
302
 
        self.failUnlessExists('./file1')
303
 
        self.failIfExists('./file2')
304
 
        self.assertEquals(['m1'], master.get_parent_ids())
 
301
        self.assertPathExists('./file1')
 
302
        self.assertPathDoesNotExist('./file2')
 
303
        self.assertEqual(['m1'], master.get_parent_ids())
305
304
 
306
305
    def test_update_dash_r_outside_history(self):
307
306
        """Ensure that we can update -r to dotted revisions.
309
308
        master = self.make_branch_and_tree('master')
310
309
        self.build_tree(['master/file1'])
311
310
        master.add(['file1'])
312
 
        master.commit('one', rev_id='m1')
 
311
        master.commit('one', rev_id=b'm1')
313
312
 
314
313
        # Create a second branch, with extra commits
315
 
        other = master.bzrdir.sprout('other').open_workingtree()
 
314
        other = master.controldir.sprout('other').open_workingtree()
316
315
        self.build_tree(['other/file2', 'other/file3'])
317
316
        other.add(['file2'])
318
 
        other.commit('other2', rev_id='o2')
 
317
        other.commit('other2', rev_id=b'o2')
319
318
        other.add(['file3'])
320
 
        other.commit('other3', rev_id='o3')
 
319
        other.commit('other3', rev_id=b'o3')
321
320
 
322
321
        os.chdir('master')
323
322
        self.run_bzr('merge ../other')
324
 
        master.commit('merge', rev_id='merge')
 
323
        master.commit('merge', rev_id=b'merge')
325
324
 
326
325
        # Switch to o2. file3 was added only in o3 and should be deleted.
327
326
        out, err = self.run_bzr('update -r revid:o2')
336
335
        self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
337
336
 
338
337
    def test_update_dash_r_in_master(self):
339
 
        # Test that 'bzr update' works correctly when you have
 
338
        # Test that 'brz update' works correctly when you have
340
339
        # an update in the master tree,
341
340
        master = self.make_branch_and_tree('master')
342
341
        self.build_tree(['master/file1'])
343
342
        master.add(['file1'])
344
 
        master.commit('one', rev_id='m1')
 
343
        master.commit('one', rev_id=b'm1')
345
344
 
346
345
        self.run_bzr('checkout master checkout')
347
346
 
348
347
        # add a revision in the master.
349
348
        self.build_tree(['master/file2'])
350
349
        master.add(['file2'])
351
 
        master.commit('two', rev_id='m2')
 
350
        master.commit('two', rev_id=b'm2')
352
351
 
353
352
        os.chdir('checkout')
354
353
        sr = ScriptRunner()
355
354
        sr.run_script(self, '''
356
 
$ bzr update -r revid:m2
 
355
$ brz update -r revid:m2
357
356
2>+N  file2
358
357
2>All changes applied successfully.
359
358
2>Updated to revision 2 of branch .../master
360
359
''')
361
360
 
 
361
    def test_update_show_base(self):
 
362
        """brz update support --show-base
 
363
 
 
364
        see https://bugs.launchpad.net/bzr/+bug/202374"""
 
365
 
 
366
        tree=self.make_branch_and_tree('.')
 
367
 
 
368
        f = open('hello', 'wt')
 
369
        f.write('foo')
 
370
        f.close()
 
371
        tree.add('hello')
 
372
        tree.commit('fie')
 
373
 
 
374
        f = open('hello', 'wt')
 
375
        f.write('fee')
 
376
        f.close()
 
377
        tree.commit('fee')
 
378
 
 
379
        #tree.update() gives no such revision, so ...
 
380
        self.run_bzr(['update', '-r1'])
 
381
 
 
382
        #create conflict
 
383
        f = open('hello', 'wt')
 
384
        f.write('fie')
 
385
        f.close()
 
386
 
 
387
        out, err = self.run_bzr(['update', '--show-base'], retcode=1)
 
388
 
 
389
        # check for conflict notification
 
390
        self.assertContainsString(err,
 
391
                                  ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
 
392
        
 
393
        self.assertEqualDiff('<<<<<<< TREE\n'
 
394
                             'fie||||||| BASE-REVISION\n'
 
395
                             'foo=======\n'
 
396
                             'fee>>>>>>> MERGE-SOURCE\n',
 
397
                             open('hello').read())
 
398
 
362
399
    def test_update_checkout_prevent_double_merge(self):
363
 
        """"Launchpad bug 113809 in bzr "update performs two merges"
 
400
        """"Launchpad bug 113809 in brz "update performs two merges"
364
401
        https://launchpad.net/bugs/113809"""
365
402
        master = self.make_branch_and_tree('master')
366
 
        self.build_tree_contents([('master/file', 'initial contents\n')])
 
403
        self.build_tree_contents([('master/file', b'initial contents\n')])
367
404
        master.add(['file'])
368
 
        master.commit('one', rev_id='m1')
 
405
        master.commit('one', rev_id=b'm1')
369
406
 
370
407
        checkout = master.branch.create_checkout('checkout')
371
408
        lightweight = checkout.branch.create_checkout('lightweight',
373
410
 
374
411
        # time to create a mess
375
412
        # add a commit to the master
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')])
 
413
        self.build_tree_contents([('master/file', b'master\n')])
 
414
        master.commit('two', rev_id=b'm2')
 
415
        self.build_tree_contents([('master/file', b'master local changes\n')])
379
416
 
380
417
        # local commit on the checkout
381
 
        self.build_tree_contents([('checkout/file', 'checkout\n')])
382
 
        checkout.commit('tree', rev_id='c2', local=True)
 
418
        self.build_tree_contents([('checkout/file', b'checkout\n')])
 
419
        checkout.commit('tree', rev_id=b'c2', local=True)
383
420
        self.build_tree_contents([('checkout/file',
384
 
                                   'checkout local changes\n')])
 
421
                                   b'checkout local changes\n')])
385
422
 
386
423
        # lightweight 
387
424
        self.build_tree_contents([('lightweight/file',
388
 
                                   'lightweight local changes\n')])
 
425
                                   b'lightweight local changes\n')])
389
426
 
390
427
        # now update (and get conflicts)
391
428
        out, err = self.run_bzr('update lightweight', retcode=1)
402
439
 
403
440
        # resolve it
404
441
        self.build_tree_contents([('lightweight/file',
405
 
                                   'lightweight+checkout\n')])
 
442
                                   b'lightweight+checkout\n')])
406
443
        self.run_bzr('resolve lightweight/file')
407
444
 
408
445
        # check we get the second conflict
417
454
>>>>>>> MERGE-SOURCE
418
455
''',
419
456
                             'lightweight/file')
 
457
 
 
458
 
 
459
    def test_no_upgrade_single_file(self):
 
460
        """There's one basis revision per tree.
 
461
 
 
462
        Since you can't actually change the basis for a single file at the
 
463
        moment, we don't let you think you can.
 
464
 
 
465
        See bug 557886.
 
466
        """
 
467
        self.make_branch_and_tree('.')
 
468
        self.build_tree_contents([('a/',),
 
469
            ('a/file', b'content')])
 
470
        sr = ScriptRunner()
 
471
        sr.run_script(self, '''
 
472
            $ brz update ./a
 
473
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
 
474
            $ brz update ./a/file
 
475
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
 
476
            $ brz update .
 
477
            2>Tree is up to date at revision 0 of branch ...
 
478
            $ cd a
 
479
            $ brz update .
 
480
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
 
481
            # however, you can update the whole tree from a subdirectory
 
482
            $ brz update
 
483
            2>Tree is up to date at revision 0 of branch ...
 
484
            ''')