/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-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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
 
                         err)
93
 
        self.failUnlessExists('branch/file')
 
92
            err)
 
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
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()
130
 
        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)
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):
140
138
        # smoke test for doing an update of a checkout of a bound
141
139
        # branch with local commits.
142
140
        master = self.make_branch_and_tree('master')
 
141
        master.commit('first commit')
143
142
        # make a bound branch
144
143
        self.run_bzr('checkout master child')
145
 
        # get an object form of child
146
 
        child = workingtree.WorkingTree.open('child')
147
144
        # check that out
148
145
        self.run_bzr('checkout --lightweight child checkout')
149
146
        # get an object form of the checkout to manipulate
150
147
        wt = workingtree.WorkingTree.open('checkout')
151
148
        # change master
152
 
        a_file = file('master/file', 'wt')
153
 
        a_file.write('Foo')
154
 
        a_file.close()
 
149
        with open('master/file', 'wt') as a_file:
 
150
            a_file.write('Foo')
155
151
        master.add(['file'])
156
152
        master_tip = master.commit('add file')
157
153
        # change child
158
 
        a_file = file('child/file_b', 'wt')
159
 
        a_file.write('Foo')
160
 
        a_file.close()
 
154
        with open('child/file_b', 'wt') as a_file:
 
155
            a_file.write('Foo')
 
156
        # get an object form of child
 
157
        child = workingtree.WorkingTree.open('child')
161
158
        child.add(['file_b'])
162
159
        child_tip = child.commit('add file_b', local=True)
163
160
        # check checkout
164
 
        a_file = file('checkout/file_c', 'wt')
165
 
        a_file.write('Foo')
166
 
        a_file.close()
 
161
        with open('checkout/file_c', 'wt') as a_file:
 
162
            a_file.write('Foo')
167
163
        wt.add(['file_c'])
168
164
 
169
165
        # now, update checkout ->
174
170
All changes applied successfully.
175
171
+N  file
176
172
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'.
 
173
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'.
179
175
""" % osutils.pathjoin(self.test_dir, 'master',),
180
 
                         err)
 
176
            err)
181
177
        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')
 
178
        self.assertPathExists('checkout/file')
 
179
        self.assertPathExists('checkout/file_b')
 
180
        self.assertPathExists('checkout/file_c')
185
181
        self.assertTrue(wt.has_filename('file_c'))
186
182
 
187
183
    def test_update_with_merges(self):
188
 
        # Test that 'bzr update' works correctly when you have
 
184
        # Test that 'brz update' works correctly when you have
189
185
        # an update in the master tree, and a lightweight checkout
190
186
        # which has merged another branch
191
187
        master = self.make_branch_and_tree('master')
192
188
        self.build_tree(['master/file'])
193
189
        master.add(['file'])
194
 
        master.commit('one', rev_id='m1')
 
190
        master.commit('one', rev_id=b'm1')
195
191
 
196
192
        self.build_tree(['checkout1/'])
197
193
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
198
 
        branch.BranchReferenceFormat().initialize(checkout_dir,
199
 
            target_branch=master.branch)
200
 
        checkout1 = checkout_dir.create_workingtree('m1')
 
194
        checkout_dir.set_branch_reference(master.branch)
 
195
        checkout1 = checkout_dir.create_workingtree(b'm1')
201
196
 
202
197
        # Create a second branch, with an extra commit
203
 
        other = master.bzrdir.sprout('other').open_workingtree()
 
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
 
        self.run_bzr_error(["please run 'bzr update'"],
 
215
        self.run_bzr_error(["please run 'brz update'"],
221
216
                           'commit -m merged')
222
217
 
223
218
        # This should not report about local commits being pending
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"""
242
237
        self.run_bzr('update checkout')
243
238
 
244
239
    def test_update_with_merge_merged_to_master(self):
245
 
        # Test that 'bzr update' works correctly when you have
 
240
        # Test that 'brz update' works correctly when you have
246
241
        # an update in the master tree, and a [lightweight or otherwise]
247
242
        # checkout which has merge a revision merged to master already.
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
 
        branch.BranchReferenceFormat().initialize(checkout_dir,
256
 
            target_branch=master.branch)
257
 
        checkout1 = checkout_dir.create_workingtree('m1')
 
250
        checkout_dir.set_branch_reference(master.branch)
 
251
        checkout1 = checkout_dir.create_workingtree(b'm1')
258
252
 
259
253
        # Create a second branch, with an extra commit
260
 
        other = master.bzrdir.sprout('other').open_workingtree()
 
