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
18
19
"""Tests for the update command of bzr."""
29
from bzrlib.tests.script import ScriptRunner
32
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):
34
30
def test_update_standalone_trivial(self):
35
31
self.make_branch_and_tree('.')
36
32
out, err = self.run_bzr('update')
38
'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
40
self.assertEqual('', out)
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)
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'
39
self.assertEqual('Tree is up to date at revision 0.\n', err)
54
40
self.assertEqual('', out)
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'),
46
self.assertEqual('Tree is up to date at revision 0.\n', err)
63
47
self.assertEqual('', out)
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')
69
sr.run_script(self, '''
71
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)
74
56
def test_update_out_of_date_standalone_tree(self):
75
57
# FIXME the default format has to change for this to pass
239
209
lightweight=True)
240
210
tree.commit('empty commit')
241
211
self.run_bzr('update checkout')
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'])
250
master.commit('one', rev_id='m1')
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')
258
# Create a second branch, with an extra commit
259
other = master.bzrdir.sprout('other').open_workingtree()
260
self.build_tree(['other/file2'])
262
other.commit('other2', rev_id='o2')
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:])
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')
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',),
281
# The pending merges should still be there
282
self.assertEqual([], checkout1.get_parent_ids()[1:])
284
def test_update_dash_r(self):
285
master = self.make_branch_and_tree('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')
295
sr.run_script(self, '''
298
2>All changes applied successfully.
299
2>Updated to revision 1 of .../master
301
self.assertPathExists('./file1')
302
self.assertPathDoesNotExist('./file2')
303
self.assertEquals(['m1'], master.get_parent_ids())
305
def test_update_dash_r_outside_history(self):
306
"""Ensure that we can update -r to dotted revisions.
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')
313
# Create a second branch, with extra commits
314
other = master.bzrdir.sprout('other').open_workingtree()
315
self.build_tree(['other/file2', 'other/file3'])
317
other.commit('other2', rev_id='o2')
319
other.commit('other3', rev_id='o3')
322
self.run_bzr('merge ../other')
323
master.commit('merge', rev_id='merge')
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 .*')
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 .*')
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')
345
self.run_bzr('checkout master checkout')
347
# add a revision in the master.
348
self.build_tree(['master/file2'])
349
master.add(['file2'])
350
master.commit('two', rev_id='m2')
354
sr.run_script(self, '''
355
$ bzr update -r revid:m2
357
2>All changes applied successfully.
358
2>Updated to revision 2 of branch .../master
361
def test_update_show_base(self):
362
"""bzr update support --show-base
364
see https://bugs.launchpad.net/bzr/+bug/202374"""
366
tree=self.make_branch_and_tree('.')
368
f = open('hello','wt')
374
f = open('hello','wt')
379
#tree.update() gives no such revision, so ...
380
self.run_bzr(['update','-r1'])
383
f = open('hello','wt')
387
out, err = self.run_bzr(['update','--show-base'],retcode=1)
389
# check for conflict notification
390
self.assertContainsString(err,
391
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
393
self.assertEqualDiff('<<<<<<< TREE\n'
394
'fie||||||| BASE-REVISION\n'
396
'fee>>>>>>> MERGE-SOURCE\n',
397
open('hello').read())
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')])
405
master.commit('one', rev_id='m1')
407
checkout = master.branch.create_checkout('checkout')
408
lightweight = checkout.branch.create_checkout('lightweight',
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')])
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')])
424
self.build_tree_contents([('lightweight/file',
425
'lightweight local changes\n')])
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('''\
433
lightweight local changes
441
self.build_tree_contents([('lightweight/file',
442
'lightweight+checkout\n')])
443
self.run_bzr('resolve lightweight/file')
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('''\
459
def test_no_upgrade_single_file(self):
460
"""There's one basis revision per tree.
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.
467
self.make_branch_and_tree('.')
468
self.build_tree_contents([('a/',),
469
('a/file', 'content')])
471
sr.run_script(self, '''
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
477
2>Tree is up to date at revision 0 of branch ...
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
483
2>Tree is up to date at revision 0 of branch ...