~ubuntu-branches/ubuntu/maverick/bzr/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-02-17 17:47:40 UTC
  • mfrom: (1.4.5 upstream) (9.2.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20100217174740-35yh6t5rjnztg9z6
Tags: 2.1.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2009 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
19
19
"""Tests for the update command of bzr."""
20
20
 
21
21
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):
 
22
import re
 
23
 
 
24
from bzrlib import (
 
25
    branch,
 
26
    bzrdir,
 
27
    osutils,
 
28
    tests,
 
29
    urlutils,
 
30
    workingtree,
 
31
    )
 
32
from bzrlib.tests.script import ScriptRunner
 
33
 
 
34
 
 
35
class TestUpdate(tests.TestCaseWithTransport):
29
36
 
30
37
    def test_update_standalone_trivial(self):
31
38
        self.make_branch_and_tree('.')
32
39
        out, err = self.run_bzr('update')
33
 
        self.assertEqual('Tree is up to date at revision 0.\n', err)
 
40
        self.assertEqual(
 
41
            'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
 
42
            err)
 
43
        self.assertEqual('', out)
 
44
 
 
45
    def test_update_quiet(self):
 
46
        self.make_branch_and_tree('.')
 
47
        out, err = self.run_bzr('update --quiet')
 
48
        self.assertEqual('', err)
34
49
        self.assertEqual('', out)
35
50
 
36
51
    def test_update_standalone_trivial_with_alias_up(self):
37
52
        self.make_branch_and_tree('.')
38
53
        out, err = self.run_bzr('up')
39
 
        self.assertEqual('Tree is up to date at revision 0.\n', err)
 
54
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
 
55
                         % self.test_dir,
 
56
                         err)
40
57
        self.assertEqual('', out)
41
58
 
42
59
    def test_update_up_to_date_light_checkout(self):
43
60
        self.make_branch_and_tree('branch')
44
61
        self.run_bzr('checkout --lightweight branch checkout')
45
62
        out, err = self.run_bzr('update checkout')
46
 
        self.assertEqual('Tree is up to date at revision 0.\n', err)
 
63
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
 
64
                         % osutils.pathjoin(self.test_dir, 'branch'),
 
65
                         err)
47
66
        self.assertEqual('', out)
48
67
 
49
68
    def test_update_up_to_date_checkout(self):
50
69
        self.make_branch_and_tree('branch')
51
70
        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)
 
71
        sr = ScriptRunner()
 
72
        sr.run_script(self, '''
 
73
$ bzr update checkout
 
74
2>Tree is up to date at revision 0 of branch .../branch
 
75
''')
55
76
 
56
77
    def test_update_out_of_date_standalone_tree(self):
57
78
        # FIXME the default format has to change for this to pass
65
86
        # now branch should be out of date
66
87
        out,err = self.run_bzr('update branch')
67
88
        self.assertEqual('', out)
68
 
        self.assertContainsRe(err, '\+N  file')
69
 
        self.assertEndsWith(err, 'All changes applied successfully.\n'
70
 
                         'Updated to revision 1.\n')
 
89
        self.assertEqualDiff("""+N  file
 
90
All changes applied successfully.
 
91
Updated to revision 1 of branch %s
 
92
""" % osutils.pathjoin(self.test_dir, 'branch',),
 
93
                         err)
71
94
        self.failUnlessExists('branch/file')
72
95
 
73
96
    def test_update_out_of_date_light_checkout(self):
80
103
        self.run_bzr('commit -m add-file checkout')
81
104
        # now checkout2 should be out of date
82
105
        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')
 
106
        self.assertEqualDiff('''+N  file
 
107
All changes applied successfully.
 
108
Updated to revision 1 of branch %s
 
109
''' % osutils.pathjoin(self.test_dir, 'branch',),
 
110
                         err)
86
111
        self.assertEqual('', out)
87
112
 
88
113
    def test_update_conflicts_returns_2(self):
104
129
        a_file.write('Bar')
105
130
        a_file.close()
106
131
        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')
 
132
        self.assertEqualDiff(''' M  file
 
133
Text conflict in file
 
134
1 conflicts encountered.
 
135
Updated to revision 2 of branch %s
 
136
''' % osutils.pathjoin(self.test_dir, 'branch',),
 
137
                         err)
112
138
        self.assertEqual('', out)
113
139
 
114
140
    def test_smoke_update_checkout_bound_branch_local_commits(self):
118
144
        # make a bound branch
119
145
        self.run_bzr('checkout master child')
120
146
        # get an object form of child
121
 
        child = WorkingTree.open('child')
 
147
        child = workingtree.WorkingTree.open('child')
122
148
        # check that out
