83
83
self.run_bzr('add checkout/file')
84
84
self.run_bzr('commit -m add-file checkout')
85
85
# now branch should be out of date
86
out,err = self.run_bzr('update branch')
86
out, err = self.run_bzr('update branch')
87
87
self.assertEqual('', out)
88
88
self.assertEqualDiff("""+N file
89
89
All changes applied successfully.
90
90
Updated to revision 1 of branch %s
91
91
""" % osutils.pathjoin(self.test_dir, 'branch',),
93
self.failUnlessExists('branch/file')
93
self.assertPathExists('branch/file')
95
95
def test_update_out_of_date_light_checkout(self):
96
96
self.make_branch_and_tree('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)
126
with open('checkout2/file', 'wt') as a_file:
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.
134
132
Updated to revision 2 of branch %s
135
133
''' % osutils.pathjoin(self.test_dir, 'branch',),
137
135
self.assertEqual('', 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 ->
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)
200
checkout1 = checkout_dir.create_workingtree('m1')
194
checkout_dir.set_branch_reference(master.branch)
195
checkout1 = checkout_dir.create_workingtree(b'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(["please run 'brz update'"],
221
216
'commit -m merged')
223
218
# This should not report about local commits being pending
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)
257
checkout1 = checkout_dir.create_workingtree('m1')
250
checkout_dir.set_branch_reference(master.branch)
251
checkout1 = checkout_dir.create_workingtree(b'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).
287
281
os.chdir('master')
288
282
self.build_tree(['./file1'])
289
283
master.add(['file1'])
290
master.commit('one', rev_id='m1')
284
master.commit('one', rev_id=b'm1')
291
285
self.build_tree(['./file2'])
292
286
master.add(['file2'])
293
master.commit('two', rev_id='m2')
287
master.commit('two', rev_id=b'm2')
295
289
sr = ScriptRunner()
296
290
sr.run_script(self, '''
299
293
2>All changes applied successfully.
300
294
2>Updated to revision 1 of .../master
302
self.failUnlessExists('./file1')
303
self.failIfExists('./file2')
304
self.assertEquals(['m1'], master.get_parent_ids())
296
self.assertPathExists('./file1')
297
self.assertPathDoesNotExist('./file2')
298
self.assertEqual([b'm1'], master.get_parent_ids())
306
300
def test_update_dash_r_outside_history(self):
307
301
"""Ensure that we can update -r to dotted revisions.
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\.')
322
self.assertContainsRe(err, '-D\\s+file3')
323
self.assertContainsRe(err, 'All changes applied successfully\\.')
330
324
self.assertContainsRe(err, '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\.')
328
self.assertContainsRe(err, '\\+N\\s+file3')
329
self.assertContainsRe(err, 'All changes applied successfully\\.')
336
330
self.assertContainsRe(err, '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
' 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',
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)
417
446
>>>>>>> MERGE-SOURCE
419
448
'lightweight/file')
450
def test_no_upgrade_single_file(self):
451
"""There's one basis revision per tree.
453
Since you can't actually change the basis for a single file at the
454
moment, we don't let you think you can.
458
self.make_branch_and_tree('.')
459
self.build_tree_contents([('a/',),
460
('a/file', b'content')])
462
sr.run_script(self, '''
464
2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
465
$ brz update ./a/file
466
2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
468
2>Tree is up to date at revision 0 of branch ...
471
2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
472
# however, you can update the whole tree from a subdirectory
474
2>Tree is up to date at revision 0 of branch ...