~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2011-12-21 14:25:26 UTC
  • mto: This revision was merged to the branch mainline in revision 6397.
  • Revision ID: v.ladeuil+lp@free.fr-20111221142526-pnwau0xnalimujts
Provides MemoryStack to simplify configuration setup in tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
2
 
# -*- coding: utf-8 -*-
 
1
# Copyright (C) 2006-2011 Canonical Ltd
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
19
18
"""Tests for the update command of bzr."""
20
19
 
21
20
import os
22
 
import re
23
21
 
24
22
from bzrlib import (
25
23
    branch,
26
24
    bzrdir,
27
25
    osutils,
28
26
    tests,
29
 
    urlutils,
30
27
    workingtree,
31
28
    )
32
29
from bzrlib.tests.script import ScriptRunner
91
88
Updated to revision 1 of branch %s
92
89
""" % osutils.pathjoin(self.test_dir, 'branch',),
93
90
                         err)
94
 
        self.failUnlessExists('branch/file')
 
91
        self.assertPathExists('branch/file')
95
92
 
96
93
    def test_update_out_of_date_light_checkout(self):
97
94
        self.make_branch_and_tree('branch')
141
138
        # smoke test for doing an update of a checkout of a bound
142
139
        # branch with local commits.
143
140
        master = self.make_branch_and_tree('master')
 
141
        master.commit('first commit')
144
142
        # make a bound branch
145
143
        self.run_bzr('checkout master child')
146
 
        # get an object form of child
147
 
        child = workingtree.WorkingTree.open('child')
148
144
        # check that out
149
145
        self.run_bzr('checkout --lightweight child checkout')
150
146
        # get an object form of the checkout to manipulate
159
155
        a_file = file('child/file_b', 'wt')
160
156
        a_file.write('Foo')
161
157
        a_file.close()
 
158
        # get an object form of child
 
159
        child = workingtree.WorkingTree.open('child')
162
160
        child.add(['file_b'])
163
161
        child_tip = child.commit('add file_b', local=True)
164
162
        # check checkout
175
173
All changes applied successfully.
176
174
+N  file
177
175
All changes applied successfully.
178
 
Updated to revision 1 of branch %s
 
176
Updated to revision 2 of branch %s
179
177
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
180
178
""" % osutils.pathjoin(self.test_dir, 'master',),
181
179
                         err)
182
180
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
183
 
        self.failUnlessExists('checkout/file')
184
 
        self.failUnlessExists('checkout/file_b')
185
 
        self.failUnlessExists('checkout/file_c')
 
181
        self.assertPathExists('checkout/file')
 
182
        self.assertPathExists('checkout/file_b')
 
183
        self.assertPathExists('checkout/file_c')
186
184
        self.assertTrue(wt.has_filename('file_c'))
187
185
 
188
186
    def test_update_with_merges(self):
196
194
 
197
195
        self.build_tree(['checkout1/'])
198
196
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
199
 
        branch.BranchReferenceFormat().initialize(checkout_dir, master.branch)
 
197
        branch.BranchReferenceFormat().initialize(checkout_dir,
 
198
            target_branch=master.branch)
200
199
        checkout1 = checkout_dir.create_workingtree('m1')
201
200
 
202
201
        # Create a second branch, with an extra commit
241
240
        tree.commit('empty commit')
242
241
        self.run_bzr('update checkout')
243
242
 
 
243
    def test_update_with_merge_merged_to_master(self):
 
244
        # Test that 'bzr update' works correctly when you have
 
245
        # an update in the master tree, and a [lightweight or otherwise]
 
246
        # checkout which has merge a revision merged to master already.
 
247
        master = self.make_branch_and_tree('master')
 
248
        self.build_tree(['master/file'])
 
249
        master.add(['file'])
 
250
        master.commit('one', rev_id='m1')
 
251
 
 
252
        self.build_tree(['checkout1/'])
 
253
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
 
254
        branch.BranchReferenceFormat().initialize(checkout_dir,
 
255
            target_branch=master.branch)
 
256
        checkout1 = checkout_dir.create_workingtree('m1')
 
257
 
 
258
        # Create a second branch, with an extra commit
 
259
        other = master.bzrdir.sprout('other').open_workingtree()
 
260
        self.build_tree(['other/file2'])
 
261
        other.add(['file2'])
 
262
        other.commit('other2', rev_id='o2')
 
263
 
 
264
        # Merge the other branch into checkout -  'start reviewing a patch'
 
265
        checkout1.merge_from_branch(other.branch)
 
266
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 
267
 
 
268
        # Create a new commit in the master branch - 'someone else lands its'
 
269
        master.merge_from_branch(other.branch)
 
270
        master.commit('f3', rev_id='m2')
 
271
 
 
272
        # This should not report about local commits being pending
 
273
        # merges, because they were real merges (but are now gone).
 
274
        # It should perhaps report on them.
 
275
        out, err = self.run_bzr('update', working_dir='checkout1')
 
276
        self.assertEqual('', out)
 
277
        self.assertEqualDiff('''All changes applied successfully.
 
278
Updated to revision 2 of branch %s
 
279
''' % osutils.pathjoin(self.test_dir, 'master',),
 
280
                         err)
 
281
        # The pending merges should still be there
 
282
        self.assertEqual([], checkout1.get_parent_ids()[1:])
 
283
 
244
284
    def test_update_dash_r(self):
245
285
        master = self.make_branch_and_tree('master')
246
286
        os.chdir('master')
