~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_update.py

  • Committer: Robert Collins
  • Date: 2009-12-16 22:29:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4920.
  • Revision ID: robertc@robertcollins.net-20091216222931-wbbn5ey4mwmpatwd
Review feedback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
 
2
# -*- coding: utf-8 -*-
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
28
29
    urlutils,
29
30
    workingtree,
30
31
    )
31
 
from bzrlib.tests.script import ScriptRunner
32
32
 
33
33
 
34
34
class TestUpdate(tests.TestCaseWithTransport):
67
67
    def test_update_up_to_date_checkout(self):
68
68
        self.make_branch_and_tree('branch')
69
69
        self.run_bzr('checkout branch checkout')
70
 
        sr = ScriptRunner()
71
 
        sr.run_script(self, '''
72
 
$ bzr update checkout
73
 
2>Tree is up to date at revision 0 of branch .../branch
74
 
''')
 
70
        out, err = self.run_bzr('update checkout')
 
71
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
 
72
                         % osutils.pathjoin(self.test_dir, 'branch'),
 
73
                         err)
 
74
        self.assertEqual('', out)
75
75
 
76
76
    def test_update_out_of_date_standalone_tree(self):
77
77
        # FIXME the default format has to change for this to pass
90
90
Updated to revision 1 of branch %s
91
91
""" % osutils.pathjoin(self.test_dir, 'branch',),
92
92
                         err)
93
 
        self.assertPathExists('branch/file')
 
93
        self.failUnlessExists('branch/file')
94
94
 
95
95
    def test_update_out_of_date_light_checkout(self):
96
96
        self.make_branch_and_tree('branch')
140
140
        # smoke test for doing an update of a checkout of a bound
141
141
        # branch with local commits.
142
142
        master = self.make_branch_and_tree('master')
143
 
        master.commit('first commit')
144
143
        # make a bound branch
145
144
        self.run_bzr('checkout master child')
 
145
        # get an object form of child
 
146
        child = workingtree.WorkingTree.open('child')
146
147
        # check that out
147
148
        self.run_bzr('checkout --lightweight child checkout')
148
149
        # get an object form of the checkout to manipulate
157
158
        a_file = file('child/file_b', 'wt')
158
159
        a_file.write('Foo')
159
160
        a_file.close()
160
 
        # get an object form of child
161
 
        child = workingtree.WorkingTree.open('child')
162
161
        child.add(['file_b'])
163
162
        child_tip = child.commit('add file_b', local=True)
164
163
        # check checkout
171
170
        # get all three files and a pending merge.
172
171
        out, err = self.run_bzr('update checkout')
173
172
        self.assertEqual('', out)
174
 
        self.assertEqualDiff("""+N  file_b
175
 
All changes applied successfully.
176
 
+N  file
177
 
All changes applied successfully.
178
 
Updated to revision 2 of branch %s
 
173
        self.assertEqualDiff("""+N  file
 
174
All changes applied successfully.
 
175
+N  file_b
 
176
All changes applied successfully.
 
177
Updated to revision 1 of branch %s
179
178
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
180
179
""" % osutils.pathjoin(self.test_dir, 'master',),
181
180
                         err)
182
181
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
183
 
        self.assertPathExists('checkout/file')
184
 
        self.assertPathExists('checkout/file_b')
185
 
        self.assertPathExists('checkout/file_c')
 
182
        self.failUnlessExists('checkout/file')
 
183
        self.failUnlessExists('checkout/file_b')
 
184
        self.failUnlessExists('checkout/file_c')
186
185
        self.assertTrue(wt.has_filename('file_c'))
187
186
 
188
187
    def test_update_with_merges(self):
196
195
 
197
196
        self.build_tree(['checkout1/'])
198
197
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
199
 
        branch.BranchReferenceFormat().initialize(checkout_dir,
200
 
            target_branch=master.branch)
 
198
        branch.BranchReferenceFormat().initialize(checkout_dir, master.branch)
201
199
        checkout1 = checkout_dir.create_workingtree('m1')
202
200
 
203
201
        # Create a second branch, with an extra commit
241
239
                                                   lightweight=True)
242
240
        tree.commit('empty commit')
243
241
        self.run_bzr('update checkout')
244
 
 
245
 
    def test_update_with_merge_merged_to_master(self):
246
 
        # Test that 'bzr update' works correctly when you have
247
 
        # an update in the master tree, and a [lightweight or otherwise]
248
 
        # checkout which has merge a revision merged to master already.
