~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-16 16:58:03 UTC
  • mfrom: (3224.3.1 news-typo)
  • Revision ID: pqm@pqm.ubuntu.com-20080316165803-tisoc9mpob9z544o
(Matt Nordhoff) Trivial NEWS typo fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 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
12
13
#
13
14
# You should have received a copy of the GNU General Public License
14
15
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
 
17
18
 
18
19
"""Tests for the update command of bzr."""
19
20
 
20
21
import os
21
22
 
22
 
from bzrlib import (
23
 
    branch,
24
 
    bzrdir,
25
 
    osutils,
26
 
    tests,
27
 
    workingtree,
28
 
    )
29
 
from bzrlib.tests.script import ScriptRunner
30
 
 
31
 
 
32
 
class TestUpdate(tests.TestCaseWithTransport):
 
23
from bzrlib import branch, bzrdir
 
24
from bzrlib.tests.blackbox import ExternalBase
 
25
from bzrlib.workingtree import WorkingTree
 
26
 
 
27
 
 
28
class TestUpdate(ExternalBase):
33
29
 
34
30
    def test_update_standalone_trivial(self):
35
31
        self.make_branch_and_tree('.')
36
32
        out, err = self.run_bzr('update')
37
 
        self.assertEqual(
38
 
            'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
39
 
            err)
40
 
        self.assertEqual('', out)
41
 
 
42
 
    def test_update_quiet(self):
43
 
        self.make_branch_and_tree('.')
44
 
        out, err = self.run_bzr('update --quiet')
45
 
        self.assertEqual('', err)
 
33
        self.assertEqual('Tree is up to date at revision 0.\n', err)
46
34
        self.assertEqual('', out)
47
35
 
48
36
    def test_update_standalone_trivial_with_alias_up(self):
49
37
        self.make_branch_and_tree('.')
50
38
        out, err = self.run_bzr('up')
51
 
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
52
 
                         % self.test_dir,
53
 
                         err)
 
39
        self.assertEqual('Tree is up to date at revision 0.\n', err)
54
40
        self.assertEqual('', out)
55
41
 
56
42
    def test_update_up_to_date_light_checkout(self):
57
43
        self.make_branch_and_tree('branch')
58
44
        self.run_bzr('checkout --lightweight branch checkout')
59
45
        out, err = self.run_bzr('update checkout')
60
 
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
61
 
                         % osutils.pathjoin(self.test_dir, 'branch'),
62
 
                         err)
 
46
        self.assertEqual('Tree is up to date at revision 0.\n', err)
63
47
        self.assertEqual('', out)
64
48
 
65
49
    def test_update_up_to_date_checkout(self):
66
50
        self.make_branch_and_tree('branch')
67
51
        self.run_bzr('checkout branch checkout')
68
 
        sr = ScriptRunner()
69
 
        sr.run_script(self, '''
70
 
$ bzr update checkout
71
 
2>Tree is up to date at revision 0 of branch .../branch
72
 
''')
 
52
        out, err = self.run_bzr('update checkout')
 
53
        self.assertEqual('Tree is up to date at revision 0.\n', err)
 
54
        self.assertEqual('', out)
73
55
 
74
56
    def test_update_out_of_date_standalone_tree(self):
75
57
        # FIXME the default format has to change for this to pass
83
65
        # now branch should be out of date
84
66
        out,err = self.run_bzr('update branch')
85
67
        self.assertEqual('', out)
86
 
        self.assertEqualDiff("""+N  file
87
 
All changes applied successfully.
88
 
Updated to revision 1 of branch %s
89
 
""" % osutils.pathjoin(self.test_dir, 'branch',),
90
 
                         err)
91
 
        self.assertPathExists('branch/file')
 
68
        self.assertContainsRe(err, '\+N  file')
 
69
        self.assertEndsWith(err, 'All changes applied successfully.\n'
 
70
                         'Updated to revision 1.\n')
 
71
        self.failUnlessExists('branch/file')
92
72
 
93
73
    def test_update_out_of_date_light_checkout(self):
94
74
        self.make_branch_and_tree('branch')
100
80
        self.run_bzr('commit -m add-file checkout')
101
81
        # now checkout2 should be out of date
102
82
        out,err = self.run_bzr('update checkout2')
103
 
        self.assertEqualDiff('''+N  file
104
 
All changes applied successfully.
105
 
Updated to revision 1 of branch %s
106
 
''' % osutils.pathjoin(self.test_dir, 'branch',),
107
 
                         err)
 
83
        self.assertContainsRe(err, '\+N  file')
 
84
        self.assertEndsWith(err, 'All changes applied successfully.\n'
 
85
                         'Updated to revision 1.\n')
108
86
        self.assertEqual('', out)
109
87
 
110
88
    def test_update_conflicts_returns_2(self):
