/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
 
92
            err)
93
93
        self.assertPathExists('branch/file')
94
94
 
95
95
    def test_update_out_of_date_light_checkout(self):
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
 
        a_file = file('checkout/file', 'wt')
122
 
        a_file.write('Foo')
123
 
        a_file.close()
 
121
        with open('checkout/file', 'wt') as a_file:
 
122
            a_file.write('Foo')
124
123
        self.run_bzr('commit -m checnge-file checkout')
125
124
        # now checkout2 should be out of date
126
125
        # make a local change to file
127
 
        a_file = file('checkout2/file', 'wt')
128
 
        a_file.write('Bar')
129
 
        a_file.close()
 
126
        with open('checkout2/file', 'wt') as a_file:
 
127
            a_file.write('Bar')
130
128
        out, err = self.run_bzr('update checkout2', retcode=1)
131
129
        self.assertEqualDiff(''' M  file
132
130
Text conflict in file
133
131
1 conflicts encountered.
134
132
Updated to revision 2 of branch %s
135
133
''' % osutils.pathjoin(self.test_dir, 'branch',),
136
 
                         err)
 
134
            err)
137
135
        self.assertEqual('', out)
138
136
 
139
137
    def test_smoke_update_checkout_bound_branch_local_commits(self):
148
146
        # get an object form of the checkout to manipulate
149
147
        wt = workingtree.WorkingTree.open('checkout')
150
148
        # change master
151
 
        a_file = file('master/file', 'wt')
152
 
        a_file.write('Foo')
153
 
        a_file.close()
 
149
        with open('master/file', 'wt') as a_file:
 
150
            a_file.write('Foo')
154
151
        master.add(['file'])
155
152
        master_tip = master.commit('add file')
156
153
        # change child
157
 
        a_file = file('child/file_b', 'wt')
158
 
        a_file.write('Foo')
159
 
        a_file.close()
 
154
        with open('child/file_b', 'wt') as a_file:
 
155
            a_file.write('Foo')
160
156
        # get an object form of child
161
157
        child = workingtree.WorkingTree.open('child')
162
158
        child.add(['file_b'])
163
159
        child_tip = child.commit('add file_b', local=True)
164
160
        # check checkout
165
 
        a_file = file('checkout/file_c', 'wt')
166
 
        a_file.write('Foo')
167
 
        a_file.close()
 
161
        with open('checkout/file_c', 'wt') as a_file:
 
162
            a_file.write('Foo')
168
163
        wt.add(['file_c'])
169
164
 
170
165
        # now, update checkout ->
