116
118
self.run_bzr('commit -m add-file checkout')
117
119
self.run_bzr('checkout --lightweight branch checkout2')
118
120
# now alter file in checkout
119
a_file = file('checkout/file', 'wt')
121
with open('checkout/file', 'wt') as a_file:
122
123
self.run_bzr('commit -m checnge-file checkout')
123
124
# now checkout2 should be out of date
124
125
# make a local change to file
125
a_file = file('checkout2/file', 'wt')
128
out,err = self.run_bzr('update checkout2', retcode=1)
126
with open('checkout2/file', 'wt') as a_file:
128
out, err = self.run_bzr('update checkout2', retcode=1)
129
129
self.assertEqualDiff(''' M file
130
130
Text conflict in file
131
131
1 conflicts encountered.
132
132
Updated to revision 2 of branch %s
133
133
''' % osutils.pathjoin(self.test_dir, 'branch',),
135
135
self.assertEqual('', out)
137
137
def test_smoke_update_checkout_bound_branch_local_commits(self):
184
181
self.assertTrue(wt.has_filename('file_c'))
186
183
def test_update_with_merges(self):
187
# Test that 'bzr update' works correctly when you have
184
# Test that 'brz update' works correctly when you have
188
185
# an update in the master tree, and a lightweight checkout
189
186
# which has merged another branch
190
187
master = self.make_branch_and_tree('master')
191
188
self.build_tree(['master/file'])
192
189
master.add(['file'])
193
master.commit('one', rev_id='m1')
190
master.commit('one', rev_id=b'm1')
195
192
self.build_tree(['checkout1/'])
196
193
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
197
194
checkout_dir.set_branch_reference(master.branch)
198
checkout1 = checkout_dir.create_workingtree('m1')
195
checkout1 = checkout_dir.create_workingtree(b'm1')
200
197
# Create a second branch, with an extra commit
201
other = master.bzrdir.sprout('other').open_workingtree()
198
other = master.controldir.sprout('other').open_workingtree()
202
199
self.build_tree(['other/file2'])
203
200
other.add(['file2'])
204
other.commit('other2', rev_id='o2')
201
other.commit('other2', rev_id=b'o2')
206
203
# Create a new commit in the master branch
207
204
self.build_tree(['master/file3'])
208
205
master.add(['file3'])
209
master.commit('f3', rev_id='m2')
206
master.commit('f3', rev_id=b'm2')
211
208
# Merge the other branch into checkout
212
209
os.chdir('checkout1')
213
210
self.run_bzr('merge ../other')
215
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
212
self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
217
214
# At this point, 'commit' should fail, because we are out of date
218
self.run_bzr_error(["please run 'bzr update'"],
215
self.run_bzr_error(["please run 'brz update'"],
219
216
'commit -m merged')
221
218
# This should not report about local commits being pending
240
237
self.run_bzr('update checkout')
242
239
def test_update_with_merge_merged_to_master(self):
243
# Test that 'bzr update' works correctly when you have
240
# Test that 'brz update' works correctly when you have
244
241
# an update in the master tree, and a [lightweight or otherwise]
245
242
# checkout which has merge a revision merged to master already.
246
243
master = self.make_branch_and_tree('master')
247
244
self.build_tree(['master/file'])
248
245
master.add(['file'])
249
master.commit('one', rev_id='m1')
246
master.commit('one', rev_id=b'm1')
251
248
self.build_tree(['checkout1/'])
252
249
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
253
250
checkout_dir.set_branch_reference(master.branch)
254
checkout1 = checkout_dir.create_workingtree('m1')
251
checkout1 = checkout_dir.create_workingtree(b'm1')
256
253
# Create a second branch, with an extra commit
257
other = master.bzrdir.sprout('other').open_workingtree()
254
other = master.controldir.sprout('other').open_workingtree()
258
255
self.build_tree(['other/file2'])
259
256
other.add(['file2'])
260
other.commit('other2', rev_id='o2')
257
other.commit('other2', rev_id=b'o2')
262
259
# Merge the other branch into checkout - 'start reviewing a patch'
263
260
checkout1.merge_from_branch(other.branch)
264
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
261
self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
266
263
# Create a new commit in the master branch - 'someone else lands its'
267
264
master.merge_from_branch(other.branch)
268
master.commit('f3', rev_id='m2')
265
master.commit('f3', rev_id=b'm2')
270
267
# This should not report about local commits being pending
271
268
# merges, because they were real merges (but are now gone).
306
303
master = self.make_branch_and_tree('master')
307
304
self.build_tree(['master/file1'])
308
305
master.add(['file1'])
309
master.commit('one', rev_id='m1')
306
master.commit('one', rev_id=b'm1')
311
308
# Create a second branch, with extra commits
312
other = master.bzrdir.sprout('other').open_workingtree()
309
other = master.controldir.sprout('other').open_workingtree()
313
310
self.build_tree(['other/file2', 'other/file3'])
314
311
other.add(['file2'])
315
other.commit('other2', rev_id='o2')
312
other.commit('other2', rev_id=b'o2')
316
313
other.add(['file3'])
317
other.commit('other3', rev_id='o3')
314
other.commit('other3', rev_id=b'o3')
319
316
os.chdir('master')
320
317
self.run_bzr('merge ../other')
321
master.commit('merge', rev_id='merge')
318
master.commit('merge', rev_id=b'merge')
323
320
# Switch to o2. file3 was added only in o3 and should be deleted.
324
321
out, err = self.run_bzr('update -r revid:o2')
325
self.assertContainsRe(err, '-D\s+file3')
326
self.assertContainsRe(err, 'All changes applied successfully\.')
322
self.assertContainsRe(err, '-D\\s+file3')
323
self.assertContainsRe(err, 'All changes applied successfully\\.')
327
324
self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
329
326
# Switch back to latest
330
327
out, err = self.run_bzr('update')
331
self.assertContainsRe(err, '\+N\s+file3')
332
self.assertContainsRe(err, 'All changes applied successfully\.')
328
self.assertContainsRe(err, '\\+N\\s+file3')
329
self.assertContainsRe(err, 'All changes applied successfully\\.')
333
330
self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
335
332
def test_update_dash_r_in_master(self):
336
# Test that 'bzr update' works correctly when you have
333
# Test that 'brz update' works correctly when you have
337
334
# an update in the master tree,
338
335
master = self.make_branch_and_tree('master')
339
336
self.build_tree(['master/file1'])
340
337
master.add(['file1'])
341
master.commit('one', rev_id='m1')
338
master.commit('one', rev_id=b'm1')
343
340
self.run_bzr('checkout master checkout')
345
342
# add a revision in the master.
346
343
self.build_tree(['master/file2'])
347
344
master.add(['file2'])
348
master.commit('two', rev_id='m2')
345
master.commit('two', rev_id=b'm2')
350
347
os.chdir('checkout')
351
348
sr = ScriptRunner()
352
349
sr.run_script(self, '''
353
$ bzr update -r revid:m2
350
$ brz update -r revid:m2
355
352
2>All changes applied successfully.
356
353
2>Updated to revision 2 of branch .../master
359
356
def test_update_show_base(self):
360
"""bzr update support --show-base
357
"""brz update support --show-base
362
359
see https://bugs.launchpad.net/bzr/+bug/202374"""
364
tree=self.make_branch_and_tree('.')
361
tree = self.make_branch_and_tree('.')
366
f = open('hello','wt')
363
with open('hello', 'wt') as f:
369
365
tree.add('hello')
370
366
tree.commit('fie')
372
f = open('hello','wt')
368
with open('hello', 'wt') as f:
375
370
tree.commit('fee')
377
#tree.update() gives no such revision, so ...
378
self.run_bzr(['update','-r1'])
381
f = open('hello','wt')
385
out, err = self.run_bzr(['update','--show-base'],retcode=1)
372
# tree.update() gives no such revision, so ...
373
self.run_bzr(['update', '-r1'])
376
with open('hello', 'wt') as f:
379
out, err = self.run_bzr(['update', '--show-base'], retcode=1)
387
381
# check for conflict notification
388
382
self.assertContainsString(err,
389
383
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
391
self.assertEqualDiff('<<<<<<< TREE\n'
392
'fie||||||| BASE-REVISION\n'
394
'fee>>>>>>> MERGE-SOURCE\n',
395
open('hello').read())
384
with open('hello', 'rb') as f:
385
self.assertEqualDiff(b'<<<<<<< TREE\n'
386
b'fie||||||| BASE-REVISION\n'
388
b'fee>>>>>>> MERGE-SOURCE\n',
397
391
def test_update_checkout_prevent_double_merge(self):
398
""""Launchpad bug 113809 in bzr "update performs two merges"
392
""""Launchpad bug 113809 in brz "update performs two merges"
399
393
https://launchpad.net/bugs/113809"""
400
394
master = self.make_branch_and_tree('master')
401
self.build_tree_contents([('master/file', 'initial contents\n')])
395
self.build_tree_contents([('master/file', b'initial contents\n')])
402
396
master.add(['file'])
403
master.commit('one', rev_id='m1')
397
master.commit('one', rev_id=b'm1')
405
399
checkout = master.branch.create_checkout('checkout')
406
400
lightweight = checkout.branch.create_checkout('lightweight',
409
403
# time to create a mess
410
404
# add a commit to the master
411
self.build_tree_contents([('master/file', 'master\n')])
412
master.commit('two', rev_id='m2')
413
self.build_tree_contents([('master/file', 'master local changes\n')])
405
self.build_tree_contents([('master/file', b'master\n')])
406
master.commit('two', rev_id=b'm2')
407
self.build_tree_contents([('master/file', b'master local changes\n')])
415
409
# local commit on the checkout
416
self.build_tree_contents([('checkout/file', 'checkout\n')])
417
checkout.commit('tree', rev_id='c2', local=True)
410
self.build_tree_contents([('checkout/file', b'checkout\n')])
411
checkout.commit('tree', rev_id=b'c2', local=True)
418
412
self.build_tree_contents([('checkout/file',
419
'checkout local changes\n')])
413
b'checkout local changes\n')])
422
416
self.build_tree_contents([('lightweight/file',
423
'lightweight local changes\n')])
417
b'lightweight local changes\n')])
425
419
# now update (and get conflicts)
426
420
out, err = self.run_bzr('update lightweight', retcode=1)