1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
1
# Copyright (C) 2006-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
83
81
self.run_bzr('add checkout/file')
84
82
self.run_bzr('commit -m add-file checkout')
85
83
# now branch should be out of date
86
out, err = self.run_bzr('update branch')
84
out,err = self.run_bzr('update branch')
87
85
self.assertEqual('', out)
88
86
self.assertEqualDiff("""+N file
89
87
All changes applied successfully.
101
99
self.run_bzr('add checkout/file')
102
100
self.run_bzr('commit -m add-file checkout')
103
101
# now checkout2 should be out of date
104
out, err = self.run_bzr('update checkout2')
102
out,err = self.run_bzr('update checkout2')
105
103
self.assertEqualDiff('''+N file
106
104
All changes applied successfully.
107
105
Updated to revision 1 of branch %s
127
125
a_file = file('checkout2/file', 'wt')
128
126
a_file.write('Bar')
130
out, err = self.run_bzr('update checkout2', retcode=1)
128
out,err = self.run_bzr('update checkout2', retcode=1)
131
129
self.assertEqualDiff(''' M file
132
130
Text conflict in file
133
131
1 conflicts encountered.
177
175
All changes applied successfully.
178
176
Updated to revision 2 of branch %s
179
Your local commits will now show as pending merges with 'brz status', and can be committed with 'brz commit'.
177
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
180
178
""" % osutils.pathjoin(self.test_dir, 'master',),
182
180
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
186
184
self.assertTrue(wt.has_filename('file_c'))
188
186
def test_update_with_merges(self):
189
# Test that 'brz update' works correctly when you have
187
# Test that 'bzr update' works correctly when you have
190
188
# an update in the master tree, and a lightweight checkout
191
189
# which has merged another branch
192
190
master = self.make_branch_and_tree('master')
193
191
self.build_tree(['master/file'])
194
192
master.add(['file'])
195
master.commit('one', rev_id=b'm1')
193
master.commit('one', rev_id='m1')
197
195
self.build_tree(['checkout1/'])
198
196
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
200
198
checkout1 = checkout_dir.create_workingtree('m1')
202
200
# Create a second branch, with an extra commit
203
other = master.controldir.sprout('other').open_workingtree()
201
other = master.bzrdir.sprout('other').open_workingtree()
204
202
self.build_tree(['other/file2'])
205
203
other.add(['file2'])
206
other.commit('other2', rev_id=b'o2')
204
other.commit('other2', rev_id='o2')
208
206
# Create a new commit in the master branch
209
207
self.build_tree(['master/file3'])
210
208
master.add(['file3'])
211
master.commit('f3', rev_id=b'm2')
209
master.commit('f3', rev_id='m2')
213
211
# Merge the other branch into checkout
214
212
os.chdir('checkout1')
217
215
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
219
217
# At this point, 'commit' should fail, because we are out of date
220
self.run_bzr_error(["please run 'brz update'"],
218
self.run_bzr_error(["please run 'bzr update'"],
221
219
'commit -m merged')
223
221
# This should not report about local commits being pending
242
240
self.run_bzr('update checkout')
244
242
def test_update_with_merge_merged_to_master(self):
245
# Test that 'brz update' works correctly when you have
243
# Test that 'bzr update' works correctly when you have
246
244
# an update in the master tree, and a [lightweight or otherwise]
247
245
# checkout which has merge a revision merged to master already.
248
246
master = self.make_branch_and_tree('master')
249
247
self.build_tree(['master/file'])
250
248
master.add(['file'])
251
master.commit('one', rev_id=b'm1')
249
master.commit('one', rev_id='m1')
253
251
self.build_tree(['checkout1/'])
254
252
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
256
254
checkout1 = checkout_dir.create_workingtree('m1')
258
256
# Create a second branch, with an extra commit
259
other = master.controldir.sprout('other').open_workingtree()
257
other = master.bzrdir.sprout('other').open_workingtree()
260
258
self.build_tree(['other/file2'])
261
259
other.add(['file2'])
262
other.commit('other2', rev_id=b'o2')
260
other.commit('other2', rev_id='o2')
264
262
# Merge the other branch into checkout - 'start reviewing a patch'
265
263
checkout1.merge_from_branch(other.branch)
268
266
# Create a new commit in the master branch - 'someone else lands its'
269
267
master.merge_from_branch(other.branch)
270
master.commit('f3', rev_id=b'm2')
268
master.commit('f3', rev_id='m2')
272
270
# This should not report about local commits being pending
273
271
# merges, because they were real merges (but are now gone).
286
284
os.chdir('master')
287
285
self.build_tree(['./file1'])
288
286
master.add(['file1'])
289
master.commit('one', rev_id=b'm1')
287
master.commit('one', rev_id='m1')
290
288
self.build_tree(['./file2'])
291
289
master.add(['file2'])
292
master.commit('two', rev_id=b'm2')
290
master.commit('two', rev_id='m2')
294
292
sr = ScriptRunner()
295
293
sr.run_script(self, '''
298
296
2>All changes applied successfully.
299
297
2>Updated to revision 1 of .../master
301
299
self.assertPathExists('./file1')
302
300
self.assertPathDoesNotExist('./file2')
303
self.assertEqual(['m1'], master.get_parent_ids())
301
self.assertEquals(['m1'], master.get_parent_ids())
305
303
def test_update_dash_r_outside_history(self):
306
304
"""Ensure that we can update -r to dotted revisions.
308
306
master = self.make_branch_and_tree('master')
309
307
self.build_tree(['master/file1'])
310
308
master.add(['file1'])
311
master.commit('one', rev_id=b'm1')
309
master.commit('one', rev_id='m1')
313
311
# Create a second branch, with extra commits
314
other = master.controldir.sprout('other').open_workingtree()
312
other = master.bzrdir.sprout('other').open_workingtree()
315
313
self.build_tree(['other/file2', 'other/file3'])
316
314
other.add(['file2'])
317
other.commit('other2', rev_id=b'o2')
315
other.commit('other2', rev_id='o2')
318
316
other.add(['file3'])
319
other.commit('other3', rev_id=b'o3')
317
other.commit('other3', rev_id='o3')
321
319
os.chdir('master')
322
320
self.run_bzr('merge ../other')
323
master.commit('merge', rev_id=b'merge')
321
master.commit('merge', rev_id='merge')
325
323
# Switch to o2. file3 was added only in o3 and should be deleted.
326
324
out, err = self.run_bzr('update -r revid:o2')
335
333
self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
337
335
def test_update_dash_r_in_master(self):
338
# Test that 'brz update' works correctly when you have
336
# Test that 'bzr update' works correctly when you have
339
337
# an update in the master tree,
340
338
master = self.make_branch_and_tree('master')
341
339
self.build_tree(['master/file1'])
342
340
master.add(['file1'])
343
master.commit('one', rev_id=b'm1')
341
master.commit('one', rev_id='m1')
345
343
self.run_bzr('checkout master checkout')
347
345
# add a revision in the master.
348
346
self.build_tree(['master/file2'])
349
347
master.add(['file2'])
350
master.commit('two', rev_id=b'm2')
348
master.commit('two', rev_id='m2')
352
350
os.chdir('checkout')
353
351
sr = ScriptRunner()
354
352
sr.run_script(self, '''
355
$ brz update -r revid:m2
353
$ bzr update -r revid:m2
357
355
2>All changes applied successfully.
358
356
2>Updated to revision 2 of branch .../master
361
359
def test_update_show_base(self):
362
"""brz update support --show-base
360
"""bzr update support --show-base
364
362
see https://bugs.launchpad.net/bzr/+bug/202374"""
366
364
tree=self.make_branch_and_tree('.')
368
f = open('hello', 'wt')
366
f = open('hello','wt')
371
369
tree.add('hello')
372
370
tree.commit('fie')
374
f = open('hello', 'wt')
372
f = open('hello','wt')
377
375
tree.commit('fee')
379
377
#tree.update() gives no such revision, so ...
380
self.run_bzr(['update', '-r1'])
378
self.run_bzr(['update','-r1'])
383
f = open('hello', 'wt')
381
f = open('hello','wt')
387
out, err = self.run_bzr(['update', '--show-base'], retcode=1)
385
out, err = self.run_bzr(['update','--show-base'],retcode=1)
389
387
# check for conflict notification
390
388
self.assertContainsString(err,
397
395
open('hello').read())
399
397
def test_update_checkout_prevent_double_merge(self):
400
""""Launchpad bug 113809 in brz "update performs two merges"
398
""""Launchpad bug 113809 in bzr "update performs two merges"
401
399
https://launchpad.net/bugs/113809"""
402
400
master = self.make_branch_and_tree('master')
403
self.build_tree_contents([('master/file', b'initial contents\n')])
401
self.build_tree_contents([('master/file', 'initial contents\n')])
404
402
master.add(['file'])
405
master.commit('one', rev_id=b'm1')
403
master.commit('one', rev_id='m1')
407
405
checkout = master.branch.create_checkout('checkout')
408
406
lightweight = checkout.branch.create_checkout('lightweight',
411
409
# time to create a mess
412
410
# add a commit to the master
413
self.build_tree_contents([('master/file', b'master\n')])
414
master.commit('two', rev_id=b'm2')
415
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')])
417
415
# local commit on the checkout
418
self.build_tree_contents([('checkout/file', b'checkout\n')])
419
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)
420
418
self.build_tree_contents([('checkout/file',
421
b'checkout local changes\n')])
419
'checkout local changes\n')])
424
422
self.build_tree_contents([('lightweight/file',
425
b'lightweight local changes\n')])
423
'lightweight local changes\n')])
427
425
# now update (and get conflicts)
428
426
out, err = self.run_bzr('update lightweight', retcode=1)
441
439
self.build_tree_contents([('lightweight/file',
442
b'lightweight+checkout\n')])
440
'lightweight+checkout\n')])
443
441
self.run_bzr('resolve lightweight/file')
445
443
# check we get the second conflict
467
465
self.make_branch_and_tree('.')
468
466
self.build_tree_contents([('a/',),
469
('a/file', b'content')])
467
('a/file', 'content')])
470
468
sr = ScriptRunner()
471
469
sr.run_script(self, '''
473
2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
474
$ brz update ./a/file
475
2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
471
2>bzr: ERROR: bzr update can only update a whole tree, not a file or subdirectory
472
$ bzr update ./a/file
473
2>bzr: ERROR: bzr update can only update a whole tree, not a file or subdirectory
477
475
2>Tree is up to date at revision 0 of branch ...
480
2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
478
2>bzr: ERROR: bzr update can only update a whole tree, not a file or subdirectory
481
479
# however, you can update the whole tree from a subdirectory
483
481
2>Tree is up to date at revision 0 of branch ...