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