~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2010-02-25 06:17:27 UTC
  • mfrom: (5055 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5057.
  • Revision ID: mbp@sourcefrog.net-20100225061727-4sd9lt0qmdc6087t
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
2
 
# -*- coding: utf-8 -*-
 
1
# Copyright (C) 2006-2010 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
 
 
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):
 
21
import re
 
22
 
 
23
from bzrlib import (
 
24
    branch,
 
25
    bzrdir,
 
26
    osutils,
 
27
    tests,
 
28
    urlutils,
 
29
    workingtree,
 
30
    )
 
31
from bzrlib.tests.script import ScriptRunner
 
32
 
 
33
 
 
34
class TestUpdate(tests.TestCaseWithTransport):
29
35
 
30
36
    def test_update_standalone_trivial(self):
31
37
        self.make_branch_and_tree('.')
32
38
        out, err = self.run_bzr('update')
33
 
        self.assertEqual('Tree is up to date at revision 0.\n', err)
 
39
        self.assertEqual(
 
40
            'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
 
41
            err)
 
42
        self.assertEqual('', out)
 
43
 
 
44
    def test_update_quiet(self):
 
45
        self.make_branch_and_tree('.')
 
46
        out, err = self.run_bzr('update --quiet')
 
47
        self.assertEqual('', err)
34
48
        self.assertEqual('', out)
35
49
 
36
50
    def test_update_standalone_trivial_with_alias_up(self):
37
51
        self.make_branch_and_tree('.')
38
52
        out, err = self.run_bzr('up')
39
 
        self.assertEqual('Tree is up to date at revision 0.\n', err)
 
53
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
 
54
                         % self.test_dir,
 
55
                         err)
40
56
        self.assertEqual('', out)
41
57
 
42
58
    def test_update_up_to_date_light_checkout(self):
43
59
        self.make_branch_and_tree('branch')
44
60
        self.run_bzr('checkout --lightweight branch checkout')
45
61
        out, err = self.run_bzr('update checkout')
46
 
        self.assertEqual('Tree is up to date at revision 0.\n', err)
 
62
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
 
63
                         % osutils.pathjoin(self.test_dir, 'branch'),
 
64
                         err)
47
65
        self.assertEqual('', out)
48
66
 
49
67
    def test_update_up_to_date_checkout(self):
50
68
        self.make_branch_and_tree('branch')
51
69
        self.run_bzr('checkout branch checkout')
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)
 
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
''')
55
75
 
56
76
    def test_update_out_of_date_standalone_tree(self):
57
77
        # FIXME the default format has to change for this to pass
65
85
        # now branch should be out of date
66
86
        out,err = self.run_bzr('update branch')
67
87
        self.assertEqual('', out)
68
 
        self.assertContainsRe(err, '\+N  file')
69
 
        self.assertEndsWith(err, 'All changes applied successfully.\n'
70
 
                         'Updated to revision 1.\n')
 
88
        self.assertEqualDiff("""+N  file
 
89
All changes applied successfully.
 
90
Updated to revision 1 of branch %s
 
91
""" % osutils.pathjoin(self.test_dir, 'branch',),
 
92
                         err)
71
93
        self.failUnlessExists('branch/file')
72
94
 
73
95
    def test_update_out_of_date_light_checkout(self):
80
102
        self.run_bzr('commit -m add-file checkout')
81
103
        # now checkout2 should be out of date
82
104
        out,err = self.run_bzr('update checkout2')
83
 
        self.assertContainsRe(err, '\+N  file')
84
 
        self.assertEndsWith(err, 'All changes applied successfully.\n'
85
 
                         'Updated to revision 1.\n')
 
105
        self.assertEqualDiff('''+N  file
 
106
All changes applied successfully.
 
107
Updated to revision 1 of branch %s
 