126
104
        a_file.write('Bar')
127
105
        a_file.close()
128
106
        out,err = self.run_bzr('update checkout2', retcode=1)
129
 
        self.assertEqualDiff(''' M  file
130
 
Text conflict in file
131
 
1 conflicts encountered.
132
 
Updated to revision 2 of branch %s
133
 
''' % osutils.pathjoin(self.test_dir, 'branch',),
134
 
                         err)
 
107
        self.assertContainsRe(err, 'M  file')
 
108
        self.assertEqual(['1 conflicts encountered.',
 
109
                          'Updated to revision 2.'],
 
110
                         err.split('\n')[-3:-1])
 
111
        self.assertContainsRe(err, 'Text conflict in file\n')
135
112
        self.assertEqual('', out)
136
113
 
137
114
    def test_smoke_update_checkout_bound_branch_local_commits(self):
138
115
        # smoke test for doing an update of a checkout of a bound
139
116
        # branch with local commits.
140
117
        master = self.make_branch_and_tree('master')
141
 
        master.commit('first commit')
142
118
        # make a bound branch
143
119
        self.run_bzr('checkout master child')
 
120
        # get an object form of child
 
121
        child = WorkingTree.open('child')
144
122
        # check that out
145
123
        self.run_bzr('checkout --lightweight child checkout')
146
124
        # get an object form of the checkout to manipulate
147
 
        wt = workingtree.WorkingTree.open('checkout')
 
125
        wt = WorkingTree.open('checkout')
148
126
        # change master
149
127
        a_file = file('master/file', 'wt')
150
128
        a_file.write('Foo')
155
133
        a_file = file('child/file_b', 'wt')
156
134
        a_file.write('Foo')
157
135
        a_file.close()
158
 
        # get an object form of child
159
 
        child = workingtree.WorkingTree.open('child')
160
136
        child.add(['file_b'])
161
137
        child_tip = child.commit('add file_b', local=True)
162
138
        # check checkout
169
145
        # get all three files and a pending merge.
170
146
        out, err = self.run_bzr('update checkout')
171
147
        self.assertEqual('', out)
172
 
        self.assertEqualDiff("""+N  file_b
173
 
All changes applied successfully.
174
 
+N  file
175
 
All changes applied successfully.
176
 
Updated to revision 2 of branch %s
177
 
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
178
 
""" % osutils.pathjoin(self.test_dir, 'master',),
179
 
                         err)
 
148
        self.assertContainsRe(err, '\+N  file')
 
149
        self.assertContainsRe(err, '\+N  file_b')
 
150
        self.assertContainsRe(err, 'Updated to revision 1.\n'
 
151
                                   'Your local commits will now show as'
 
152
                                   ' pending merges')
180
153
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
181
 
        self.assertPathExists('checkout/file')
182
 
        self.assertPathExists('checkout/file_b')
183
 
        self.assertPathExists('checkout/file_c')
 
154
        self.failUnlessExists('checkout/file')
 
155
        self.failUnlessExists('checkout/file_b')
 
156
        self.failUnlessExists('checkout/file_c')
184
157
        self.assertTrue(wt.has_filename('file_c'))
185
158
 
186
159
    def test_update_with_merges(self):
194
167
 
195
168
        self.build_tree(['checkout1/'])
196
169
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
197
 
        branch.BranchReferenceFormat().initialize(checkout_dir,
198
 
            target_branch=master.branch)
 
170
        branch.BranchReferenceFormat().initialize(checkout_dir, master.branch)
199
171
        checkout1 = checkout_dir.create_workingtree('m1')
200
172
 
201
173
        # Create a second branch, with an extra commit
223
195
        # merges, because they were real merges
224
196
        out, err = self.run_bzr('update')
225
197
        self.assertEqual('', out)
226
 
        self.assertEqualDiff('''+N  file3
227
 
All changes applied successfully.
228
 
Updated to revision 2 of branch %s
229
 
''' % osutils.pathjoin(self.test_dir, 'master',),
230
 
                         err)
 
198
        self.assertEndsWith(err, 'All changes applied successfully.\n'
 
199
                         'Updated to revision 2.\n')
 
200
        self.assertContainsRe(err, r'\+N  file3')
231
201
        # The pending merges should still be there
232
202
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
233
203
 
239
209
                                                   lightweight=True)
240
210
        tree.commit('empty commit')
241
211
        self.run_bzr('update checkout')
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
 
 
284
 
    def test_update_dash_r(self):
285
 
        master = self.make_branch_and_tree('master')
286
 
        os.chdir('master')
287
 
        self.build_tree(['./file1'])
288
 
        master.add(['file1'])
289
 
        master.commit('one', rev_id='m1')
290
 
        self.build_tree(['./file2'])
291
 
        master.add(['file2'])