254
        other = master.controldir.sprout('other').open_workingtree()
261
255
        self.build_tree(['other/file2'])
262
256
        other.add(['file2'])
263
 
        other.commit('other2', rev_id='o2')
 
257
        other.commit('other2', rev_id=b'o2')
264
258
 
265
259
        # Merge the other branch into checkout -  'start reviewing a patch'
266
260
        checkout1.merge_from_branch(other.branch)
267
 
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 
261
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
268
262
 
269
263
        # Create a new commit in the master branch - 'someone else lands its'
270
264
        master.merge_from_branch(other.branch)
271
 
        master.commit('f3', rev_id='m2')
 
265
        master.commit('f3', rev_id=b'm2')
272
266
 
273
267
        # This should not report about local commits being pending
274
268
        # merges, because they were real merges (but are now gone).
278
272
        self.assertEqualDiff('''All changes applied successfully.
279
273
Updated to revision 2 of branch %s
280
274
''' % osutils.pathjoin(self.test_dir, 'master',),
281
 
                         err)
 
275
            err)
282
276
        # The pending merges should still be there
283
277
        self.assertEqual([], checkout1.get_parent_ids()[1:])
284
278
 
287
281
        os.chdir('master')
288
282
        self.build_tree(['./file1'])
289
283
        master.add(['file1'])
290
 
        master.commit('one', rev_id='m1')
 
284
        master.commit('one', rev_id=b'm1')
291
285
        self.build_tree(['./file2'])
292
286
        master.add(['file2'])
293
 
        master.commit('two', rev_id='m2')
 
287
        master.commit('two', rev_id=b'm2')
294
288
 
295
289
        sr = ScriptRunner()
296
290
        sr.run_script(self, '''
297
 
$ bzr update -r 1
 
291
$ brz update -r 1
298
292
2>-D  file2
299
293
2>All changes applied successfully.
300
294
2>Updated to revision 1 of .../master
301
295
''')
302
 
        self.failUnlessExists('./file1')
303
 
        self.failIfExists('./file2')
304
 
        self.assertEquals(['m1'], master.get_parent_ids())
 
296
        self.assertPathExists('./file1')
 
297
        self.assertPathDoesNotExist('./file2')
 
298
        self.assertEqual([b'm1'], master.get_parent_ids())
305
299
 
306
300
    def test_update_dash_r_outside_history(self):
307
301
        """Ensure that we can update -r to dotted revisions.
309
303
        master = self.make_branch_and_tree('master')
310
304
        self.build_tree(['master/file1'])
311
305
        master.add(['file1'])
312
 
        master.commit('one', rev_id='m1')
 
306
        master.commit('one', rev_id=b'm1')
313
307
 
314
308
        # Create a second branch, with extra commits
315
 
        other = master.bzrdir.sprout('other').open_workingtree()
 
309
        other = master.controldir.sprout('other').open_workingtree()
316
310
        self.build_tree(['other/file2', 'other/file3'])
317
311
        other.add(['file2'])
318
 
        other.commit('other2', rev_id='o2')
 
312
        other.commit('other2', rev_id=b'o2')
319
313
        other.add(['file3'])
320
 
        other.commit('other3', rev_id='o3')
 
314
        other.commit('other3', rev_id=b'o3')
321
315
 
322
316
        os.chdir('master')
323
317
        self.run_bzr('merge ../other')
324
 
        master.commit('merge', rev_id='merge')
 
318
        master.commit('merge', rev_id=b'merge')
325
319
 
326
320
        # Switch to o2. file3 was added only in o3 and should be deleted.
327
321
        out, err = self.run_bzr('update -r revid:o2')
328
 
        self.assertContainsRe(err, '-D\s+file3')
329
 
        self.assertContainsRe(err, 'All changes applied successfully\.')
 
322
        self.assertContainsRe(err, '-D\\s+file3')
 
323
        self.assertContainsRe(err, 'All changes applied successfully\\.')
330
324
        self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
331
325
 
332
326
        # Switch back to latest
333
327
        out, err = self.run_bzr('update')
334
 
        self.assertContainsRe(err, '\+N\s+file3')
335
 
        self.assertContainsRe(err, 'All changes applied successfully\.')
 
328
        self.assertContainsRe(err, '\\+N\\s+file3')
 
329
        self.assertContainsRe(err, 'All changes applied successfully\\.')
336
330
        self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
337
331
 
338
332
    def test_update_dash_r_in_master(self):
339
 
        # Test that 'bzr update' works correctly when you have
 
333
        # Test that 'brz update' works correctly when you have
340
334
        # an update in the master tree,
341
335
        master = self.make_branch_and_tree('master')
342
336
        self.build_tree(['master/file1'])
343
337
        master.add(['file1'])
344
 
        master.commit('one', rev_id='m1')
 
338
        master.commit('one', rev_id=b'm1')
345
339
 
346
340
        self.run_bzr('checkout master checkout')
347
341
 
348
342
        # add a revision in the master.
349
343
        self.build_tree(['master/file2'])
350
344
        master.add(['file2'])
351
 
        master.commit('two', rev_id='m2')
 
345
        master.commit('two', rev_id=b'm2')
352
346
 
353
347
        os.chdir('checkout')
354
348
        sr = ScriptRunner()
355
349
        sr.run_script(self, '''
356
 
$ bzr update -r revid:m2
 
350
$ brz update -r revid:m2
357
351
2>+N  file2
358
352
2>All changes applied successfully.
359
353
2>Updated to revision 2 of branch .../master
360
354
''')
361
355
 
 
356
    def test_update_show_base(self):
 
357
        """brz update support --show-base
 