178
173
Updated to revision 2 of branch %s
179
174
Your local commits will now show as pending merges with 'brz status', and can be committed with 'brz commit'.
180
175
""" % osutils.pathjoin(self.test_dir, 'master',),
181
 
                         err)
 
176
            err)
182
177
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
183
178
        self.assertPathExists('checkout/file')
184
179
        self.assertPathExists('checkout/file_b')
192
187
        master = self.make_branch_and_tree('master')
193
188
        self.build_tree(['master/file'])
194
189
        master.add(['file'])
195
 
        master.commit('one', rev_id='m1')
 
190
        master.commit('one', rev_id=b'm1')
196
191
 
197
192
        self.build_tree(['checkout1/'])
198
193
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
199
194
        checkout_dir.set_branch_reference(master.branch)
200
 
        checkout1 = checkout_dir.create_workingtree('m1')
 
195
        checkout1 = checkout_dir.create_workingtree(b'm1')
201
196
 
202
197
        # Create a second branch, with an extra commit
203
198
        other = master.controldir.sprout('other').open_workingtree()
204
199
        self.build_tree(['other/file2'])
205
200
        other.add(['file2'])
206
 
        other.commit('other2', rev_id='o2')
 
201
        other.commit('other2', rev_id=b'o2')
207
202
 
208
203
        # Create a new commit in the master branch
209
204
        self.build_tree(['master/file3'])
210
205
        master.add(['file3'])
211
 
        master.commit('f3', rev_id='m2')
 
206
        master.commit('f3', rev_id=b'm2')
212
207
 
213
208
        # Merge the other branch into checkout
214
209
        os.chdir('checkout1')
215
210
        self.run_bzr('merge ../other')
216
211
 
217
 
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 
212
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
218
213
 
219
214
        # At this point, 'commit' should fail, because we are out of date
220
215
        self.run_bzr_error(["please run 'brz update'"],
228
223
All changes applied successfully.
229
224
Updated to revision 2 of branch %s
230
225
''' % osutils.pathjoin(self.test_dir, 'master',),
231
 
                         err)
 
226
            err)
232
227
        # The pending merges should still be there
233
 
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 
228
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
234
229
 
235
230
    def test_readonly_lightweight_update(self):
236
231
        """Update a light checkout of a readonly branch"""
248
243
        master = self.make_branch_and_tree('master')
249
244
        self.build_tree(['master/file'])
250
245
        master.add(['file'])
251
 
        master.commit('one', rev_id='m1')
 
246
        master.commit('one', rev_id=b'm1')
252
247
 
253
248
        self.build_tree(['checkout1/'])
254
249
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
255
250
        checkout_dir.set_branch_reference(master.branch)
256
 
        checkout1 = checkout_dir.create_workingtree('m1')
 
251
        checkout1 = checkout_dir.create_workingtree(b'm1')
257
252
 
258
253
        # Create a second branch, with an extra commit
259
254
        other = master.controldir.sprout('other').open_workingtree()
260
255
        self.build_tree(['other/file2'])
261
256
        other.add(['file2'])
262
 
        other.commit('other2', rev_id='o2')
 
257
        other.commit('other2', rev_id=b'o2')
263
258
 
264
259
        # Merge the other branch into checkout -  'start reviewing a patch'
265
260
        checkout1.merge_from_branch(other.branch)
266
 
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 
261
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
267
262
 
268
263
        # Create a new commit in the master branch - 'someone else lands its'
269
264
        master.merge_from_branch(other.branch)
270
 
        master.commit('f3', rev_id='m2')
 
265
        master.commit('f3', rev_id=b'm2')
271
266
 
272
267
        # This should not report about local commits being pending
273
268
        # merges, because they were real merges (but are now gone).
277
272
        self.assertEqualDiff('''All changes applied successfully.
278
273
Updated to revision 2 of branch %s
279
274
''' % osutils.pathjoin(self.test_dir, 'master',),
280
 
                         err)
 
275
            err)
281
276
        # The pending merges should still be there
282
277
        self.assertEqual([], checkout1.get_parent_ids()[1:])
283
278
 
286
281
        os.chdir('master')
287
282
        self.build_tree(['./file1'])
288
283
        master.add(['file1'])
289
 
        master.commit('one', rev_id='m1')
 
284
        master.commit('one', rev_id=b'm1')
290
285
        self.build_tree(['./file2'])
291
286
        master.add(['file2'])
292
 
        master.commit('two', rev_id='m2')
 
287
        master.commit('two', rev_id=b'm2')
293
288
 
294
289
        sr = ScriptRunner()
295
290
        sr.run_script(self, '''
300
295
''')
301
296
        self.assertPathExists('./file1')
302
297
        self.assertPathDoesNotExist('./file2')
303
 
        self.assertEqual(['m1'], master.get_parent_ids())
 
298
        self.assertEqual([b'm1'], master.get_parent_ids())
304
299
 
305
300
    def test_update_dash_r_outside_history(self):
306
301
        """Ensure that we can update -r to dotted revisions.
308
303
        master = self.make_branch_and_tree('master')
309
304
        self.build_tree(['master/file1'])
310
305
        master.add(['file1'])
311
 
        master.commit('one', rev_id='m1')
 
306
        master.commit('one', rev_id=b'm1')
312
307
 
313
308
        # Create a second branch, with extra commits
314
309
        other = master.controldir.sprout('other').open_workingtree()
315
310
        self.build_tree(['other/file2', 'other/file3'])
316
311
        other.add(['file2'])
317
 
        other.commit('other2', rev_id='o2')
 
312
        other.commit('other2', rev_id=b'o2')
318
313
        other.add(['file3'])
319
 
        other.commit('other3', rev_id='o3')
 
314
        other.commit('other3', rev_id=b'o3')
320
315
 
321
316
        os.chdir('master')
322
317
        self.run_bzr('merge ../other')
323
 
        master.commit('merge', rev_id='merge')
 
318
        master.commit('merge', rev_id=b'merge')
324
319
 
325
320
        # Switch to o2. file3 was added only in o3 and should be deleted.
326
321
        out, err = self.run_bzr('update -r revid:o2')
327
 
        self.assertContainsRe(err, '-D\s+file3')
328
 
        self.assertContainsRe(err, 'All changes applied successfully\.')
 
322
        self.assertContainsRe(err, '-D\\s+file3')
 
323
        self.assertContainsRe(err, 'All changes applied successfully\\.')
329
324
        self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
330
325
 
331
326
        # Switch back to latest
332
327
        out, err = self.run_bzr('update')
333
 
        self.assertContainsRe(err, '\+N\s+file3')
334
 
        self.assertContainsRe(err, 'All changes applied successfully\.')
 
328
        self.assertContainsRe(err, '\\+N\\s+file3')
 
329
        self.assertContainsRe(err, 'All changes applied successfully\\.')
