89
89
All changes applied successfully.
90
90
Updated to revision 1 of branch %s
91
91
""" % osutils.pathjoin(self.test_dir, 'branch',),
93
93
self.assertPathExists('branch/file')
95
95
def test_update_out_of_date_light_checkout(self):
106
106
All changes applied successfully.
107
107
Updated to revision 1 of branch %s
108
108
''' % osutils.pathjoin(self.test_dir, 'branch',),
110
110
self.assertEqual('', out)
112
112
def test_update_conflicts_returns_2(self):
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')
126
with open('checkout2/file', 'wt') as a_file:
130
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):
148
146
# get an object form of the checkout to manipulate
149
147
wt = workingtree.WorkingTree.open('checkout')
151
a_file = file('master/file', 'wt')
149
with open('master/file', 'wt') as a_file:
154
151
master.add(['file'])
155
152
master_tip = master.commit('add file')
157
a_file = file('child/file_b', 'wt')
154
with open('child/file_b', 'wt') as a_file:
160
156
# get an object form of child
161
157
child = workingtree.WorkingTree.open('child')
162
158
child.add(['file_b'])
163
159
child_tip = child.commit('add file_b', local=True)
165
a_file = file('checkout/file_c', 'wt')
161
with open('checkout/file_c', 'wt') as a_file:
168
163
wt.add(['file_c'])
170
165
# now, update checkout ->
178
173
Updated to revision 2 of branch %s
179
174
Your local commits will now show as pending merges with 'brz status', and can be committed with 'brz commit'.
180
175
""" % osutils.pathjoin(self.test_dir, 'master',),
182
177
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
183
178
self.assertPathExists('checkout/file')
184
179
self.assertPathExists('checkout/file_b')
192
187
master = self.make_branch_and_tree('master')
193
188
self.build_tree(['master/file'])
194
189
master.add(['file'])
195
master.commit('one', rev_id='m1')
190
master.commit('one', rev_id=b'm1')
197
192
self.build_tree(['checkout1/'])
198
193
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
199
194
checkout_dir.set_branch_reference(master.branch)
200
checkout1 = checkout_dir.create_workingtree('m1')
195
checkout1 = checkout_dir.create_workingtree(b'm1')
202
197
# Create a second branch, with an extra commit
203
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
215
self.run_bzr_error(["please run 'brz update'"],
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"""
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
250
checkout_dir.set_branch_reference(master.branch)
256
checkout1 = checkout_dir.create_workingtree('m1')
251
checkout1 = checkout_dir.create_workingtree(b'm1')
258
253
# Create a second branch, with an extra commit
259
254
other = master.controldir.sprout('other').open_workingtree()
260
255
self.build_tree(['other/file2'])
261
256
other.add(['file2'])
262
other.commit('other2', rev_id='o2')
257
other.commit('other2', rev_id=b'o2')
264
259
# Merge the other branch into checkout - 'start reviewing a patch'
265
260
checkout1.merge_from_branch(other.branch)
266
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
261
self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
268
263
# Create a new commit in the master branch - 'someone else lands its'
269
264
master.merge_from_branch(other.branch)
270
master.commit('f3', rev_id='m2')
265
master.commit('f3', rev_id=b'm2')
272
267
# This should not report about local commits being pending
273
268
# merges, because they were real merges (but are now gone).
277
272
self.assertEqualDiff('''All changes applied successfully.
278
273
Updated to revision 2 of branch %s
279
274
''' % osutils.pathjoin(self.test_dir, 'master',),
281
276
# The pending merges should still be there
282
277
self.assertEqual([], checkout1.get_parent_ids()[1:])
286
281
os.chdir('master')
287
282
self.build_tree(['./file1'])
288
283
master.add(['file1'])
289
master.commit('one', rev_id='m1')
284
master.commit('one', rev_id=b'm1')
290
285
self.build_tree(['./file2'])
291
286
master.add(['file2'])
292
master.commit('two', rev_id='m2')
287
master.commit('two', rev_id=b'm2')
294
289
sr = ScriptRunner()
295
290
sr.run_script(self, '''
301
296
self.assertPathExists('./file1')
302
297
self.assertPathDoesNotExist('./file2')
303
self.assertEqual(['m1'], master.get_parent_ids())
298
self.assertEqual([b'm1'], master.get_parent_ids())
305
300
def test_update_dash_r_outside_history(self):
306
301
"""Ensure that we can update -r to dotted revisions.
308
303
master = self.make_branch_and_tree('master')
309
304
self.build_tree(['master/file1'])
310
305
master.add(['file1'])
311
master.commit('one', rev_id='m1')
306
master.commit('one', rev_id=b'm1')
313
308
# Create a second branch, with extra commits
314
309
other = master.controldir.sprout('other').open_workingtree()
315
310
self.build_tree(['other/file2', 'other/file3'])
316
311
other.add(['file2'])
317
other.commit('other2', rev_id='o2')
312
other.commit('other2', rev_id=b'o2')
318
313
other.add(['file3'])
319
other.commit('other3', rev_id='o3')
314
other.commit('other3', rev_id=b'o3')
321
316
os.chdir('master')
322
317
self.run_bzr('merge ../other')
323
master.commit('merge', rev_id='merge')
318
master.commit('merge', rev_id=b'merge')
325
320
# Switch to o2. file3 was added only in o3 and should be deleted.
326
321
out, err = self.run_bzr('update -r revid:o2')
327
self.assertContainsRe(err, '-D\s+file3')
328
self.assertContainsRe(err, 'All changes applied successfully\.')
322
self.assertContainsRe(err, '-D\\s+file3')
323
self.assertContainsRe(err, 'All changes applied successfully\\.')
329
324
self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
331
326
# Switch back to latest
332
327
out, err = self.run_bzr('update')
333
self.assertContainsRe(err, '\+N\s+file3')
334
self.assertContainsRe(err, 'All changes applied successfully\.')
328
self.assertContainsRe(err, '\\+N\\s+file3')
329
self.assertContainsRe(err, 'All changes applied successfully\\.')
335
330
self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
337
332
def test_update_dash_r_in_master(self):
340
335
master = self.make_branch_and_tree('master')
341
336
self.build_tree(['master/file1'])
342
337
master.add(['file1'])
343
master.commit('one', rev_id='m1')
338
master.commit('one', rev_id=b'm1')
345
340
self.run_bzr('checkout master checkout')
347
342
# add a revision in the master.
348
343
self.build_tree(['master/file2'])
349
344
master.add(['file2'])
350
master.commit('two', rev_id='m2')
345
master.commit('two', rev_id=b'm2')
352
347
os.chdir('checkout')
353
348
sr = ScriptRunner()
364
359
see https://bugs.launchpad.net/bzr/+bug/202374"""
366
tree=self.make_branch_and_tree('.')
361
tree = self.make_branch_and_tree('.')
368
f = open('hello', 'wt')
363
with open('hello', 'wt') as f:
371
365
tree.add('hello')
372
366
tree.commit('fie')
374
f = open('hello', 'wt')
368
with open('hello', 'wt') as f:
377
370
tree.commit('fee')
379
#tree.update() gives no such revision, so ...
372
# tree.update() gives no such revision, so ...
380
373
self.run_bzr(['update', '-r1'])
383
f = open('hello', 'wt')
376
with open('hello', 'wt') as f:
387
379
out, err = self.run_bzr(['update', '--show-base'], retcode=1)
389
381
# check for conflict notification
390
382
self.assertContainsString(err,
391
383
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
393
self.assertEqualDiff('<<<<<<< TREE\n'
394
'fie||||||| BASE-REVISION\n'
396
'fee>>>>>>> MERGE-SOURCE\n',
397
open('hello').read())
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',
399
391
def test_update_checkout_prevent_double_merge(self):
400
392
""""Launchpad bug 113809 in brz "update performs two merges"
401
393
https://launchpad.net/bugs/113809"""
402
394
master = self.make_branch_and_tree('master')
403
self.build_tree_contents([('master/file', 'initial contents\n')])
395
self.build_tree_contents([('master/file', b'initial contents\n')])
404
396
master.add(['file'])
405
master.commit('one', rev_id='m1')
397
master.commit('one', rev_id=b'm1')
407
399
checkout = master.branch.create_checkout('checkout')
408
400
lightweight = checkout.branch.create_checkout('lightweight',
411
403
# time to create a mess
412
404
# add a commit to the master
413
self.build_tree_contents([('master/file', 'master\n')])
414
master.commit('two', rev_id='m2')
415
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')])
417
409
# local commit on the checkout
418
self.build_tree_contents([('checkout/file', 'checkout\n')])
419
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)
420
412
self.build_tree_contents([('checkout/file',
421
'checkout local changes\n')])
413
b'checkout local changes\n')])
424
416
self.build_tree_contents([('lightweight/file',
425
'lightweight local changes\n')])
417
b'lightweight local changes\n')])
427
419
# now update (and get conflicts)
428
420
out, err = self.run_bzr('update lightweight', retcode=1)
441
433
self.build_tree_contents([('lightweight/file',
442
'lightweight+checkout\n')])
434
b'lightweight+checkout\n')])
443
435
self.run_bzr('resolve lightweight/file')
445
437
# check we get the second conflict