292
 
        master.commit('two', rev_id='m2')
293
 
 
294
 
        sr = ScriptRunner()
295
 
        sr.run_script(self, '''
296
 
$ bzr update -r 1
297
 
2>-D  file2
298
 
2>All changes applied successfully.
299
 
2>Updated to revision 1 of .../master
300
 
''')
301
 
        self.assertPathExists('./file1')
302
 
        self.assertPathDoesNotExist('./file2')
303
 
        self.assertEquals(['m1'], master.get_parent_ids())
304
 
 
305
 
    def test_update_dash_r_outside_history(self):
306
 
        """Ensure that we can update -r to dotted revisions.
307
 
        """
308
 
        master = self.make_branch_and_tree('master')
309
 
        self.build_tree(['master/file1'])
310
 
        master.add(['file1'])
311
 
        master.commit('one', rev_id='m1')
312
 
 
313
 
        # Create a second branch, with extra commits
314
 
        other = master.bzrdir.sprout('other').open_workingtree()
315
 
        self.build_tree(['other/file2', 'other/file3'])
316
 
        other.add(['file2'])
317
 
        other.commit('other2', rev_id='o2')
318
 
        other.add(['file3'])
319
 
        other.commit('other3', rev_id='o3')
320
 
 
321
 
        os.chdir('master')
322
 
        self.run_bzr('merge ../other')
323
 
        master.commit('merge', rev_id='merge')
324
 
 
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 .*')
336
 
 
337
 
    def test_update_dash_r_in_master(self):
338
 
        # Test that 'bzr update' works correctly when you have
339
 
        # an update in the master tree,
340
 
        master = self.make_branch_and_tree('master')
341
 
        self.build_tree(['master/file1'])
342
 
        master.add(['file1'])
343
 
        master.commit('one', rev_id='m1')
344
 
 
345
 
        self.run_bzr('checkout master checkout')
346
 
 
347
 
        # add a revision in the master.
348
 
        self.build_tree(['master/file2'])
349
 
        master.add(['file2'])
350
 
        master.commit('two', rev_id='m2')
351
 
 
352
 
        os.chdir('checkout')
353
 
        sr = ScriptRunner()
354
 
        sr.run_script(self, '''
355
 
$ bzr update -r revid:m2
356
 
2>+N  file2
357
 
2>All changes applied successfully.
358
 
2>Updated to revision 2 of branch .../master
359
 
''')
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
 
 
399
 
    def test_update_checkout_prevent_double_merge(self):
400
 
        """"Launchpad bug 113809 in bzr "update performs two merges"
401
 
        https://launchpad.net/bugs/113809"""
402
 
        master = self.make_branch_and_tree('master')
403
 
        self.build_tree_contents([('master/file', 'initial contents\n')])
404
 
        master.add(['file'])
405
 
        master.commit('one', rev_id='m1')
406
 
 
407
 
        checkout = master.branch.create_checkout('checkout')
408
 
        lightweight = checkout.branch.create_checkout('lightweight',
409
 
                                                      lightweight=True)
410
 
 
411
 
        # time to create a mess
412
 
        # 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')])
416
 
 
417
 
        # local commit on the checkout
418
 
        self.build_tree_contents([('checkout/file', 'checkout\n')])
419
 
        checkout.commit('tree', rev_id='c2', local=True)
420
 
        self.build_tree_contents([('checkout/file',
421
 
                                   'checkout local changes\n')])
422
 
 
423
 
        # lightweight 
424
 
        self.build_tree_contents([('lightweight/file',
425
 
                                   'lightweight local changes\n')])
426
 
 
427
 
        # now update (and get conflicts)
428
 
        out, err = self.run_bzr('update lightweight', retcode=1)
429
 
        self.assertEqual('', out)
430
 
        # NB: these conflicts are actually in the source code
431
 
        self.assertFileEqual('''\
432
 
<<<<<<< TREE
433
 
lightweight local changes
434
 
=======
435
 
checkout
436
 
>>>>>>> MERGE-SOURCE
437
 
''',
438
 
                             'lightweight/file')
439
 
 
440
 
        # resolve it
441
 
        self.build_tree_contents([('lightweight/file',
442
 
                                   'lightweight+checkout\n')])
443
 
        self.run_bzr('resolve lightweight/file')
444
 
 
445
 
        # check we get the second conflict
446
 
        out, err = self.run_bzr('update lightweight', retcode=1)
447
 
        self.assertEqual('', out)
448
 
        # NB: these conflicts are actually in the source code
449
 
        self.assertFileEqual('''\
450
 
<<<<<<< TREE
451
 
lightweight+checkout
452
 
=======
453
 
master
454
 
>>>>>>> MERGE-SOURCE
455
 
''',
456
 
                             'lightweight/file')
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
 
            ''')