335
330
        self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
336
331
 
337
332
    def test_update_dash_r_in_master(self):
340
335
        master = self.make_branch_and_tree('master')
341
336
        self.build_tree(['master/file1'])
342
337
        master.add(['file1'])
343
 
        master.commit('one', rev_id='m1')
 
338
        master.commit('one', rev_id=b'm1')
344
339
 
345
340
        self.run_bzr('checkout master checkout')
346
341
 
347
342
        # add a revision in the master.
348
343
        self.build_tree(['master/file2'])
349
344
        master.add(['file2'])
350
 
        master.commit('two', rev_id='m2')
 
345
        master.commit('two', rev_id=b'm2')
351
346
 
352
347
        os.chdir('checkout')
353
348
        sr = ScriptRunner()
363
358
 
364
359
        see https://bugs.launchpad.net/bzr/+bug/202374"""
365
360
 
366
 
        tree=self.make_branch_and_tree('.')
 
361
        tree = self.make_branch_and_tree('.')
367
362
 
368
 
        f = open('hello', 'wt')
369
 
        f.write('foo')
370
 
        f.close()
 
363
        with open('hello', 'wt') as f:
 
364
            f.write('foo')
371
365
        tree.add('hello')
372
366
        tree.commit('fie')
373
367
 
374
 
        f = open('hello', 'wt')
375
 
        f.write('fee')
376
 
        f.close()
 
368
        with open('hello', 'wt') as f:
 
369
            f.write('fee')
377
370
        tree.commit('fee')
378
371
 
379
 
        #tree.update() gives no such revision, so ...
 
372
        # tree.update() gives no such revision, so ...
380
373
        self.run_bzr(['update', '-r1'])
381
374
 
382
 
        #create conflict
383
 
        f = open('hello', 'wt')
384
 
        f.write('fie')
385
 
        f.close()
 
375
        # create conflict
 
376
        with open('hello', 'wt') as f:
 
377
            f.write('fie')
386
378
 
387
379
        out, err = self.run_bzr(['update', '--show-base'], retcode=1)
388
380
 
389
381
        # check for conflict notification
390
382
        self.assertContainsString(err,
391
383
                                  ' 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())
 
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())
398
390
 
399
391
    def test_update_checkout_prevent_double_merge(self):
400
392
        """"Launchpad bug 113809 in brz "update performs two merges"
401
393
        https://launchpad.net/bugs/113809"""
402
394
        master = self.make_branch_and_tree('master')
403
 
        self.build_tree_contents([('master/file', 'initial contents\n')])
 
395
        self.build_tree_contents([('master/file', b'initial contents\n')])
404
396
        master.add(['file'])
405
 
        master.commit('one', rev_id='m1')
 
397
        master.commit('one', rev_id=b'm1')
406
398
 
407
399
        checkout = master.branch.create_checkout('checkout')
408
400
        lightweight = checkout.branch.create_checkout('lightweight',
410
402
 
411
403
        # time to create a mess
412
404
        # add a commit to the master
413
 
        self.build_tree_contents([('master/file', 'master\n')])
414
 
        master.commit('two', rev_id='m2')
415
 
        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')])
416
408
 
417
409
        # local commit on the checkout
418
 
        self.build_tree_contents([('checkout/file', 'checkout\n')])
419
 
        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)
420
412
        self.build_tree_contents([('checkout/file',
421
 
                                   'checkout local changes\n')])
 
413
                                   b'checkout local changes\n')])
422
414
 
423
 
        # lightweight 
 
415
        # lightweight
424
416
        self.build_tree_contents([('lightweight/file',
425
 
                                   'lightweight local changes\n')])
 
417
                                   b'lightweight local changes\n')])
426
418
 
427
419
        # now update (and get conflicts)
428
420
        out, err = self.run_bzr('update lightweight', retcode=1)
439
431
 
440
432
        # resolve it
441
433
        self.build_tree_contents([('lightweight/file',
442
 
                                   'lightweight+checkout\n')])
 
434
                                   b'lightweight+checkout\n')])
443
435
        self.run_bzr('resolve lightweight/file')
444
436
 
445
437
        # check we get the second conflict
455
447
''',
456
448
                             'lightweight/file')
457
449
 
458
 
 
459
450
    def test_no_upgrade_single_file(self):
460
451
        """There's one basis revision per tree.
461
452
 
466
457
        """
467
458
        self.make_branch_and_tree('.')
468
459
        self.build_tree_contents([('a/',),
469
 
            ('a/file', 'content')])
 
460
                                  ('a/file', b'content')])
470
461
        sr = ScriptRunner()
471
462
        sr.run_script(self, '''
472
463
            $ brz update ./a