1
# Copyright (C) 2006-2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Tests for the update command of bzr."""
29
from bzrlib.tests.script import ScriptRunner
32
class TestUpdate(tests.TestCaseWithTransport):
34
def test_update_standalone_trivial(self):
35
self.make_branch_and_tree('.')
36
out, err = self.run_bzr('update')
38
'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
40
self.assertEqual('', out)
42
def test_update_quiet(self):
43
self.make_branch_and_tree('.')
44
out, err = self.run_bzr('update --quiet')
45
self.assertEqual('', err)
46
self.assertEqual('', out)
48
def test_update_standalone_trivial_with_alias_up(self):
49
self.make_branch_and_tree('.')
50
out, err = self.run_bzr('up')
51
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
54
self.assertEqual('', out)
56
def test_update_up_to_date_light_checkout(self):
57
self.make_branch_and_tree('branch')
58
self.run_bzr('checkout --lightweight branch checkout')
59
out, err = self.run_bzr('update checkout')
60
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
61
% osutils.pathjoin(self.test_dir, 'branch'),
63
self.assertEqual('', out)
65
def test_update_up_to_date_checkout(self):
66
self.make_branch_and_tree('branch')
67
self.run_bzr('checkout branch checkout')
69
sr.run_script(self, '''
71
2>Tree is up to date at revision 0 of branch .../branch
74
def test_update_out_of_date_standalone_tree(self):
75
# FIXME the default format has to change for this to pass
76
# because it currently uses the branch last-revision marker.
77
self.make_branch_and_tree('branch')
79
self.run_bzr('checkout --lightweight branch checkout')
80
self.build_tree(['checkout/file'])
81
self.run_bzr('add checkout/file')
82
self.run_bzr('commit -m add-file checkout')
83
# now branch should be out of date
84
out,err = self.run_bzr('update branch')
85
self.assertEqual('', out)
86
self.assertEqualDiff("""+N file
87
All changes applied successfully.
88
Updated to revision 1 of branch %s
89
""" % osutils.pathjoin(self.test_dir, 'branch',),
91
self.assertPathExists('branch/file')
93
def test_update_out_of_date_light_checkout(self):
94
self.make_branch_and_tree('branch')
96
self.run_bzr('checkout --lightweight branch checkout')
97
self.run_bzr('checkout --lightweight branch checkout2')
98
self.build_tree(['checkout/file'])
99
self.run_bzr('add checkout/file')
100
self.run_bzr('commit -m add-file checkout')
101
# now checkout2 should be out of date
102
out,err = self.run_bzr('update checkout2')
103
self.assertEqualDiff('''+N file
104
All changes applied successfully.
105
Updated to revision 1 of branch %s
106
''' % osutils.pathjoin(self.test_dir, 'branch',),
108
self.assertEqual('', out)
110
def test_update_conflicts_returns_2(self):
111
self.make_branch_and_tree('branch')
113
self.run_bzr('checkout --lightweight branch checkout')
114
self.build_tree(['checkout/file'])
115
self.run_bzr('add checkout/file')
116
self.run_bzr('commit -m add-file checkout')
117
self.run_bzr('checkout --lightweight branch checkout2')
118
# now alter file in checkout
119
a_file = file('checkout/file', 'wt')
122
self.run_bzr('commit -m checnge-file checkout')
123
# now checkout2 should be out of date
124
# make a local change to file
125
a_file = file('checkout2/file', 'wt')
128
out,err = self.run_bzr('update checkout2', retcode=1)
129
self.assertEqualDiff(''' M file
130
Text conflict in file
131
1 conflicts encountered.
132
Updated to revision 2 of branch %s
133
''' % osutils.pathjoin(self.test_dir, 'branch',),
135
self.assertEqual('', out)
137
def test_smoke_update_checkout_bound_branch_local_commits(self):
138
# smoke test for doing an update of a checkout of a bound
139
# branch with local commits.
140
master = self.make_branch_and_tree('master')
141
master.commit('first commit')
142
# make a bound branch
143
self.run_bzr('checkout master child')
145
self.run_bzr('checkout --lightweight child checkout')
146
# get an object form of the checkout to manipulate
147
wt = workingtree.WorkingTree.open('checkout')
149
a_file = file('master/file', 'wt')
153
master_tip = master.commit('add file')
155
a_file = file('child/file_b', 'wt')
158
# get an object form of child
159
child = workingtree.WorkingTree.open('child')
160
child.add(['file_b'])
161
child_tip = child.commit('add file_b', local=True)
163
a_file = file('checkout/file_c', 'wt')
168
# now, update checkout ->
169
# get all three files and a pending merge.
170
out, err = self.run_bzr('update checkout')
171
self.assertEqual('', out)
172
self.assertEqualDiff("""+N file_b
173
All changes applied successfully.
175
All changes applied successfully.
176
Updated to revision 2 of branch %s
177
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
178
""" % osutils.pathjoin(self.test_dir, 'master',),
180
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
181
self.assertPathExists('checkout/file')
182
self.assertPathExists('checkout/file_b')
183
self.assertPathExists('checkout/file_c')
184
self.assertTrue(wt.has_filename('file_c'))
186
def test_update_with_merges(self):
187
# Test that 'bzr update' works correctly when you have
188
# an update in the master tree, and a lightweight checkout
189
# which has merged another branch
190
master = self.make_branch_and_tree('master')
191
self.build_tree(['master/file'])
193
master.commit('one', rev_id='m1')
195
self.build_tree(['checkout1/'])
196
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
197
branch.BranchReferenceFormat().initialize(checkout_dir,
198
target_branch=master.branch)
199
checkout1 = checkout_dir.create_workingtree('m1')
201
# Create a second branch, with an extra commit
202
other = master.bzrdir.sprout('other').open_workingtree()
203
self.build_tree(['other/file2'])
205
other.commit('other2', rev_id='o2')
207
# Create a new commit in the master branch
208
self.build_tree(['master/file3'])
209
master.add(['file3'])
210
master.commit('f3', rev_id='m2')
212
# Merge the other branch into checkout
213
os.chdir('checkout1')
214
self.run_bzr('merge ../other')
216
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
218
# At this point, 'commit' should fail, because we are out of date
219
self.run_bzr_error(["please run 'bzr update'"],
222
# This should not report about local commits being pending
223
# merges, because they were real merges
224
out, err = self.run_bzr('update')
225
self.assertEqual('', out)
226
self.assertEqualDiff('''+N file3
227
All changes applied successfully.
228
Updated to revision 2 of branch %s
229
''' % osutils.pathjoin(self.test_dir, 'master',),
231
# The pending merges should still be there
232
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
234
def test_readonly_lightweight_update(self):
235
"""Update a light checkout of a readonly branch"""
236
tree = self.make_branch_and_tree('branch')
237
readonly_branch = branch.Branch.open(self.get_readonly_url('branch'))
238
checkout = readonly_branch.create_checkout('checkout',
240
tree.commit('empty commit')
241
self.run_bzr('update checkout')
243
def test_update_with_merge_merged_to_master(self):
244
# Test that 'bzr update' works correctly when you have
245
# an update in the master tree, and a [lightweight or otherwise]
246
# checkout which has merge a revision merged to master already.
247
master = self.make_branch_and_tree('master')
248
self.build_tree(['master/file'])
250
master.commit('one', rev_id='m1')
252
self.build_tree(['checkout1/'])
253
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
254
branch.BranchReferenceFormat().initialize(checkout_dir,
255
target_branch=master.branch)
256
checkout1 = checkout_dir.create_workingtree('m1')
258
# Create a second branch, with an extra commit
259
other = master.bzrdir.sprout('other').open_workingtree()
260
self.build_tree(['other/file2'])
262
other.commit('other2', rev_id='o2')
264
# Merge the other branch into checkout - 'start reviewing a patch'
265
checkout1.merge_from_branch(other.branch)
266
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
268
# Create a new commit in the master branch - 'someone else lands its'
269
master.merge_from_branch(other.branch)
270
master.commit('f3', rev_id='m2')
272
# This should not report about local commits being pending
273
# merges, because they were real merges (but are now gone).
274
# It should perhaps report on them.
275
out, err = self.run_bzr('update', working_dir='checkout1')
276
self.assertEqual('', out)
277
self.assertEqualDiff('''All changes applied successfully.
278
Updated to revision 2 of branch %s
279
''' % osutils.pathjoin(self.test_dir, 'master',),
281
# The pending merges should still be there
282
self.assertEqual([], checkout1.get_parent_ids()[1:])
284
def test_update_dash_r(self):
285
master = self.make_branch_and_tree('master')
287
self.build_tree(['./file1'])
288
master.add(['file1'])
289
master.commit('one', rev_id='m1')
290
self.build_tree(['./file2'])
291
master.add(['file2'])
292
master.commit('two', rev_id='m2')
295
sr.run_script(self, '''
298
2>All changes applied successfully.
299
2>Updated to revision 1 of .../master
301
self.assertPathExists('./file1')
302
self.assertPathDoesNotExist('./file2')
303
self.assertEquals(['m1'], master.get_parent_ids())
305
def test_update_dash_r_outside_history(self):
306
"""Ensure that we can update -r to dotted revisions.
308
master = self.make_branch_and_tree('master')
309
self.build_tree(['master/file1'])
310
master.add(['file1'])
311
master.commit('one', rev_id='m1')
313
# Create a second branch, with extra commits
314
other = master.bzrdir.sprout('other').open_workingtree()
315
self.build_tree(['other/file2', 'other/file3'])
317
other.commit('other2', rev_id='o2')
319
other.commit('other3', rev_id='o3')
322
self.run_bzr('merge ../other')
323
master.commit('merge', rev_id='merge')
325
# Switch to o2. file3 was added only in o3 and should be deleted.
326
out, err = self.run_bzr('update -r revid:o2')
327
self.assertContainsRe(err, '-D\s+file3')
328
self.assertContainsRe(err, 'All changes applied successfully\.')
329
self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
331
# Switch back to latest
332
out, err = self.run_bzr('update')
333
self.assertContainsRe(err, '\+N\s+file3')
334
self.assertContainsRe(err, 'All changes applied successfully\.')
335
self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
337
def test_update_dash_r_in_master(self):
338
# Test that 'bzr update' works correctly when you have
339
# an update in the master tree,
340
master = self.make_branch_and_tree('master')
341
self.build_tree(['master/file1'])
342
master.add(['file1'])
343
master.commit('one', rev_id='m1')
345
self.run_bzr('checkout master checkout')
347
# add a revision in the master.
348
self.build_tree(['master/file2'])
349
master.add(['file2'])
350
master.commit('two', rev_id='m2')
354
sr.run_script(self, '''
355
$ bzr update -r revid:m2
357
2>All changes applied successfully.
358
2>Updated to revision 2 of branch .../master
361
def test_update_show_base(self):
362
"""bzr update support --show-base
364
see https://bugs.launchpad.net/bzr/+bug/202374"""
366
tree=self.make_branch_and_tree('.')
368
f = open('hello','wt')
374
f = open('hello','wt')
379
#tree.update() gives no such revision, so ...
380
self.run_bzr(['update','-r1'])
383
f = open('hello','wt')
387
out, err = self.run_bzr(['update','--show-base'],retcode=1)
389
# check for conflict notification
390
self.assertContainsString(err,
391
' 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())
399
def test_update_checkout_prevent_double_merge(self):
400
""""Launchpad bug 113809 in bzr "update performs two merges"
401
https://launchpad.net/bugs/113809"""
402
master = self.make_branch_and_tree('master')
403
self.build_tree_contents([('master/file', 'initial contents\n')])
405
master.commit('one', rev_id='m1')
407
checkout = master.branch.create_checkout('checkout')
408
lightweight = checkout.branch.create_checkout('lightweight',
411
# time to create a mess
412
# 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')])
417
# local commit on the checkout
418
self.build_tree_contents([('checkout/file', 'checkout\n')])
419
checkout.commit('tree', rev_id='c2', local=True)
420
self.build_tree_contents([('checkout/file',
421
'checkout local changes\n')])
424
self.build_tree_contents([('lightweight/file',
425
'lightweight local changes\n')])
427
# now update (and get conflicts)
428
out, err = self.run_bzr('update lightweight', retcode=1)
429
self.assertEqual('', out)
430
# NB: these conflicts are actually in the source code
431
self.assertFileEqual('''\
433
lightweight local changes
441
self.build_tree_contents([('lightweight/file',
442
'lightweight+checkout\n')])
443
self.run_bzr('resolve lightweight/file')
445
# check we get the second conflict
446
out, err = self.run_bzr('update lightweight', retcode=1)
447
self.assertEqual('', out)
448
# NB: these conflicts are actually in the source code
449
self.assertFileEqual('''\
459
def test_no_upgrade_single_file(self):
460
"""There's one basis revision per tree.
462
Since you can't actually change the basis for a single file at the
463
moment, we don't let you think you can.
467
self.make_branch_and_tree('.')
468
self.build_tree_contents([('a/',),
469
('a/file', 'content')])
471
sr.run_script(self, '''
473
2>bzr: ERROR: bzr update can only update a whole tree, not a file or subdirectory
474
$ bzr update ./a/file
475
2>bzr: ERROR: bzr update can only update a whole tree, not a file or subdirectory
477
2>Tree is up to date at revision 0 of branch ...
480
2>bzr: ERROR: bzr update can only update a whole tree, not a file or subdirectory
481
# however, you can update the whole tree from a subdirectory
483
2>Tree is up to date at revision 0 of branch ...