108
''' % osutils.pathjoin(self.test_dir, 'branch',),
 
109
                         err)
86
110
        self.assertEqual('', out)
87
111
 
88
112
    def test_update_conflicts_returns_2(self):
104
128
        a_file.write('Bar')
105
129
        a_file.close()
106
130
        out,err = self.run_bzr('update checkout2', retcode=1)
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')
 
131
        self.assertEqualDiff(''' M  file
 
132
Text conflict in file
 
133
1 conflicts encountered.
 
134
Updated to revision 2 of branch %s
 
135
''' % osutils.pathjoin(self.test_dir, 'branch',),
 
136
                         err)
112
137
        self.assertEqual('', out)
113
138
 
114
139
    def test_smoke_update_checkout_bound_branch_local_commits(self):
118
143
        # make a bound branch
119
144
        self.run_bzr('checkout master child')
120
145
        # get an object form of child
121
 
        child = WorkingTree.open('child')
 
146
        child = workingtree.WorkingTree.open('child')
122
147
        # check that out
123
148
        self.run_bzr('checkout --lightweight child checkout')
124
149
        # get an object form of the checkout to manipulate
125
 
        wt = WorkingTree.open('checkout')
 
150
        wt = workingtree.WorkingTree.open('checkout')
126
151
        # change master
127
152
        a_file = file('master/file', 'wt')
128
153
        a_file.write('Foo')
145
170
        # get all three files and a pending merge.
146
171
        out, err = self.run_bzr('update checkout')
147
172
        self.assertEqual('', out)
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')
 
173
        self.assertEqualDiff("""+N  file_b
 
174
All changes applied successfully.
 
175
+N  file
 
176
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'.
 
179
""" % osutils.pathjoin(self.test_dir, 'master',),
 
180
                         err)
153
181
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
154
182
        self.failUnlessExists('checkout/file')
155
183
        self.failUnlessExists('checkout/file_b')
195
223
        # merges, because they were real merges
196
224
        out, err = self.run_bzr('update')
197
225
        self.assertEqual('', out)
198
 
        self.assertEndsWith(err, 'All changes applied successfully.\n'
199
 
                         'Updated to revision 2.\n')
200
 
        self.assertContainsRe(err, r'\+N  file3')
 
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)
201
231
        # The pending merges should still be there
202
232
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
203
233
 
209
239
                                                   lightweight=True)
210
240
        tree.commit('empty commit')
211
241
        self.run_bzr('update checkout')
 
242
 
 
243
    def test_update_dash_r(self):
 
244
        master = self.make_branch_and_tree('master')
 
245
        os.chdir('master')
 
246
        self.build_tree(['./file1'])
 
247
        master.add(['file1'])
 
248
        master.commit('one', rev_id='m1')
 
249
        self.build_tree(['./file2'])
 
250
        master.add(['file2'])
 
251
        master.commit('two', rev_id='m2')
 
252
 
 
253
        sr = ScriptRunner()
 
254
        sr.run_script(self, '''
 
255
$ bzr update -r 1
 
256
2>-D  file2
 
257
2>All changes applied successfully.
 
258
2>Updated to revision 1 of .../master
 