249
 
        master = self.make_branch_and_tree('master')
250
 
        self.build_tree(['master/file'])
251
 
        master.add(['file'])
252
 
        master.commit('one', rev_id='m1')
253
 
 
254
 
        self.build_tree(['checkout1/'])
255
 
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
256
 
        branch.BranchReferenceFormat().initialize(checkout_dir,
257
 
            target_branch=master.branch)
258
 
        checkout1 = checkout_dir.create_workingtree('m1')
259
 
 
260
 
        # Create a second branch, with an extra commit
261
 
        other = master.bzrdir.sprout('other').open_workingtree()
262
 
        self.build_tree(['other/file2'])
263
 
        other.add(['file2'])
264
 
        other.commit('other2', rev_id='o2')
265
 
 
266
 
        # Merge the other branch into checkout -  'start reviewing a patch'
267
 
        checkout1.merge_from_branch(other.branch)
268
 
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
269
 
 
270
 
        # Create a new commit in the master branch - 'someone else lands its'
271
 
        master.merge_from_branch(other.branch)
272
 
        master.commit('f3', rev_id='m2')
273
 
 
274
 
        # This should not report about local commits being pending
275
 
        # merges, because they were real merges (but are now gone).
276
 
        # It should perhaps report on them.
277
 
        out, err = self.run_bzr('update', working_dir='checkout1')
278
 
        self.assertEqual('', out)
279
 
        self.assertEqualDiff('''All changes applied successfully.
280
 
Updated to revision 2 of branch %s
281
 
''' % osutils.pathjoin(self.test_dir, 'master',),
282
 
                         err)
283
 
        # The pending merges should still be there
284
 
        self.assertEqual([], checkout1.get_parent_ids()[1:])
285
 
 
286
 
    def test_update_dash_r(self):
287
 
        master = self.make_branch_and_tree('master')
288
 
        os.chdir('master')
289
 
        self.build_tree(['./file1'])
290
 
        master.add(['file1'])
291
 
        master.commit('one', rev_id='m1')
292
 
        self.build_tree(['./file2'])
293
 
        master.add(['file2'])
294
 
        master.commit('two', rev_id='m2')
295
 
 
296
 
        sr = ScriptRunner()
297
 
        sr.run_script(self, '''
298
 
$ bzr update -r 1
299
 
2>-D  file2
300
 
2>All changes applied successfully.
301
 
2>Updated to revision 1 of .../master
302
 
''')
303
 
        self.assertPathExists('./file1')
304
 
        self.assertPathDoesNotExist('./file2')
305
 
        self.assertEquals(['m1'], master.get_parent_ids())
306
 
 
307
 
    def test_update_dash_r_outside_history(self):
308
 
        """Ensure that we can update -r to dotted revisions.
309
 
        """
310
 
        master = self.make_branch_and_tree('master')
311
 
        self.build_tree(['master/file1'])
312
 
        master.add(['file1'])
313
 
        master.commit('one', rev_id='m1')
314
 
 
315
 
        # Create a second branch, with extra commits
316
 
        other = master.bzrdir.sprout('other').open_workingtree()
317
 
        self.build_tree(['other/file2', 'other/file3'])
318
 
        other.add(['file2'])
319
 
        other.commit('other2', rev_id='o2')
320
 
        other.add(['file3'])
321
 
        other.commit('other3', rev_id='o3')
322
 
 
323
 
        os.chdir('master')
324
 
        self.run_bzr('merge ../other')
325
 
        master.commit('merge', rev_id='merge')
326
 
 
327
 
        # Switch to o2. file3 was added only in o3 and should be deleted.
328
 
        out, err = self.run_bzr('update -r revid:o2')
329
 
        self.assertContainsRe(err, '-D\s+file3')
330
 
        self.assertContainsRe(err, 'All changes applied successfully\.')
331
 
        self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
332
 
 
333
 
        # Switch back to latest
334
 
        out, err = self.run_bzr('update')
335
 
        self.assertContainsRe(err, '\+N\s+file3')
336
 
        self.assertContainsRe(err, 'All changes applied successfully\.')
337
 
        self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
338
 
 
339
 
    def test_update_dash_r_in_master(self):
340
 
        # Test that 'bzr update' works correctly when you have
341
 
        # an update in the master tree,
342
 
        master = self.make_branch_and_tree('master')
343
 
        self.build_tree(['master/file1'])
344
 
        master.add(['file1'])
345
 
        master.commit('one', rev_id='m1')
346
 
 
347
 
        self.run_bzr('checkout master checkout')
