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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

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