123
149
        self.run_bzr('checkout --lightweight child checkout')
124
150
        # get an object form of the checkout to manipulate
125
 
        wt = WorkingTree.open('checkout')
 
151
        wt = workingtree.WorkingTree.open('checkout')
126
152
        # change master
127
153
        a_file = file('master/file', 'wt')
128
154
        a_file.write('Foo')
145
171
        # get all three files and a pending merge.
146
172
        out, err = self.run_bzr('update checkout')
147
173
        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')
 
174
        self.assertEqualDiff("""+N  file
 
175
All changes applied successfully.
 
176
+N  file_b
 
177
All changes applied successfully.
 
178
Updated to revision 1 of branch %s
 
179
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
 
180
""" % osutils.pathjoin(self.test_dir, 'master',),
 
181
                         err)
153
182
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
154
183
        self.failUnlessExists('checkout/file')
155
184
        self.failUnlessExists('checkout/file_b')
195
224
        # merges, because they were real merges
196
225
        out, err = self.run_bzr('update')
197
226
        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')
 
227
        self.assertEqualDiff('''+N  file3
 
228
All changes applied successfully.
 
229
Updated to revision 2 of branch %s
 
230
''' % osutils.pathjoin(self.test_dir, 'master',),
 
231
                         err)
201
232
        # The pending merges should still be there
202
233
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
203
234
 
209
240
                                                   lightweight=True)
210
241
        tree.commit('empty commit')
211
242
        self.run_bzr('update checkout')
 
243
 
 
244
    def test_update_dash_r(self):
 
245
        # Test that 'bzr update' works correctly when you have
 
246
        # an update in the master tree, and a lightweight checkout
 
247
        # which has merged another branch
 
248
        master = self.make_branch_and_tree('master')
 
249
        os.chdir('master')
 
250
        self.build_tree(['./file1'])
 
251
        master.add(['file1'])
 
252
        master.commit('one', rev_id='m1')
 
253
        self.build_tree(['./file2'])
 
254
        master.add(['file2'])
 
255
        master.commit('two', rev_id='m2')
 
256
 
 
257
        sr = ScriptRunner()
 
258
        sr.run_script(self, '''
 
259
$ bzr update -r 1
 
260
2>-D  file2
 
261
2>All changes applied successfully.
 
262
2>Updated to revision 1 of .../master
 
263
''')
 
264
        self.failUnlessExists('./file1')
 
265
        self.failIfExists('./file2')
 
266
        self.assertEquals(['m1'], master.get_parent_ids())
 
267
 
 
268
    def test_update_dash_r_outside_history(self):
 
269
        # Test that 'bzr update' works correctly when you have
 
270
        # an update in the master tree, and a lightweight checkout
 
271
        # which has merged another branch
 
272
        master = self.make_branch_and_tree('master')
 
273
        self.build_tree(['master/file1'])
 
274
        master.add(['file1'])
 
275
        master.commit('one', rev_id='m1')
 
276
 
 
277
        # Create a second branch, with an extra commit
 
278
        other = master.bzrdir.sprout('other').open_workingtree()
 
279
        self.build_tree(['other/file2'])
 
280
        other.add(['file2'])
 
281
        other.commit('other2', rev_id='o2')
 
282
 
 
283
        os.chdir('master')
 
284
        self.run_bzr('merge ../other')
 
285
        master.commit('merge', rev_id='merge')
 
286
 
 
287
        out, err = self.run_bzr('update -r revid:o2',
 
288
                                retcode=3)
 
289
        self.assertEqual('', out)
 
290
        self.assertEqual('bzr: ERROR: branch has no revision o2\n'
 
291
                         'bzr update --revision only works'
 
292
                         ' for a revision in the branch history\n',
 
293
                         err)
 
294
 
 
295
    def test_update_dash_r_in_master(self):
 
296
        # Test that 'bzr update' works correctly when you have
 
297
        # an update in the master tree,
 
298
        master = self.make_branch_and_tree('master')
 
299
        self.build_tree(['master/file1'])
 
300
        master.add(['file1'])
 
301
        master.commit('one', rev_id='m1')
 
302
 
 
303
        self.run_bzr('checkout master checkout')
 
304
 
 
305
        # add a revision in the master.
 
306
        self.build_tree(['master/file2'])
 
307
        master.add(['file2'])
 
308
        master.commit('two', rev_id='m2')
 
309
 
 
310
        os.chdir('checkout')
 
311
        sr = ScriptRunner()
 
312
        sr.run_script(self, '''
 
313
$ bzr update -r revid:m2
 
314
2>+N  file2
 
315
2>All changes applied successfully.
 
316
2>Updated to revision 2 of branch .../master
 
317
''')