19
19
"""Tests for the update command of bzr."""
32
from bzrlib.tests.script import ScriptRunner
35
class TestUpdate(tests.TestCaseWithTransport):
23
from bzrlib import branch, bzrdir
24
from bzrlib.tests.blackbox import ExternalBase
25
from bzrlib.workingtree import WorkingTree
28
class TestUpdate(ExternalBase):
37
30
def test_update_standalone_trivial(self):
38
31
self.make_branch_and_tree('.')
39
32
out, err = self.run_bzr('update')
41
'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
43
self.assertEqual('', out)
45
def test_update_quiet(self):
46
self.make_branch_and_tree('.')
47
out, err = self.run_bzr('update --quiet')
48
self.assertEqual('', err)
33
self.assertEqual('Tree is up to date at revision 0.\n', err)
49
34
self.assertEqual('', out)
51
36
def test_update_standalone_trivial_with_alias_up(self):
52
37
self.make_branch_and_tree('.')
53
38
out, err = self.run_bzr('up')
54
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
39
self.assertEqual('Tree is up to date at revision 0.\n', err)
57
40
self.assertEqual('', out)
59
42
def test_update_up_to_date_light_checkout(self):
60
43
self.make_branch_and_tree('branch')
61
44
self.run_bzr('checkout --lightweight branch checkout')
62
45
out, err = self.run_bzr('update checkout')
63
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
64
% osutils.pathjoin(self.test_dir, 'branch'),
46
self.assertEqual('Tree is up to date at revision 0.\n', err)
66
47
self.assertEqual('', out)
68
49
def test_update_up_to_date_checkout(self):
69
50
self.make_branch_and_tree('branch')
70
51
self.run_bzr('checkout branch checkout')
72
sr.run_script(self, '''
74
2>Tree is up to date at revision 0 of branch .../branch
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)
77
56
def test_update_out_of_date_standalone_tree(self):
78
57
# FIXME the default format has to change for this to pass
86
65
# now branch should be out of date
87
66
out,err = self.run_bzr('update branch')
88
67
self.assertEqual('', out)
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',),
68
self.assertContainsRe(err, '\+N file')
69
self.assertEndsWith(err, 'All changes applied successfully.\n'
70
'Updated to revision 1.\n')
94
71
self.failUnlessExists('branch/file')
96
73
def test_update_out_of_date_light_checkout(self):
103
80
self.run_bzr('commit -m add-file checkout')
104
81
# now checkout2 should be out of date
105
82
out,err = self.run_bzr('update checkout2')
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',),
83
self.assertContainsRe(err, '\+N file')
84
self.assertEndsWith(err, 'All changes applied successfully.\n'
85
'Updated to revision 1.\n')
111
86
self.assertEqual('', out)
113
88
def test_update_conflicts_returns_2(self):
129
104
a_file.write('Bar')
131
106
out,err = self.run_bzr('update checkout2', retcode=1)
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',),
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')
138
112
self.assertEqual('', out)
140
114
def test_smoke_update_checkout_bound_branch_local_commits(self):
171
145
# get all three files and a pending merge.
172
146
out, err = self.run_bzr('update checkout')
173
147
self.assertEqual('', out)
174
self.assertEqualDiff("""+N file_b
175
All changes applied successfully.
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',),
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'
182
153
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
183
154
self.failUnlessExists('checkout/file')
184
155
self.failUnlessExists('checkout/file_b')
224
195
# merges, because they were real merges
225
196
out, err = self.run_bzr('update')
226
197
self.assertEqual('', out)
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',),
198
self.assertEndsWith(err, 'All changes applied successfully.\n'
199
'Updated to revision 2.\n')
200
self.assertContainsRe(err, r'\+N file3')
232
201
# The pending merges should still be there
233
202
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
240
209
lightweight=True)
241
210
tree.commit('empty commit')
242
211
self.run_bzr('update checkout')
244
def test_update_dash_r(self):
245
master = self.make_branch_and_tree('master')
247
self.build_tree(['./file1'])
248
master.add(['file1'])
249
master.commit('one', rev_id='m1')
250
self.build_tree(['./file2'])
251
master.add(['file2'])
252
master.commit('two', rev_id='m2')
255
sr.run_script(self, '''
258
2>All changes applied successfully.
259
2>Updated to revision 1 of .../master
261
self.failUnlessExists('./file1')
262
self.failIfExists('./file2')
263
self.assertEquals(['m1'], master.get_parent_ids())
265
def test_update_dash_r_outside_history(self):
266
master = self.make_branch_and_tree('master')
267
self.build_tree(['master/file1'])
268
master.add(['file1'])
269
master.commit('one', rev_id='m1')
271
# Create a second branch, with an extra commit
272
other = master.bzrdir.sprout('other').open_workingtree()
273
self.build_tree(['other/file2'])
275
other.commit('other2', rev_id='o2')
278
self.run_bzr('merge ../other')
279
master.commit('merge', rev_id='merge')
281
out, err = self.run_bzr('update -r revid:o2',
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',
289
def test_update_dash_r_in_master(self):
290
# Test that 'bzr update' works correctly when you have
291
# an update in the master tree,
292
master = self.make_branch_and_tree('master')
293
self.build_tree(['master/file1'])
294
master.add(['file1'])
295
master.commit('one', rev_id='m1')
297
self.run_bzr('checkout master checkout')
299
# add a revision in the master.
300
self.build_tree(['master/file2'])
301
master.add(['file2'])
302
master.commit('two', rev_id='m2')
306
sr.run_script(self, '''
307
$ bzr update -r revid:m2
309
2>All changes applied successfully.
310
2>Updated to revision 2 of branch .../master
313
def test_update_checkout_prevent_double_merge(self):
314
""""Launchpad bug 113809 in bzr "update performs two merges"
315
https://launchpad.net/bugs/113809"""
316
master = self.make_branch_and_tree('master')
317
self.build_tree_contents([('master/file', 'initial contents\n')])
319
master.commit('one', rev_id='m1')
321
checkout = master.branch.create_checkout('checkout')
322
lightweight = checkout.branch.create_checkout('lightweight',
325
# time to create a mess
326
# add a commit to the master
327
self.build_tree_contents([('master/file', 'master\n')])
328
master.commit('two', rev_id='m2')
329
self.build_tree_contents([('master/file', 'master local changes\n')])
331
# local commit on the checkout
332
self.build_tree_contents([('checkout/file', 'checkout\n')])
333
checkout.commit('tree', rev_id='c2', local=True)
334
self.build_tree_contents([('checkout/file',
335
'checkout local changes\n')])
338
self.build_tree_contents([('lightweight/file',
339
'lightweight local changes\n')])
341
# now update (and get conflicts)
342
out, err = self.run_bzr('update lightweight', retcode=1)
343
self.assertEqual('', out)
344
self.assertFileEqual('''\
346
lightweight local changes
354
self.build_tree_contents([('lightweight/file',
355
'lightweight+checkout\n')])
356
self.run_bzr('resolve lightweight/file')
358
# check we get the second conflict
359
out, err = self.run_bzr('update lightweight', retcode=1)
360
self.assertEqual('', out)
361
self.assertFileEqual('''\