259
''')
 
260
        self.failUnlessExists('./file1')
 
261
        self.failIfExists('./file2')
 
262
        self.assertEquals(['m1'], master.get_parent_ids())
 
263
 
 
264
    def test_update_dash_r_outside_history(self):
 
265
        master = self.make_branch_and_tree('master')
 
266
        self.build_tree(['master/file1'])
 
267
        master.add(['file1'])
 
268
        master.commit('one', rev_id='m1')
 
269
 
 
270
        # Create a second branch, with an extra commit
 
271
        other = master.bzrdir.sprout('other').open_workingtree()
 
272
        self.build_tree(['other/file2'])
 
273
        other.add(['file2'])
 
274
        other.commit('other2', rev_id='o2')
 
275
 
 
276
        os.chdir('master')
 
277
        self.run_bzr('merge ../other')
 
278
        master.commit('merge', rev_id='merge')
 
279
 
 
280
        out, err = self.run_bzr('update -r revid:o2',
 
281
                                retcode=3)
 
282
        self.assertEqual('', out)
 
283
        self.assertEqual('bzr: ERROR: branch has no revision o2\n'
 
284
                         'bzr update --revision only works'
 
285
                         ' for a revision in the branch history\n',
 
286
                         err)
 
287
 
 
288
    def test_update_dash_r_in_master(self):
 
289
        # Test that 'bzr update' works correctly when you have
 
290
        # an update in the master tree,
 
291
        master = self.make_branch_and_tree('master')
 
292
        self.build_tree(['master/file1'])
 
293
        master.add(['file1'])
 
294
        master.commit('one', rev_id='m1')
 
295
 
 
296
        self.run_bzr('checkout master checkout')
 
297
 
 
298
        # add a revision in the master.
 
299
        self.build_tree(['master/file2'])
 
300
        master.add(['file2'])
 
301
        master.commit('two', rev_id='m2')
 
302
 
 
303
        os.chdir('checkout')
 
304
        sr = ScriptRunner()
 
305
        sr.run_script(self, '''
 
306
$ bzr update -r revid:m2
 
307
2>+N  file2
 
308
2>All changes applied successfully.
 
309
2>Updated to revision 2 of branch .../master
 
310
''')
 
311
 
 
312
    def test_update_checkout_prevent_double_merge(self):
 
313
        """"Launchpad bug 113809 in bzr "update performs two merges"
 
314
        https://launchpad.net/bugs/113809"""
 
315
        master = self.make_branch_and_tree('master')
 
316
        self.build_tree_contents([('master/file', 'initial contents\n')])
 
317
        master.add(['file'])
 
318
        master.commit('one', rev_id='m1')
 
319
 
 
320
        checkout = master.branch.create_checkout('checkout')
 
321
        lightweight = checkout.branch.create_checkout('lightweight',
 
322
                                                      lightweight=True)
 
323
 
 
324
        # time to create a mess
 
325
        # add a commit to the master
 
326
        self.build_tree_contents([('master/file', 'master\n')])
 
327
        master.commit('two', rev_id='m2')
 
328
        self.build_tree_contents([('master/file', 'master local changes\n')])
 
329
 
 
330
        # local commit on the checkout
 
331
        self.build_tree_contents([('checkout/file', 'checkout\n')])
 
332
        checkout.commit('tree', rev_id='c2', local=True)
 
333
        self.build_tree_contents([('checkout/file',
 
334
                                   'checkout local changes\n')])
 
335
 
 
336
        # lightweight 
 
337
        self.build_tree_contents([('lightweight/file',
 
338
                                   'lightweight local changes\n')])
 
339
 
 
340
        # now update (and get conflicts)
 
341
        out, err = self.run_bzr('update lightweight', retcode=1)
 
342
        self.assertEqual('', out)
 
343
        # NB: these conflicts are actually in the source code
 
344
        self.assertFileEqual('''\
 
345
<<<<<<< TREE
 
346
lightweight local changes
 
347
=======
 
348
checkout
 
349
>>>>>>> MERGE-SOURCE
 
350
''',
 
351
                             'lightweight/file')
 
352
 
 
353
        # resolve it
 
354
        self.build_tree_contents([('lightweight/file',
 
355
                                   'lightweight+checkout\n')])
 
356
        self.run_bzr('resolve lightweight/file')
 
357
 
 
358
        # check we get the second conflict
 
359
        out, err = self.run_bzr('update lightweight', retcode=1)
 
360
        self.assertEqual('', out)
 
361
        # NB: these conflicts are actually in the source code
 
362
        self.assertFileEqual('''\
 
363
<<<<<<< TREE
 
364
lightweight+checkout
 
365
=======
 
366
master
 
367
>>>>>>> MERGE-SOURCE
 
368
''',
 
369
                             'lightweight/file')