18
19
"""Tests for the update command of bzr."""
31
from bzrlib.tests.script import ScriptRunner
34
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):
36
30
def test_update_standalone_trivial(self):
37
31
self.make_branch_and_tree('.')
38
32
out, err = self.run_bzr('update')
40
'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
42
self.assertEqual('', out)
44
def test_update_quiet(self):
45
self.make_branch_and_tree('.')
46
out, err = self.run_bzr('update --quiet')
47
self.assertEqual('', err)
33
self.assertEqual('Tree is up to date at revision 0.\n', err)
48
34
self.assertEqual('', out)
50
36
def test_update_standalone_trivial_with_alias_up(self):
51
37
self.make_branch_and_tree('.')
52
38
out, err = self.run_bzr('up')
53
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)
56
40
self.assertEqual('', out)
58
42
def test_update_up_to_date_light_checkout(self):
59
43
self.make_branch_and_tree('branch')
60
44
self.run_bzr('checkout --lightweight branch checkout')
61
45
out, err = self.run_bzr('update checkout')
62
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
63
% osutils.pathjoin(self.test_dir, 'branch'),
46
self.assertEqual('Tree is up to date at revision 0.\n', err)
65
47
self.assertEqual('', out)
67
49
def test_update_up_to_date_checkout(self):
68
50
self.make_branch_and_tree('branch')
69
51
self.run_bzr('checkout branch checkout')
71
sr.run_script(self, '''
73
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)
76
56
def test_update_out_of_date_standalone_tree(self):
77
57
# FIXME the default format has to change for this to pass
240
209
lightweight=True)
241
210
tree.commit('empty commit')
242
211
self.run_bzr('update checkout')
244
def test_update_with_merge_merged_to_master(self):
245
# Test that 'bzr update' works correctly when you have
246
# an update in the master tree, and a [lightweight or otherwise]
247
# checkout which has merge a revision merged to master already.
248
master = self.make_branch_and_tree('master')
249
self.build_tree(['master/file'])
251
master.commit('one', rev_id='m1')
253
self.build_tree(['checkout1/'])
254
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
255
branch.BranchReferenceFormat().initialize(checkout_dir,
256
target_branch=master.branch)
257
checkout1 = checkout_dir.create_workingtree('m1')
259
# Create a second branch, with an extra commit
260
other = master.bzrdir.sprout('other').open_workingtree()
261
self.build_tree(['other/file2'])
263
other.commit('other2', rev_id='o2')
265
# Merge the other branch into checkout - 'start reviewing a patch'
266
checkout1.merge_from_branch(other.branch)
267
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
269
# Create a new commit in the master branch - 'someone else lands its'
270
master.merge_from_branch(other.branch)
271
master.commit('f3', rev_id='m2')
273
# This should not report about local commits being pending
274
# merges, because they were real merges (but are now gone).
275
# It should perhaps report on them.
276
out, err = self.run_bzr('update', working_dir='checkout1')
277
self.assertEqual('', out)
278
self.assertEqualDiff('''All changes applied successfully.
279
Updated to revision 2 of branch %s
280
''' % osutils.pathjoin(self.test_dir, 'master',),
282
# The pending merges should still be there
283
self.assertEqual([], checkout1.get_parent_ids()[1:])
285
def test_update_dash_r(self):
286
master = self.make_branch_and_tree('master')
288
self.build_tree(['./file1'])
289
master.add(['file1'])
290
master.commit('one', rev_id='m1')
291
self.build_tree(['./file2'])
292
master.add(['file2'])
293
master.commit('two', rev_id='m2')
296
sr.run_script(self, '''
299
2>All changes applied successfully.
300
2>Updated to revision 1 of .../master
302
self.failUnlessExists('./file1')
303
self.failIfExists('./file2')
304
self.assertEquals(['m1'], master.get_parent_ids())
306
def test_update_dash_r_outside_history(self):
307
"""Ensure that we can update -r to dotted revisions.
309
master = self.make_branch_and_tree('master')
310
self.build_tree(['master/file1'])
311
master.add(['file1'])
312
master.commit('one', rev_id='m1')
314
# Create a second branch, with extra commits
315
other = master.bzrdir.sprout('other').open_workingtree()
316
self.build_tree(['other/file2', 'other/file3'])
318
other.commit('other2', rev_id='o2')
320
other.commit('other3', rev_id='o3')
323
self.run_bzr('merge ../other')
324
master.commit('merge', rev_id='merge')
326
# Switch to o2. file3 was added only in o3 and should be deleted.
327
out, err = self.run_bzr('update -r revid:o2')
328
self.assertContainsRe(err, '-D\s+file3')
329
self.assertContainsRe(err, 'All changes applied successfully\.')
330
self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
332
# Switch back to latest
333
out, err = self.run_bzr('update')
334
self.assertContainsRe(err, '\+N\s+file3')
335
self.assertContainsRe(err, 'All changes applied successfully\.')
336
self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
338
def test_update_dash_r_in_master(self):
339
# Test that 'bzr update' works correctly when you have
340
# an update in the master tree,
341
master = self.make_branch_and_tree('master')
342
self.build_tree(['master/file1'])
343
master.add(['file1'])
344
master.commit('one', rev_id='m1')
346
self.run_bzr('checkout master checkout')
348
# add a revision in the master.
349
self.build_tree(['master/file2'])
350
master.add(['file2'])
351
master.commit('two', rev_id='m2')
355
sr.run_script(self, '''
356
$ bzr update -r revid:m2
358
2>All changes applied successfully.
359
2>Updated to revision 2 of branch .../master
362
def test_update_checkout_prevent_double_merge(self):
363
""""Launchpad bug 113809 in bzr "update performs two merges"
364
https://launchpad.net/bugs/113809"""
365
master = self.make_branch_and_tree('master')
366
self.build_tree_contents([('master/file', 'initial contents\n')])
368
master.commit('one', rev_id='m1')
370
checkout = master.branch.create_checkout('checkout')
371
lightweight = checkout.branch.create_checkout('lightweight',
374
# time to create a mess
375
# add a commit to the master
376
self.build_tree_contents([('master/file', 'master\n')])
377
master.commit('two', rev_id='m2')
378
self.build_tree_contents([('master/file', 'master local changes\n')])
380
# local commit on the checkout
381
self.build_tree_contents([('checkout/file', 'checkout\n')])
382
checkout.commit('tree', rev_id='c2', local=True)
383
self.build_tree_contents([('checkout/file',
384
'checkout local changes\n')])
387
self.build_tree_contents([('lightweight/file',
388
'lightweight local changes\n')])
390
# now update (and get conflicts)
391
out, err = self.run_bzr('update lightweight', retcode=1)
392
self.assertEqual('', out)
393
# NB: these conflicts are actually in the source code
394
self.assertFileEqual('''\
396
lightweight local changes
404
self.build_tree_contents([('lightweight/file',
405
'lightweight+checkout\n')])
406
self.run_bzr('resolve lightweight/file')
408
# check we get the second conflict
409
out, err = self.run_bzr('update lightweight', retcode=1)
410
self.assertEqual('', out)
411
# NB: these conflicts are actually in the source code
412
self.assertFileEqual('''\