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