37
37
self.make_branch_and_tree('.')
38
38
out, err = self.run_bzr('update')
40
'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
40
b'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
42
self.assertEqual('', out)
42
self.assertEqual(b'', out)
44
44
def test_update_quiet(self):
45
45
self.make_branch_and_tree('.')
46
46
out, err = self.run_bzr('update --quiet')
47
self.assertEqual('', err)
48
self.assertEqual('', out)
47
self.assertEqual(b'', err)
48
self.assertEqual(b'', out)
50
50
def test_update_standalone_trivial_with_alias_up(self):
51
51
self.make_branch_and_tree('.')
52
52
out, err = self.run_bzr('up')
53
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
53
self.assertEqual(b'Tree is up to date at revision 0 of branch %s\n'
56
self.assertEqual('', out)
56
self.assertEqual(b'', out)
58
58
def test_update_up_to_date_light_checkout(self):
59
59
self.make_branch_and_tree('branch')
60
60
self.run_bzr('checkout --lightweight branch checkout')
61
61
out, err = self.run_bzr('update checkout')
62
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
62
self.assertEqual(b'Tree is up to date at revision 0 of branch %s\n'
63
63
% osutils.pathjoin(self.test_dir, 'branch'),
65
self.assertEqual('', out)
65
self.assertEqual(b'', out)
67
67
def test_update_up_to_date_checkout(self):
68
68
self.make_branch_and_tree('branch')
69
69
self.run_bzr('checkout branch checkout')
70
70
sr = ScriptRunner()
71
71
sr.run_script(self, '''
73
73
2>Tree is up to date at revision 0 of branch .../branch
118
118
self.run_bzr('commit -m add-file checkout')
119
119
self.run_bzr('checkout --lightweight branch checkout2')
120
120
# now alter file in checkout
121
a_file = file('checkout/file', 'wt')
121
with open('checkout/file', 'wt') as a_file:
124
123
self.run_bzr('commit -m checnge-file checkout')
125
124
# now checkout2 should be out of date
126
125
# make a local change to file
127
a_file = file('checkout2/file', 'wt')
130
out,err = self.run_bzr('update checkout2', retcode=1)
131
self.assertEqualDiff(''' M file
126
with open('checkout2/file', 'wt') as a_file:
128
out, err = self.run_bzr('update checkout2', retcode=1)
129
self.assertEqualDiff(b''' M file
132
130
Text conflict in file
133
131
1 conflicts encountered.
134
132
Updated to revision 2 of branch %s
135
133
''' % osutils.pathjoin(self.test_dir, 'branch',),
137
self.assertEqual('', out)
135
self.assertEqual(b'', out)
139
137
def test_smoke_update_checkout_bound_branch_local_commits(self):
140
138
# smoke test for doing an update of a checkout of a bound
141
139
# branch with local commits.
142
140
master = self.make_branch_and_tree('master')
141
master.commit('first commit')
143
142
# make a bound branch
144
143
self.run_bzr('checkout master child')
145
# get an object form of child
146
child = workingtree.WorkingTree.open('child')
148
145
self.run_bzr('checkout --lightweight child checkout')
149
146
# get an object form of the checkout to manipulate
150
147
wt = workingtree.WorkingTree.open('checkout')
152
a_file = file('master/file', 'wt')
149
with open('master/file', 'wt') as a_file:
155
151
master.add(['file'])
156
152
master_tip = master.commit('add file')
158
a_file = file('child/file_b', 'wt')
154
with open('child/file_b', 'wt') as a_file:
156
# get an object form of child
157
child = workingtree.WorkingTree.open('child')
161
158
child.add(['file_b'])
162
159
child_tip = child.commit('add file_b', local=True)
164
a_file = file('checkout/file_c', 'wt')
161
with open('checkout/file_c', 'wt') as a_file:
167
163
wt.add(['file_c'])
169
165
# now, update checkout ->
170
166
# get all three files and a pending merge.
171
167
out, err = self.run_bzr('update checkout')
172
self.assertEqual('', out)
173
self.assertEqualDiff("""+N file_b
168
self.assertEqual(b'', out)
169
self.assertEqualDiff(b"""+N file_b
174
170
All changes applied successfully.
176
172
All changes applied successfully.
177
Updated to revision 1 of branch %s
178
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
173
Updated to revision 2 of branch %s
174
Your local commits will now show as pending merges with 'brz status', and can be committed with 'brz commit'.
179
175
""" % osutils.pathjoin(self.test_dir, 'master',),
181
177
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
182
self.failUnlessExists('checkout/file')
183
self.failUnlessExists('checkout/file_b')
184
self.failUnlessExists('checkout/file_c')
178
self.assertPathExists('checkout/file')
179
self.assertPathExists('checkout/file_b')
180
self.assertPathExists('checkout/file_c')
185
181
self.assertTrue(wt.has_filename('file_c'))
187
183
def test_update_with_merges(self):
188
# Test that 'bzr update' works correctly when you have
184
# Test that 'brz update' works correctly when you have
189
185
# an update in the master tree, and a lightweight checkout
190
186
# which has merged another branch
191
187
master = self.make_branch_and_tree('master')
192
188
self.build_tree(['master/file'])
193
189
master.add(['file'])
194
master.commit('one', rev_id='m1')
190
master.commit('one', rev_id=b'm1')
196
192
self.build_tree(['checkout1/'])
197
193
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
198
branch.BranchReferenceFormat().initialize(checkout_dir,
199
target_branch=master.branch)
194
checkout_dir.set_branch_reference(master.branch)
200
195
checkout1 = checkout_dir.create_workingtree('m1')
202
197
# Create a second branch, with an extra commit
203
other = master.bzrdir.sprout('other').open_workingtree()
198
other = master.controldir.sprout('other').open_workingtree()
204
199
self.build_tree(['other/file2'])
205
200
other.add(['file2'])
206
other.commit('other2', rev_id='o2')
201
other.commit('other2', rev_id=b'o2')
208
203
# Create a new commit in the master branch
209
204
self.build_tree(['master/file3'])
210
205
master.add(['file3'])
211
master.commit('f3', rev_id='m2')
206
master.commit('f3', rev_id=b'm2')
213
208
# Merge the other branch into checkout
214
209
os.chdir('checkout1')
215
210
self.run_bzr('merge ../other')
217
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
212
self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
219
214
# At this point, 'commit' should fail, because we are out of date
220
self.run_bzr_error(["please run 'bzr update'"],
215
self.run_bzr_error([b"please run 'brz update'"],
221
216
'commit -m merged')
223
218
# This should not report about local commits being pending
224
219
# merges, because they were real merges
225
220
out, err = self.run_bzr('update')
226
self.assertEqual('', out)
227
self.assertEqualDiff('''+N file3
221
self.assertEqual(b'', out)
222
self.assertEqualDiff(b'''+N file3
228
223
All changes applied successfully.
229
224
Updated to revision 2 of branch %s
230
225
''' % osutils.pathjoin(self.test_dir, 'master',),
232
227
# The pending merges should still be there
233
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
228
self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
235
230
def test_readonly_lightweight_update(self):
236
231
"""Update a light checkout of a readonly branch"""
242
237
self.run_bzr('update checkout')
244
239
def test_update_with_merge_merged_to_master(self):
245
# Test that 'bzr update' works correctly when you have
240
# Test that 'brz update' works correctly when you have
246
241
# an update in the master tree, and a [lightweight or otherwise]
247
242
# checkout which has merge a revision merged to master already.
248
243
master = self.make_branch_and_tree('master')
249
244
self.build_tree(['master/file'])
250
245
master.add(['file'])
251
master.commit('one', rev_id='m1')
246
master.commit('one', rev_id=b'm1')
253
248
self.build_tree(['checkout1/'])
254
249
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
255
branch.BranchReferenceFormat().initialize(checkout_dir,
256
target_branch=master.branch)
250
checkout_dir.set_branch_reference(master.branch)
257
251
checkout1 = checkout_dir.create_workingtree('m1')
259
253
# Create a second branch, with an extra commit
260
other = master.bzrdir.sprout('other').open_workingtree()
254
other = master.controldir.sprout('other').open_workingtree()
261
255
self.build_tree(['other/file2'])
262
256
other.add(['file2'])
263
other.commit('other2', rev_id='o2')
257
other.commit('other2', rev_id=b'o2')
265
259
# Merge the other branch into checkout - 'start reviewing a patch'
266
260
checkout1.merge_from_branch(other.branch)
267
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
261
self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
269
263
# Create a new commit in the master branch - 'someone else lands its'
270
264
master.merge_from_branch(other.branch)
271
master.commit('f3', rev_id='m2')
265
master.commit('f3', rev_id=b'm2')
273
267
# This should not report about local commits being pending
274
268
# merges, because they were real merges (but are now gone).
275
269
# It should perhaps report on them.
276
270
out, err = self.run_bzr('update', working_dir='checkout1')
277
self.assertEqual('', out)
278
self.assertEqualDiff('''All changes applied successfully.
271
self.assertEqual(b'', out)
272
self.assertEqualDiff(b'''All changes applied successfully.
279
273
Updated to revision 2 of branch %s
280
274
''' % osutils.pathjoin(self.test_dir, 'master',),
309
303
master = self.make_branch_and_tree('master')
310
304
self.build_tree(['master/file1'])
311
305
master.add(['file1'])
312
master.commit('one', rev_id='m1')
306
master.commit('one', rev_id=b'm1')
314
308
# Create a second branch, with extra commits
315
other = master.bzrdir.sprout('other').open_workingtree()
309
other = master.controldir.sprout('other').open_workingtree()
316
310
self.build_tree(['other/file2', 'other/file3'])
317
311
other.add(['file2'])
318
other.commit('other2', rev_id='o2')
312
other.commit('other2', rev_id=b'o2')
319
313
other.add(['file3'])
320
other.commit('other3', rev_id='o3')
314
other.commit('other3', rev_id=b'o3')
322
316
os.chdir('master')
323
317
self.run_bzr('merge ../other')
324
master.commit('merge', rev_id='merge')
318
master.commit('merge', rev_id=b'merge')
326
320
# Switch to o2. file3 was added only in o3 and should be deleted.
327
321
out, err = self.run_bzr('update -r revid:o2')
328
self.assertContainsRe(err, '-D\s+file3')
329
self.assertContainsRe(err, 'All changes applied successfully\.')
330
self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
322
self.assertContainsRe(err, b'-D\\s+file3')
323
self.assertContainsRe(err, b'All changes applied successfully\\.')
324
self.assertContainsRe(err, b'Updated to revision 1.1.1 of branch .*')
332
326
# Switch back to latest
333
327
out, err = self.run_bzr('update')
334
self.assertContainsRe(err, '\+N\s+file3')
335
self.assertContainsRe(err, 'All changes applied successfully\.')
336
self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
328
self.assertContainsRe(err, b'\\+N\\s+file3')
329
self.assertContainsRe(err, b'All changes applied successfully\\.')
330
self.assertContainsRe(err, b'Updated to revision 2 of branch .*')
338
332
def test_update_dash_r_in_master(self):
339
# Test that 'bzr update' works correctly when you have
333
# Test that 'brz update' works correctly when you have
340
334
# an update in the master tree,
341
335
master = self.make_branch_and_tree('master')
342
336
self.build_tree(['master/file1'])
343
337
master.add(['file1'])
344
master.commit('one', rev_id='m1')
338
master.commit('one', rev_id=b'm1')
346
340
self.run_bzr('checkout master checkout')
348
342
# add a revision in the master.
349
343
self.build_tree(['master/file2'])
350
344
master.add(['file2'])
351
master.commit('two', rev_id='m2')
345
master.commit('two', rev_id=b'm2')
353
347
os.chdir('checkout')
354
348
sr = ScriptRunner()
355
349
sr.run_script(self, '''
356
$ bzr update -r revid:m2
350
$ brz update -r revid:m2
358
352
2>All changes applied successfully.
359
353
2>Updated to revision 2 of branch .../master
356
def test_update_show_base(self):
357
"""brz update support --show-base
359
see https://bugs.launchpad.net/bzr/+bug/202374"""
361
tree=self.make_branch_and_tree('.')
363
with open('hello', 'wt') as f:
368
with open('hello', 'wt') as f:
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)
381
# check for conflict notification
382
self.assertContainsString(err,
383
b' M hello\nText conflict in hello\n1 conflicts encountered.\n')
385
self.assertEqualDiff(b'<<<<<<< TREE\n'
386
b'fie||||||| BASE-REVISION\n'
388
b'fee>>>>>>> MERGE-SOURCE\n',
389
open('hello').read())
362
391
def test_update_checkout_prevent_double_merge(self):
363
""""Launchpad bug 113809 in bzr "update performs two merges"
392
""""Launchpad bug 113809 in brz "update performs two merges"
364
393
https://launchpad.net/bugs/113809"""
365
394
master = self.make_branch_and_tree('master')
366
self.build_tree_contents([('master/file', 'initial contents\n')])
395
self.build_tree_contents([('master/file', b'initial contents\n')])
367
396
master.add(['file'])
368
master.commit('one', rev_id='m1')
397
master.commit('one', rev_id=b'm1')
370
399
checkout = master.branch.create_checkout('checkout')
371
400
lightweight = checkout.branch.create_checkout('lightweight',
374
403
# time to create a mess
375
404
# add a commit to the master
376
self.build_tree_contents([('master/file', 'master\n')])
377
master.commit('two', rev_id='m2')
378
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')])
380
409
# local commit on the checkout
381
self.build_tree_contents([('checkout/file', 'checkout\n')])
382
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)
383
412
self.build_tree_contents([('checkout/file',
384
'checkout local changes\n')])
413
b'checkout local changes\n')])
387
416
self.build_tree_contents([('lightweight/file',
388
'lightweight local changes\n')])
417
b'lightweight local changes\n')])
390
419
# now update (and get conflicts)
391
420
out, err = self.run_bzr('update lightweight', retcode=1)
392
self.assertEqual('', out)
421
self.assertEqual(b'', out)
393
422
# NB: these conflicts are actually in the source code
394
self.assertFileEqual('''\
423
self.assertFileEqual(b'''\
396
425
lightweight local changes