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.assertPathExists('branch/file')
93
self.failUnlessExists('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
with open('checkout/file', 'wt') as a_file:
121
a_file = file('checkout/file', 'wt')
123
124
self.run_bzr('commit -m checnge-file checkout')
124
125
# now checkout2 should be out of date
125
126
# 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)
127
a_file = file('checkout2/file', 'wt')
130
out,err = self.run_bzr('update checkout2', retcode=1)
129
131
self.assertEqualDiff(''' M file
130
132
Text conflict in file
131
133
1 conflicts encountered.
132
134
Updated to revision 2 of branch %s
133
135
''' % osutils.pathjoin(self.test_dir, 'branch',),
135
137
self.assertEqual('', out)
137
139
def test_smoke_update_checkout_bound_branch_local_commits(self):
138
140
# smoke test for doing an update of a checkout of a bound
139
141
# branch with local commits.
140
142
master = self.make_branch_and_tree('master')
141
master.commit('first commit')
142
143
# make a bound branch
143
144
self.run_bzr('checkout master child')
145
# get an object form of child
146
child = workingtree.WorkingTree.open('child')
145
148
self.run_bzr('checkout --lightweight child checkout')
146
149
# get an object form of the checkout to manipulate
147
150
wt = workingtree.WorkingTree.open('checkout')
149
with open('master/file', 'wt') as a_file:
152
a_file = file('master/file', 'wt')
151
155
master.add(['file'])
152
156
master_tip = master.commit('add file')
154
with open('child/file_b', 'wt') as a_file:
156
# get an object form of child
157
child = workingtree.WorkingTree.open('child')
158
a_file = file('child/file_b', 'wt')
158
161
child.add(['file_b'])
159
162
child_tip = child.commit('add file_b', local=True)
161
with open('checkout/file_c', 'wt') as a_file:
164
a_file = file('checkout/file_c', 'wt')
163
167
wt.add(['file_c'])
165
169
# now, update checkout ->
170
174
All changes applied successfully.
172
176
All changes applied successfully.
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'.
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'.
175
179
""" % osutils.pathjoin(self.test_dir, 'master',),
177
181
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
178
self.assertPathExists('checkout/file')
179
self.assertPathExists('checkout/file_b')
180
self.assertPathExists('checkout/file_c')
182
self.failUnlessExists('checkout/file')
183
self.failUnlessExists('checkout/file_b')
184
self.failUnlessExists('checkout/file_c')
181
185
self.assertTrue(wt.has_filename('file_c'))
183
187
def test_update_with_merges(self):
184
# Test that 'brz update' works correctly when you have
188
# Test that 'bzr update' works correctly when you have
185
189
# an update in the master tree, and a lightweight checkout
186
190
# which has merged another branch
187
191
master = self.make_branch_and_tree('master')
188
192
self.build_tree(['master/file'])
189
193
master.add(['file'])
190
master.commit('one', rev_id=b'm1')
194
master.commit('one', rev_id='m1')
192
196
self.build_tree(['checkout1/'])
193
197
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
194
checkout_dir.set_branch_reference(master.branch)
195
checkout1 = checkout_dir.create_workingtree(b'm1')
198
branch.BranchReferenceFormat().initialize(checkout_dir,
199
target_branch=master.branch)
200
checkout1 = checkout_dir.create_workingtree('m1')
197
202
# Create a second branch, with an extra commit
198
other = master.controldir.sprout('other').open_workingtree()
203
other = master.bzrdir.sprout('other').open_workingtree()
199
204
self.build_tree(['other/file2'])
200
205
other.add(['file2'])
201
other.commit('other2', rev_id=b'o2')
206
other.commit('other2', rev_id='o2')
203
208
# Create a new commit in the master branch
204
209
self.build_tree(['master/file3'])
205
210
master.add(['file3'])
206
master.commit('f3', rev_id=b'm2')
211
master.commit('f3', rev_id='m2')
208
213
# Merge the other branch into checkout
209
214
os.chdir('checkout1')
210
215
self.run_bzr('merge ../other')
212
self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
217
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
214
219
# At this point, 'commit' should fail, because we are out of date
215
self.run_bzr_error(["please run 'brz update'"],
220
self.run_bzr_error(["please run 'bzr update'"],
216
221
'commit -m merged')
218
223
# This should not report about local commits being pending
237
242
self.run_bzr('update checkout')
239
244
def test_update_with_merge_merged_to_master(self):
240
# Test that 'brz update' works correctly when you have
245
# Test that 'bzr update' works correctly when you have
241
246
# an update in the master tree, and a [lightweight or otherwise]
242
247
# checkout which has merge a revision merged to master already.
243
248
master = self.make_branch_and_tree('master')
244
249
self.build_tree(['master/file'])
245
250
master.add(['file'])
246
master.commit('one', rev_id=b'm1')
251
master.commit('one', rev_id='m1')
248
253
self.build_tree(['checkout1/'])
249
254
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
250
checkout_dir.set_branch_reference(master.branch)
251
checkout1 = checkout_dir.create_workingtree(b'm1')
255
branch.BranchReferenceFormat().initialize(checkout_dir,
256
target_branch=master.branch)
257
checkout1 = checkout_dir.create_workingtree('m1')
253
259
# Create a second branch, with an extra commit
254
other = master.controldir.sprout('other').open_workingtree()
260
other = master.bzrdir.sprout('other').open_workingtree()
255
261
self.build_tree(['other/file2'])
256
262
other.add(['file2'])
257
other.commit('other2', rev_id=b'o2')
263
other.commit('other2', rev_id='o2')
259
265
# Merge the other branch into checkout - 'start reviewing a patch'
260
266
checkout1.merge_from_branch(other.branch)
261
self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
267
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
263
269
# Create a new commit in the master branch - 'someone else lands its'
264
270
master.merge_from_branch(other.branch)
265
master.commit('f3', rev_id=b'm2')
271
master.commit('f3', rev_id='m2')
267
273
# This should not report about local commits being pending
268
274
# merges, because they were real merges (but are now gone).
281
287
os.chdir('master')
282
288
self.build_tree(['./file1'])
283
289
master.add(['file1'])
284
master.commit('one', rev_id=b'm1')
290
master.commit('one', rev_id='m1')
285
291
self.build_tree(['./file2'])
286
292
master.add(['file2'])
287
master.commit('two', rev_id=b'm2')
293
master.commit('two', rev_id='m2')
289
295
sr = ScriptRunner()
290
296
sr.run_script(self, '''
293
299
2>All changes applied successfully.
294
300
2>Updated to revision 1 of .../master
296
self.assertPathExists('./file1')
297
self.assertPathDoesNotExist('./file2')
298
self.assertEqual([b'm1'], master.get_parent_ids())
302
self.failUnlessExists('./file1')
303
self.failIfExists('./file2')
304
self.assertEquals(['m1'], master.get_parent_ids())
300
306
def test_update_dash_r_outside_history(self):
301
307
"""Ensure that we can update -r to dotted revisions.
303
309
master = self.make_branch_and_tree('master')
304
310
self.build_tree(['master/file1'])
305
311
master.add(['file1'])
306
master.commit('one', rev_id=b'm1')
312
master.commit('one', rev_id='m1')
308
314
# Create a second branch, with extra commits
309
other = master.controldir.sprout('other').open_workingtree()
315
other = master.bzrdir.sprout('other').open_workingtree()
310
316
self.build_tree(['other/file2', 'other/file3'])
311
317
other.add(['file2'])
312
other.commit('other2', rev_id=b'o2')
318
other.commit('other2', rev_id='o2')
313
319
other.add(['file3'])
314
other.commit('other3', rev_id=b'o3')
320
other.commit('other3', rev_id='o3')
316
322
os.chdir('master')
317
323
self.run_bzr('merge ../other')
318
master.commit('merge', rev_id=b'merge')
324
master.commit('merge', rev_id='merge')
320
326
# Switch to o2. file3 was added only in o3 and should be deleted.
321
327
out, err = self.run_bzr('update -r revid:o2')
322
self.assertContainsRe(err, '-D\\s+file3')
323
self.assertContainsRe(err, 'All changes applied successfully\\.')
328
self.assertContainsRe(err, '-D\s+file3')
329
self.assertContainsRe(err, 'All changes applied successfully\.')
324
330
self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
326
332
# Switch back to latest
327
333
out, err = self.run_bzr('update')
328
self.assertContainsRe(err, '\\+N\\s+file3')
329
self.assertContainsRe(err, 'All changes applied successfully\\.')
334
self.assertContainsRe(err, '\+N\s+file3')
335
self.assertContainsRe(err, 'All changes applied successfully\.')
330
336
self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
332
338
def test_update_dash_r_in_master(self):
333
# Test that 'brz update' works correctly when you have
339
# Test that 'bzr update' works correctly when you have
334
340
# an update in the master tree,
335
341
master = self.make_branch_and_tree('master')
336
342
self.build_tree(['master/file1'])
337
343
master.add(['file1'])
338
master.commit('one', rev_id=b'm1')
344
master.commit('one', rev_id='m1')
340
346
self.run_bzr('checkout master checkout')
342
348
# add a revision in the master.
343
349
self.build_tree(['master/file2'])
344
350
master.add(['file2'])
345
master.commit('two', rev_id=b'm2')
351
master.commit('two', rev_id='m2')
347
353
os.chdir('checkout')
348
354
sr = ScriptRunner()
349
355
sr.run_script(self, '''
350
$ brz update -r revid:m2
356
$ bzr update -r revid:m2
352
358
2>All changes applied successfully.
353
359
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',
391
362
def test_update_checkout_prevent_double_merge(self):
392
""""Launchpad bug 113809 in brz "update performs two merges"
363
""""Launchpad bug 113809 in bzr "update performs two merges"
393
364
https://launchpad.net/bugs/113809"""
394
365
master = self.make_branch_and_tree('master')
395
self.build_tree_contents([('master/file', b'initial contents\n')])
366
self.build_tree_contents([('master/file', 'initial contents\n')])
396
367
master.add(['file'])
397
master.commit('one', rev_id=b'm1')
368
master.commit('one', rev_id='m1')
399
370
checkout = master.branch.create_checkout('checkout')
400
371
lightweight = checkout.branch.create_checkout('lightweight',
403
374
# time to create a mess
404
375
# 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')])
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')])
409
380
# 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)
381
self.build_tree_contents([('checkout/file', 'checkout\n')])
382
checkout.commit('tree', rev_id='c2', local=True)
412
383
self.build_tree_contents([('checkout/file',
413
b'checkout local changes\n')])
384
'checkout local changes\n')])
416
387
self.build_tree_contents([('lightweight/file',
417
b'lightweight local changes\n')])
388
'lightweight local changes\n')])
419
390
# now update (and get conflicts)
420
391
out, err = self.run_bzr('update lightweight', retcode=1)
446
417
>>>>>>> MERGE-SOURCE
448
419
'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 ...