140
141
# smoke test for doing an update of a checkout of a bound
141
142
# branch with local commits.
142
143
master = self.make_branch_and_tree('master')
143
master.commit('first commit')
144
144
# make a bound branch
145
145
self.run_bzr('checkout master child')
146
# get an object form of child
147
child = workingtree.WorkingTree.open('child')
147
149
self.run_bzr('checkout --lightweight child checkout')
148
150
# get an object form of the checkout to manipulate
171
171
# get all three files and a pending merge.
172
172
out, err = self.run_bzr('update checkout')
173
173
self.assertEqual('', out)
174
self.assertEqualDiff("""+N file_b
175
All changes applied successfully.
177
All changes applied successfully.
178
Updated to revision 2 of branch %s
174
self.assertEqualDiff("""+N file
175
All changes applied successfully.
177
All changes applied successfully.
178
Updated to revision 1 of branch %s
179
179
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
180
180
""" % osutils.pathjoin(self.test_dir, 'master',),
182
182
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
183
self.assertPathExists('checkout/file')
184
self.assertPathExists('checkout/file_b')
185
self.assertPathExists('checkout/file_c')
183
self.failUnlessExists('checkout/file')
184
self.failUnlessExists('checkout/file_b')
185
self.failUnlessExists('checkout/file_c')
186
186
self.assertTrue(wt.has_filename('file_c'))
188
188
def test_update_with_merges(self):
197
197
self.build_tree(['checkout1/'])
198
198
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
199
branch.BranchReferenceFormat().initialize(checkout_dir,
200
target_branch=master.branch)
199
branch.BranchReferenceFormat().initialize(checkout_dir, master.branch)
201
200
checkout1 = checkout_dir.create_workingtree('m1')
203
202
# Create a second branch, with an extra commit
242
241
tree.commit('empty commit')
243
242
self.run_bzr('update checkout')
245
def test_update_with_merge_merged_to_master(self):
246
# Test that 'bzr update' works correctly when you have
247
# an update in the master tree, and a [lightweight or otherwise]
248
# checkout which has merge a revision merged to master already.
249
master = self.make_branch_and_tree('master')
250
self.build_tree(['master/file'])
252
master.commit('one', rev_id='m1')
254
self.build_tree(['checkout1/'])
255
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
256
branch.BranchReferenceFormat().initialize(checkout_dir,
257
target_branch=master.branch)
258
checkout1 = checkout_dir.create_workingtree('m1')
260
# Create a second branch, with an extra commit
261
other = master.bzrdir.sprout('other').open_workingtree()
262
self.build_tree(['other/file2'])
264
other.commit('other2', rev_id='o2')
266
# Merge the other branch into checkout - 'start reviewing a patch'
267
checkout1.merge_from_branch(other.branch)
268
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
270
# Create a new commit in the master branch - 'someone else lands its'
271
master.merge_from_branch(other.branch)
272
master.commit('f3', rev_id='m2')
274
# This should not report about local commits being pending
275
# merges, because they were real merges (but are now gone).
276
# It should perhaps report on them.
277
out, err = self.run_bzr('update', working_dir='checkout1')
278
self.assertEqual('', out)
279
self.assertEqualDiff('''All changes applied successfully.
280
Updated to revision 2 of branch %s
281
''' % osutils.pathjoin(self.test_dir, 'master',),
283
# The pending merges should still be there
284
self.assertEqual([], checkout1.get_parent_ids()[1:])
286
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
287
248
master = self.make_branch_and_tree('master')
288
249
os.chdir('master')
289
250
self.build_tree(['./file1'])
300
261
2>All changes applied successfully.
301
262
2>Updated to revision 1 of .../master
303
self.assertPathExists('./file1')
304
self.assertPathDoesNotExist('./file2')
264
self.failUnlessExists('./file1')
265
self.failIfExists('./file2')
305
266
self.assertEquals(['m1'], master.get_parent_ids())
307
268
def test_update_dash_r_outside_history(self):
308
"""Ensure that we can update -r to dotted revisions.
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
310
272
master = self.make_branch_and_tree('master')
311
273
self.build_tree(['master/file1'])
312
274
master.add(['file1'])
313
275
master.commit('one', rev_id='m1')
315
# Create a second branch, with extra commits
277
# Create a second branch, with an extra commit
316
278
other = master.bzrdir.sprout('other').open_workingtree()
317
self.build_tree(['other/file2', 'other/file3'])
279
self.build_tree(['other/file2'])
318
280
other.add(['file2'])
319
281
other.commit('other2', rev_id='o2')
321
other.commit('other3', rev_id='o3')
323
283
os.chdir('master')
324
284
self.run_bzr('merge ../other')
325
285
master.commit('merge', rev_id='merge')
327
# Switch to o2. file3 was added only in o3 and should be deleted.
328
out, err = self.run_bzr('update -r revid:o2')
329
self.assertContainsRe(err, '-D\s+file3')
330
self.assertContainsRe(err, 'All changes applied successfully\.')
331
self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
333
# Switch back to latest
334
out, err = self.run_bzr('update')
335
self.assertContainsRe(err, '\+N\s+file3')
336
self.assertContainsRe(err, 'All changes applied successfully\.')
337
self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
287
out, err = self.run_bzr('update -r revid:o2',
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',
339
295
def test_update_dash_r_in_master(self):
340
296
# Test that 'bzr update' works correctly when you have
359
315
2>All changes applied successfully.
360
316
2>Updated to revision 2 of branch .../master
363
def test_update_show_base(self):
364
"""bzr update support --show-base
366
see https://bugs.launchpad.net/bzr/+bug/202374"""
368
tree=self.make_branch_and_tree('.')
370
f = open('hello','wt')
376
f = open('hello','wt')
381
#tree.update() gives no such revision, so ...
382
self.run_bzr(['update','-r1'])
385
f = open('hello','wt')
389
out, err = self.run_bzr(['update','--show-base'],retcode=1)
391
# check for conflict notification
392
self.assertContainsString(err,
393
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
395
self.assertEqualDiff('<<<<<<< TREE\n'
396
'fie||||||| BASE-REVISION\n'
398
'fee>>>>>>> MERGE-SOURCE\n',
399
open('hello').read())
401
def test_update_checkout_prevent_double_merge(self):
402
""""Launchpad bug 113809 in bzr "update performs two merges"
403
https://launchpad.net/bugs/113809"""
404
master = self.make_branch_and_tree('master')
405
self.build_tree_contents([('master/file', 'initial contents\n')])
407
master.commit('one', rev_id='m1')
409
checkout = master.branch.create_checkout('checkout')
410
lightweight = checkout.branch.create_checkout('lightweight',
413
# time to create a mess
414
# add a commit to the master
415
self.build_tree_contents([('master/file', 'master\n')])
416
master.commit('two', rev_id='m2')
417
self.build_tree_contents([('master/file', 'master local changes\n')])
419
# local commit on the checkout
420
self.build_tree_contents([('checkout/file', 'checkout\n')])
421
checkout.commit('tree', rev_id='c2', local=True)
422
self.build_tree_contents([('checkout/file',
423
'checkout local changes\n')])
426
self.build_tree_contents([('lightweight/file',
427
'lightweight local changes\n')])
429
# now update (and get conflicts)
430
out, err = self.run_bzr('update lightweight', retcode=1)
431
self.assertEqual('', out)
432
# NB: these conflicts are actually in the source code
433
self.assertFileEqual('''\
435
lightweight local changes
443
self.build_tree_contents([('lightweight/file',
444
'lightweight+checkout\n')])
445
self.run_bzr('resolve lightweight/file')
447
# check we get the second conflict
448
out, err = self.run_bzr('update lightweight', retcode=1)
449
self.assertEqual('', out)
450
# NB: these conflicts are actually in the source code
451
self.assertFileEqual('''\