/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: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

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