/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-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

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