358
 
 
359
        see https://bugs.launchpad.net/bzr/+bug/202374"""
 
360
 
 
361
        tree = self.make_branch_and_tree('.')
 
362
 
 
363
        with open('hello', 'wt') as f:
 
364
            f.write('foo')
 
365
        tree.add('hello')
 
366
        tree.commit('fie')
 
367
 
 
368
        with open('hello', 'wt') as f:
 
369
            f.write('fee')
 
370
        tree.commit('fee')
 
371
 
 
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)
 
380
 
 
381
        # check for conflict notification
 
382
        self.assertContainsString(err,
 
383
                                  ' 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
 
362
391
    def test_update_checkout_prevent_double_merge(self):
363
 
        """"Launchpad bug 113809 in bzr "update performs two merges"
 
392
        """"Launchpad bug 113809 in brz "update performs two merges"
364
393
        https://launchpad.net/bugs/113809"""
365
394
        master = self.make_branch_and_tree('master')
366
 
        self.build_tree_contents([('master/file', 'initial contents\n')])
 
395
        self.build_tree_contents([('master/file', b'initial contents\n')])
367
396
        master.add(['file'])
368
 
        master.commit('one', rev_id='m1')
 
397
        master.commit('one', rev_id=b'm1')
369
398
 
370
399
        checkout = master.branch.create_checkout('checkout')
371
400
        lightweight = checkout.branch.create_checkout('lightweight',
373
402
 
374
403
        # time to create a mess
375
404
        # 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')])
 
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')])
379
408
 
380
409
        # local commit on the checkout
381
 
        self.build_tree_contents([('checkout/file', 'checkout\n')])
382
 
        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)
383
412
        self.build_tree_contents([('checkout/file',
384
 
                                   'checkout local changes\n')])
 
413
                                   b'checkout local changes\n')])
385
414
 
386
 
        # lightweight 
 
415
        # lightweight
387
416
        self.build_tree_contents([('lightweight/file',
388
 
                                   'lightweight local changes\n')])
 
417
                                   b'lightweight local changes\n')])
389
418
 
390
419
        # now update (and get conflicts)
391
420
        out, err = self.run_bzr('update lightweight', retcode=1)
402
431
 
403
432
        # resolve it
404
433
        self.build_tree_contents([('lightweight/file',
405
 
                                   'lightweight+checkout\n')])
 
434
                                   b'lightweight+checkout\n')])
406
435
        self.run_bzr('resolve lightweight/file')
407
436
 
408
437
        # check we get the second conflict
417
446
>>>>>>> MERGE-SOURCE
418
447
''',
419
448
                             'lightweight/file')
 
449
 
 
450
    def test_no_upgrade_single_file(self):
 
451
        """There's one basis revision per tree.
 
452
 
 
453
        Since you can't actually change the basis for a single file at the
 
454
        moment, we don't let you think you can.
 
455
 
 
456
        See bug 557886.
 
457
        """
 
458
        self.make_branch_and_tree('.')
 
459
        self.build_tree_contents([('a/',),
 
460
                                  ('a/file', b'content')])
 
461
        sr = ScriptRunner()
 
462
        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 .
 
468
            2>Tree is up to date at revision 0 of branch ...
 
469
            $ cd a
 
470
            $ brz update .
 
471
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
 
472
            # however, you can update the whole tree from a subdirectory
 
473
            $ brz update
 
474
            2>Tree is up to date at revision 0 of branch ...
 
475
            ''')