1
# Copyright (C) 2006, 2009 Canonical Ltd
1
# Copyright (C) 2006 by Canonical Ltd
2
2
# -*- coding: utf-8 -*-
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
6
6
# the Free Software Foundation; either version 2 of the License, or
7
7
# (at your option) any later version.
9
9
# This program is distributed in the hope that it will be useful,
10
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
# GNU General Public License for more details.
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
19
"""Tests for the update command of bzr."""
32
from bzrlib.tests.script import ScriptRunner
35
class TestUpdate(tests.TestCaseWithTransport):
22
from bzrlib.tests import TestSkipped
23
from bzrlib.tests.blackbox import ExternalBase
24
from bzrlib.workingtree import WorkingTree
27
class TestUpdate(ExternalBase):
37
29
def test_update_standalone_trivial(self):
38
self.make_branch_and_tree('.')
39
out, err = self.run_bzr('update')
41
'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
43
self.assertEqual('', out)
45
def test_update_quiet(self):
46
self.make_branch_and_tree('.')
47
out, err = self.run_bzr('update --quiet')
48
self.assertEqual('', err)
49
self.assertEqual('', out)
51
def test_update_standalone_trivial_with_alias_up(self):
52
self.make_branch_and_tree('.')
53
out, err = self.run_bzr('up')
54
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
31
out, err = self.runbzr('update')
32
self.assertEqual('Tree is up to date at revision 0.\n', err)
57
33
self.assertEqual('', out)
59
35
def test_update_up_to_date_light_checkout(self):
60
36
self.make_branch_and_tree('branch')
61
self.run_bzr('checkout --lightweight branch checkout')
62
out, err = self.run_bzr('update checkout')
63
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
64
% osutils.pathjoin(self.test_dir, 'branch'),
37
self.runbzr('checkout --lightweight branch checkout')
38
out, err = self.runbzr('update checkout')
39
self.assertEqual('Tree is up to date at revision 0.\n', err)
66
40
self.assertEqual('', out)
68
42
def test_update_up_to_date_checkout(self):
69
43
self.make_branch_and_tree('branch')
70
self.run_bzr('checkout branch checkout')
72
sr.run_script(self, '''
74
2>Tree is up to date at revision 0 of branch .../branch
44
self.run_bzr('checkout', 'branch', 'checkout')
45
out, err = self.run_bzr('update', 'checkout')
46
self.assertEqual('Tree is up to date at revision 0.\n', err)
47
self.assertEqual('', out)
77
49
def test_update_out_of_date_standalone_tree(self):
78
50
# FIXME the default format has to change for this to pass
79
51
# because it currently uses the branch last-revision marker.
52
raise TestSkipped('default format too old')
80
53
self.make_branch_and_tree('branch')
82
self.run_bzr('checkout --lightweight branch checkout')
55
self.runbzr('checkout --lightweight branch checkout')
83
56
self.build_tree(['checkout/file'])
84
self.run_bzr('add checkout/file')
85
self.run_bzr('commit -m add-file checkout')
57
self.runbzr('add checkout/file')
58
self.runbzr('commit -m add-file checkout')
86
59
# now branch should be out of date
87
out,err = self.run_bzr('update branch')
88
self.assertEqual('', out)
89
self.assertEqualDiff("""+N file
90
All changes applied successfully.
91
Updated to revision 1 of branch %s
92
""" % osutils.pathjoin(self.test_dir, 'branch',),
60
out,err = self.runbzr('update branch')
61
self.assertEqual('Updated to revision 1.\n', out)
62
self.assertEqual('', err)
94
63
self.failUnlessExists('branch/file')
96
65
def test_update_out_of_date_light_checkout(self):
97
66
self.make_branch_and_tree('branch')
98
67
# make two checkouts
99
self.run_bzr('checkout --lightweight branch checkout')
100
self.run_bzr('checkout --lightweight branch checkout2')
68
self.runbzr('checkout --lightweight branch checkout')
69
self.runbzr('checkout --lightweight branch checkout2')
101
70
self.build_tree(['checkout/file'])
102
self.run_bzr('add checkout/file')
103
self.run_bzr('commit -m add-file checkout')
71
self.runbzr('add checkout/file')
72
self.runbzr('commit -m add-file checkout')
104
73
# now checkout2 should be out of date
105
out,err = self.run_bzr('update checkout2')
106
self.assertEqualDiff('''+N file
107
All changes applied successfully.
108
Updated to revision 1 of branch %s
109
''' % osutils.pathjoin(self.test_dir, 'branch',),
74
out,err = self.runbzr('update checkout2')
75
self.assertEqual('All changes applied successfully.\n'
76
'Updated to revision 1.\n',
111
78
self.assertEqual('', out)
113
80
def test_update_conflicts_returns_2(self):
114
81
self.make_branch_and_tree('branch')
115
82
# make two checkouts
116
self.run_bzr('checkout --lightweight branch checkout')
83
self.runbzr('checkout --lightweight branch checkout')
117
84
self.build_tree(['checkout/file'])
118
self.run_bzr('add checkout/file')
119
self.run_bzr('commit -m add-file checkout')
120
self.run_bzr('checkout --lightweight branch checkout2')
85
self.runbzr('add checkout/file')
86
self.runbzr('commit -m add-file checkout')
87
self.runbzr('checkout --lightweight branch checkout2')
121
88
# now alter file in checkout
122
89
a_file = file('checkout/file', 'wt')
123
90
a_file.write('Foo')
125
self.run_bzr('commit -m checnge-file checkout')
92
self.runbzr('commit -m checnge-file checkout')
126
93
# now checkout2 should be out of date
127
94
# make a local change to file
128
95
a_file = file('checkout2/file', 'wt')
129
96
a_file.write('Bar')
131
out,err = self.run_bzr('update checkout2', retcode=1)
132
self.assertEqualDiff(''' M file
133
Text conflict in file
134
1 conflicts encountered.
135
Updated to revision 2 of branch %s
136
''' % osutils.pathjoin(self.test_dir, 'branch',),
98
out,err = self.runbzr('update checkout2', retcode=1)
99
self.assertEqual(['1 conflicts encountered.',
100
'Updated to revision 2.'],
101
err.split('\n')[1:3])
102
self.assertContainsRe(err, 'Text conflict in file\n')
138
103
self.assertEqual('', out)
140
105
def test_smoke_update_checkout_bound_branch_local_commits(self):
141
106
# smoke test for doing an update of a checkout of a bound
142
107
# branch with local commits.
143
master = self.make_branch_and_tree('master')
108
self.make_branch_and_tree('master')
144
109
# make a bound branch
145
self.run_bzr('checkout master child')
146
# get an object form of child
147
child = workingtree.WorkingTree.open('child')
110
self.run_bzr('checkout', 'master', 'child')
149
self.run_bzr('checkout --lightweight child checkout')
150
# get an object form of the checkout to manipulate
151
wt = workingtree.WorkingTree.open('checkout')
112
self.run_bzr('checkout', '--lightweight', 'child', 'checkout')
153
114
a_file = file('master/file', 'wt')
154
115
a_file.write('Foo')
157
master_tip = master.commit('add file')
117
self.run_bzr('add', 'master')
118
self.run_bzr('commit', '-m', 'add file', 'master')
159
120
a_file = file('child/file_b', 'wt')
160
121
a_file.write('Foo')
162
child.add(['file_b'])
163
child_tip = child.commit('add file_b', local=True)
123
self.run_bzr('add', 'child')
124
self.run_bzr('commit', '--local', '-m', 'add file_b', 'child')
165
126
a_file = file('checkout/file_c', 'wt')
166
127
a_file.write('Foo')
129
self.run_bzr('add', 'checkout')
170
131
# now, update checkout ->
171
132
# get all three files and a pending merge.
172
out, err = self.run_bzr('update checkout')
173
self.assertEqual('', out)
174
self.assertEqualDiff("""+N file
175
All changes applied successfully.
177
All changes applied successfully.
178
Updated to revision 1 of branch %s
179
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
180
""" % osutils.pathjoin(self.test_dir, 'master',),
182
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
133
self.run_bzr('update', 'checkout')
134
wt = WorkingTree.open('checkout')
135
self.assertNotEqual([], wt.pending_merges())
183
136
self.failUnlessExists('checkout/file')
184
137
self.failUnlessExists('checkout/file_b')
185
138
self.failUnlessExists('checkout/file_c')
186
139
self.assertTrue(wt.has_filename('file_c'))
188
def test_update_with_merges(self):
189
# Test that 'bzr update' works correctly when you have
190
# an update in the master tree, and a lightweight checkout
191
# which has merged another branch
192
master = self.make_branch_and_tree('master')
193
self.build_tree(['master/file'])
195
master.commit('one', rev_id='m1')
197
self.build_tree(['checkout1/'])
198
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
199
branch.BranchReferenceFormat().initialize(checkout_dir, master.branch)
200
checkout1 = checkout_dir.create_workingtree('m1')
202
# Create a second branch, with an extra commit
203
other = master.bzrdir.sprout('other').open_workingtree()
204
self.build_tree(['other/file2'])
206
other.commit('other2', rev_id='o2')
208
# Create a new commit in the master branch
209
self.build_tree(['master/file3'])
210
master.add(['file3'])
211
master.commit('f3', rev_id='m2')
213
# Merge the other branch into checkout
214
os.chdir('checkout1')
215
self.run_bzr('merge ../other')
217
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
219
# At this point, 'commit' should fail, because we are out of date
220
self.run_bzr_error(["please run 'bzr update'"],
223
# This should not report about local commits being pending
224
# merges, because they were real merges
225
out, err = self.run_bzr('update')
226
self.assertEqual('', out)
227
self.assertEqualDiff('''+N file3
228
All changes applied successfully.
229
Updated to revision 2 of branch %s
230
''' % osutils.pathjoin(self.test_dir, 'master',),
232
# The pending merges should still be there
233
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
235
def test_readonly_lightweight_update(self):
236
"""Update a light checkout of a readonly branch"""
237
tree = self.make_branch_and_tree('branch')
238
readonly_branch = branch.Branch.open(self.get_readonly_url('branch'))
239
checkout = readonly_branch.create_checkout('checkout',
241
tree.commit('empty commit')
242
self.run_bzr('update checkout')
244
def test_update_dash_r(self):
245
# Test that 'bzr update' works correctly when you have
246
# an update in the master tree, and a lightweight checkout
247
# which has merged another branch
248
master = self.make_branch_and_tree('master')
250
self.build_tree(['./file1'])
251
master.add(['file1'])
252
master.commit('one', rev_id='m1')
253
self.build_tree(['./file2'])
254
master.add(['file2'])
255
master.commit('two', rev_id='m2')
258
sr.run_script(self, '''
261
2>All changes applied successfully.
262
2>Updated to revision 1 of .../master
264
self.failUnlessExists('./file1')
265
self.failIfExists('./file2')
266
self.assertEquals(['m1'], master.get_parent_ids())
268
def test_update_dash_r_outside_history(self):
269
# Test that 'bzr update' works correctly when you have
270
# an update in the master tree, and a lightweight checkout
271
# which has merged another branch
272
master = self.make_branch_and_tree('master')
273
self.build_tree(['master/file1'])
274
master.add(['file1'])
275
master.commit('one', rev_id='m1')
277
# Create a second branch, with an extra commit
278
other = master.bzrdir.sprout('other').open_workingtree()
279
self.build_tree(['other/file2'])
281
other.commit('other2', rev_id='o2')
284
self.run_bzr('merge ../other')
285
master.commit('merge', rev_id='merge')
287
out, err = self.run_bzr('update -r revid:o2',
289
self.assertEqual('', out)
290
self.assertEqual('bzr: ERROR: branch has no revision o2\n'
291
'bzr update --revision only works'
292
' for a revision in the branch history\n',
295
def test_update_dash_r_in_master(self):
296
# Test that 'bzr update' works correctly when you have
297
# an update in the master tree,
298
master = self.make_branch_and_tree('master')
299
self.build_tree(['master/file1'])
300
master.add(['file1'])
301
master.commit('one', rev_id='m1')
303
self.run_bzr('checkout master checkout')
305
# add a revision in the master.
306
self.build_tree(['master/file2'])
307
master.add(['file2'])
308
master.commit('two', rev_id='m2')
312
sr.run_script(self, '''
313
$ bzr update -r revid:m2
315
2>All changes applied successfully.
316
2>Updated to revision 2 of branch .../master