348
 
 
349
 
        # add a revision in the master.
350
 
        self.build_tree(['master/file2'])
351
 
        master.add(['file2'])
352
 
        master.commit('two', rev_id='m2')
353
 
 
354
 
        os.chdir('checkout')
355
 
        sr = ScriptRunner()
356
 
        sr.run_script(self, '''
357
 
$ bzr update -r revid:m2
358
 
2>+N  file2
359
 
2>All changes applied successfully.
360
 
2>Updated to revision 2 of branch .../master
361
 
''')
362
 
 
363
 
    def test_update_show_base(self):
364
 
        """bzr update support --show-base
365
 
 
366
 
        see https://bugs.launchpad.net/bzr/+bug/202374"""
367
 
 
368
 
        tree=self.make_branch_and_tree('.')
369
 
 
370
 
        f = open('hello','wt')
371
 
        f.write('foo')
372
 
        f.close()
373
 
        tree.add('hello')
374
 
        tree.commit('fie')
375
 
 
376
 
        f = open('hello','wt')
377
 
        f.write('fee')
378
 
        f.close()
379
 
        tree.commit('fee')
380
 
 
381
 
        #tree.update() gives no such revision, so ...
382
 
        self.run_bzr(['update','-r1'])
383
 
 
384
 
        #create conflict
385
 
        f = open('hello','wt')
386
 
        f.write('fie')
387
 
        f.close()
388
 
 
389
 
        out, err = self.run_bzr(['update','--show-base'],retcode=1)
390
 
 
391
 
        # check for conflict notification
392
 
        self.assertContainsString(err,
393
 
                                  ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
394
 
        
395
 
        self.assertEqualDiff('<<<<<<< TREE\n'
396
 
                             'fie||||||| BASE-REVISION\n'
397
 
                             'foo=======\n'
398
 
                             'fee>>>>>>> MERGE-SOURCE\n',
399
 
                             open('hello').read())
400
 
 
401
 
    def test_update_checkout_prevent_double_merge(self):
402
 
        """"Launchpad bug 113809 in bzr "update performs two merges"
403
 
        https://launchpad.net/bugs/113809"""
404
 
        master = self.make_branch_and_tree('master')
405
 
        self.build_tree_contents([('master/file', 'initial contents\n')])
406
 
        master.add(['file'])
407
 
        master.commit('one', rev_id='m1')
408
 
 
409
 
        checkout = master.branch.create_checkout('checkout')
410
 
        lightweight = checkout.branch.create_checkout('lightweight',
411
 
                                                      lightweight=True)
412
 
 
413
 
        # time to create a mess
414
 
        # add a commit to the master
415
 
        self.build_tree_contents([('master/file', 'master\n')])
416
 
        master.commit('two', rev_id='m2')
417
 
        self.build_tree_contents([('master/file', 'master local changes\n')])
418
 
 
419
 
        # local commit on the checkout
420
 
        self.build_tree_contents([('checkout/file', 'checkout\n')])
421
 
        checkout.commit('tree', rev_id='c2', local=True)
422
 
        self.build_tree_contents([('checkout/file',
423
 
                                   'checkout local changes\n')])
424
 
 
425
 
        # lightweight 
426
 
        self.build_tree_contents([('lightweight/file',
427
 
                                   'lightweight local changes\n')])
428
 
 
429
 
        # now update (and get conflicts)
430
 
        out, err = self.run_bzr('update lightweight', retcode=1)
431
 
        self.assertEqual('', out)
432
 
        # NB: these conflicts are actually in the source code
433
 
        self.assertFileEqual('''\
434
 
<<<<<<< TREE
435
 
lightweight local changes
436
 
=======
437
 
checkout
438
 
>>>>>>> MERGE-SOURCE
439
 
''',
440
 
                             'lightweight/file')
441
 
 
442
 
        # resolve it
443
 
        self.build_tree_contents([('lightweight/file',
444
 
                                   'lightweight+checkout\n')])
445
 
        self.run_bzr('resolve lightweight/file')
446
 
 
447
 
        # check we get the second conflict
448
 
        out, err = self.run_bzr('update lightweight', retcode=1)
449
 
        self.assertEqual('', out)
450
 
        # NB: these conflicts are actually in the source code
451
 
        self.assertFileEqual('''\
452
 
<<<<<<< TREE
453
 
lightweight+checkout
454
 
=======
455
 
master
456
 
>>>>>>> MERGE-SOURCE
457
 
''',
458
 
                             'lightweight/file')