258
298
2>All changes applied successfully.
259
299
2>Updated to revision 1 of .../master
260
300
''')
261
 
        self.failUnlessExists('./file1')
262
 
        self.failIfExists('./file2')
 
301
        self.assertPathExists('./file1')
 
302
        self.assertPathDoesNotExist('./file2')
263
303
        self.assertEquals(['m1'], master.get_parent_ids())
264
304
 
265
305
    def test_update_dash_r_outside_history(self):
 
306
        """Ensure that we can update -r to dotted revisions.
 
307
        """
266
308
        master = self.make_branch_and_tree('master')
267
309
        self.build_tree(['master/file1'])
268
310
        master.add(['file1'])
269
311
        master.commit('one', rev_id='m1')
270
312
 
271
 
        # Create a second branch, with an extra commit
 
313
        # Create a second branch, with extra commits
272
314
        other = master.bzrdir.sprout('other').open_workingtree()
273
 
        self.build_tree(['other/file2'])
 
315
        self.build_tree(['other/file2', 'other/file3'])
274
316
        other.add(['file2'])
275
317
        other.commit('other2', rev_id='o2')
 
318
        other.add(['file3'])
 
319
        other.commit('other3', rev_id='o3')
276
320
 
277
321
        os.chdir('master')
278
322
        self.run_bzr('merge ../other')
279
323
        master.commit('merge', rev_id='merge')
280
324
 
281
 
        out, err = self.run_bzr('update -r revid:o2',
282
 
                                retcode=3)
283
 
        self.assertEqual('', out)
284
 
        self.assertEqual('bzr: ERROR: branch has no revision o2\n'
285
 
                         'bzr update --revision only works'
286
 
                         ' for a revision in the branch history\n',
287
 
                         err)
 
325
        # Switch to o2. file3 was added only in o3 and should be deleted.
 
326
        out, err = self.run_bzr('update -r revid:o2')
 
327
        self.assertContainsRe(err, '-D\s+file3')
 
328
        self.assertContainsRe(err, 'All changes applied successfully\.')
 
329
        self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
 
330
 
 
331
        # Switch back to latest
 
332
        out, err = self.run_bzr('update')
 
333
        self.assertContainsRe(err, '\+N\s+file3')
 
334
        self.assertContainsRe(err, 'All changes applied successfully\.')
 
335
        self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
288
336
 
289
337
    def test_update_dash_r_in_master(self):
290
338
        # Test that 'bzr update' works correctly when you have
310
358
2>Updated to revision 2 of branch .../master
311
359
''')
312
360
 
 
361
    def test_update_show_base(self):
 
362
        """bzr update support --show-base
 
363
 
 
364
        see https://bugs.launchpad.net/bzr/+bug/202374"""
 
365
 
 
366
        tree=self.make_branch_and_tree('.')
 
367
 
 
368
        f = open('hello','wt')
 
369
        f.write('foo')
 
370
        f.close()
 
371
        tree.add('hello')
 
372
        tree.commit('fie')
 
373
 
 
374
        f = open('hello','wt')
 
375
        f.write('fee')
 
376
        f.close()
 
377
        tree.commit('fee')
 
378
 
 
379
        #tree.update() gives no such revision, so ...
 
380
        self.run_bzr(['update','-r1'])
 
381
 
 
382
        #create conflict
 
383
        f = open('hello','wt')
 
384
        f.write('fie')
 
385
        f.close()
 
386
 
 
387
        out, err = self.run_bzr(['update','--show-base'],retcode=1)
 
388
 
 
389
        # check for conflict notification
 
390
        self.assertContainsString(err,
 
391
                                  ' 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())
 
398
 
313
399
    def test_update_checkout_prevent_double_merge(self):
314
400
        """"Launchpad bug 113809 in bzr "update performs two merges"
315
401
        https://launchpad.net/bugs/113809"""
341
427
        # now update (and get conflicts)
342
428
        out, err = self.run_bzr('update lightweight', retcode=1)
343
429
        self.assertEqual('', out)
 
430
        # NB: these conflicts are actually in the source code
344
431
        self.assertFileEqual('''\
345
432
<<<<<<< TREE
346
433
lightweight local changes
358
445
        # check we get the second conflict
359
446
        out, err = self.run_bzr('update lightweight', retcode=1)
360
447
        self.assertEqual('', out)
 
448
        # NB: these conflicts are actually in the source code
361
449
        self.assertFileEqual('''\
362
450
<<<<<<< TREE
363
451
lightweight+checkout
367
455
''',
368
456
                             'lightweight/file')
369
457
 
 
458
 
 
459
    def test_no_upgrade_single_file(self):
 
460
        """There's one basis revision per tree.
 
461
 
 
462
        Since you can't actually change the basis for a single file at the
 
463
        moment, we don't let you think you can.
 
464
 
 
465
        See bug 557886.
 
466
        """
 
467
        self.make_branch_and_tree('.')
 
468
        self.build_tree_contents([('a/',),
 
469
            ('a/file', 'content')])
 
470
        sr = ScriptRunner()
 
471
        sr.run_script(self, '''
 
472
            $ bzr update ./a
 
473
            2>bzr: ERROR: bzr update can only update a whole tree, not a file or subdirectory
 
474
            $ bzr update ./a/file
 
475
            2>bzr: ERROR: bzr update can only update a whole tree, not a file or subdirectory
 
476
            $ bzr update .
 
477
            2>Tree is up to date at revision 0 of branch ...
 
478
            $ cd a
 
479
            $ bzr update .
 
480
            2>bzr: ERROR: bzr update can only update a whole tree, not a file or subdirectory
 
481
            # however, you can update the whole tree from a subdirectory
 
482
            $ bzr update
 
483
            2>Tree is up to date at revision 0 of branch ...
 
484
            ''')