13
14
# You should have received a copy of the GNU General Public License
14
15
# along with this program; if not, write to the Free Software
15
# 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
18
19
"""Tests for the update command of bzr."""
31
from bzrlib.tests.script import ScriptRunner
34
class TestUpdate(tests.TestCaseWithTransport):
23
from bzrlib import branch, bzrdir
24
from bzrlib.tests import TestSkipped
25
from bzrlib.tests.blackbox import ExternalBase
26
from bzrlib.workingtree import WorkingTree
29
class TestUpdate(ExternalBase):
36
31
def test_update_standalone_trivial(self):
37
self.make_branch_and_tree('.')
38
out, err = self.run_bzr('update')
40
'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
42
self.assertEqual('', out)
44
def test_update_quiet(self):
45
self.make_branch_and_tree('.')
46
out, err = self.run_bzr('update --quiet')
47
self.assertEqual('', err)
33
out, err = self.runbzr('update')
34
self.assertEqual('Tree is up to date at revision 0.\n', err)
48
35
self.assertEqual('', out)
50
37
def test_update_standalone_trivial_with_alias_up(self):
51
self.make_branch_and_tree('.')
52
out, err = self.run_bzr('up')
53
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
39
out, err = self.runbzr('up')
40
self.assertEqual('Tree is up to date at revision 0.\n', err)
56
41
self.assertEqual('', out)
58
43
def test_update_up_to_date_light_checkout(self):
59
44
self.make_branch_and_tree('branch')
60
self.run_bzr('checkout --lightweight branch checkout')
61
out, err = self.run_bzr('update checkout')
62
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
63
% osutils.pathjoin(self.test_dir, 'branch'),
45
self.runbzr('checkout --lightweight branch checkout')
46
out, err = self.runbzr('update checkout')
47
self.assertEqual('Tree is up to date at revision 0.\n', err)
65
48
self.assertEqual('', out)
67
50
def test_update_up_to_date_checkout(self):
68
51
self.make_branch_and_tree('branch')
69
self.run_bzr('checkout branch checkout')
71
sr.run_script(self, '''
73
2>Tree is up to date at revision 0 of branch .../branch
52
self.run_bzr('checkout', 'branch', 'checkout')
53
out, err = self.run_bzr('update', 'checkout')
54
self.assertEqual('Tree is up to date at revision 0.\n', err)
55
self.assertEqual('', out)
76
57
def test_update_out_of_date_standalone_tree(self):
77
58
# FIXME the default format has to change for this to pass
78
59
# because it currently uses the branch last-revision marker.
79
60
self.make_branch_and_tree('branch')
81
self.run_bzr('checkout --lightweight branch checkout')
62
self.runbzr('checkout --lightweight branch checkout')
82
63
self.build_tree(['checkout/file'])
83
self.run_bzr('add checkout/file')
84
self.run_bzr('commit -m add-file checkout')
64
self.runbzr('add checkout/file')
65
self.runbzr('commit -m add-file checkout')
85
66
# now branch should be out of date
86
out,err = self.run_bzr('update branch')
67
out,err = self.runbzr('update branch')
87
68
self.assertEqual('', out)
88
self.assertEqualDiff("""+N file
89
All changes applied successfully.
90
Updated to revision 1 of branch %s
91
""" % osutils.pathjoin(self.test_dir, 'branch',),
69
self.assertEqual('All changes applied successfully.\n'
70
'Updated to revision 1.\n', err)
93
71
self.failUnlessExists('branch/file')
95
73
def test_update_out_of_date_light_checkout(self):
96
74
self.make_branch_and_tree('branch')
97
75
# make two checkouts
98
self.run_bzr('checkout --lightweight branch checkout')
99
self.run_bzr('checkout --lightweight branch checkout2')
76
self.runbzr('checkout --lightweight branch checkout')
77
self.runbzr('checkout --lightweight branch checkout2')
100
78
self.build_tree(['checkout/file'])
101
self.run_bzr('add checkout/file')
102
self.run_bzr('commit -m add-file checkout')
79
self.runbzr('add checkout/file')
80
self.runbzr('commit -m add-file checkout')
103
81
# now checkout2 should be out of date
104
out,err = self.run_bzr('update checkout2')
105
self.assertEqualDiff('''+N file
106
All changes applied successfully.
107
Updated to revision 1 of branch %s
108
''' % osutils.pathjoin(self.test_dir, 'branch',),
82
out,err = self.runbzr('update checkout2')
83
self.assertEqual('All changes applied successfully.\n'
84
'Updated to revision 1.\n',
110
86
self.assertEqual('', out)
112
88
def test_update_conflicts_returns_2(self):
113
89
self.make_branch_and_tree('branch')
114
90
# make two checkouts
115
self.run_bzr('checkout --lightweight branch checkout')
91
self.runbzr('checkout --lightweight branch checkout')
116
92
self.build_tree(['checkout/file'])
117
self.run_bzr('add checkout/file')
118
self.run_bzr('commit -m add-file checkout')
119
self.run_bzr('checkout --lightweight branch checkout2')
93
self.runbzr('add checkout/file')
94
self.runbzr('commit -m add-file checkout')
95
self.runbzr('checkout --lightweight branch checkout2')
120
96
# now alter file in checkout
121
97
a_file = file('checkout/file', 'wt')
122
98
a_file.write('Foo')
124
self.run_bzr('commit -m checnge-file checkout')
100
self.runbzr('commit -m checnge-file checkout')
125
101
# now checkout2 should be out of date
126
102
# make a local change to file
127
103
a_file = file('checkout2/file', 'wt')
128
104
a_file.write('Bar')
130
out,err = self.run_bzr('update checkout2', retcode=1)
131
self.assertEqualDiff(''' M file
132
Text conflict in file
133
1 conflicts encountered.
134
Updated to revision 2 of branch %s
135
''' % osutils.pathjoin(self.test_dir, 'branch',),
106
out,err = self.runbzr('update checkout2', retcode=1)
107
self.assertEqual(['1 conflicts encountered.',
108
'Updated to revision 2.'],
109
err.split('\n')[1:3])
110
self.assertContainsRe(err, 'Text conflict in file\n')
137
111
self.assertEqual('', out)
139
113
def test_smoke_update_checkout_bound_branch_local_commits(self):
238
205
checkout = readonly_branch.create_checkout('checkout',
239
206
lightweight=True)
240
207
tree.commit('empty commit')
241
self.run_bzr('update checkout')
243
def test_update_dash_r(self):
244
master = self.make_branch_and_tree('master')
246
self.build_tree(['./file1'])
247
master.add(['file1'])
248
master.commit('one', rev_id='m1')
249
self.build_tree(['./file2'])
250
master.add(['file2'])
251
master.commit('two', rev_id='m2')
254
sr.run_script(self, '''
257
2>All changes applied successfully.
258
2>Updated to revision 1 of .../master
260
self.failUnlessExists('./file1')
261
self.failIfExists('./file2')
262
self.assertEquals(['m1'], master.get_parent_ids())
264
def test_update_dash_r_outside_history(self):
265
master = self.make_branch_and_tree('master')
266
self.build_tree(['master/file1'])
267
master.add(['file1'])
268
master.commit('one', rev_id='m1')
270
# Create a second branch, with an extra commit
271
other = master.bzrdir.sprout('other').open_workingtree()
272
self.build_tree(['other/file2'])
274
other.commit('other2', rev_id='o2')
277
self.run_bzr('merge ../other')
278
master.commit('merge', rev_id='merge')
280
out, err = self.run_bzr('update -r revid:o2',
282
self.assertEqual('', out)
283
self.assertEqual('bzr: ERROR: branch has no revision o2\n'
284
'bzr update --revision only works'
285
' for a revision in the branch history\n',
288
def test_update_dash_r_in_master(self):
289
# Test that 'bzr update' works correctly when you have
290
# an update in the master tree,
291
master = self.make_branch_and_tree('master')
292
self.build_tree(['master/file1'])
293
master.add(['file1'])
294
master.commit('one', rev_id='m1')
296
self.run_bzr('checkout master checkout')
298
# add a revision in the master.
299
self.build_tree(['master/file2'])
300
master.add(['file2'])
301
master.commit('two', rev_id='m2')
305
sr.run_script(self, '''
306
$ bzr update -r revid:m2
308
2>All changes applied successfully.
309
2>Updated to revision 2 of branch .../master
312
def test_update_checkout_prevent_double_merge(self):
313
""""Launchpad bug 113809 in bzr "update performs two merges"
314
https://launchpad.net/bugs/113809"""
315
master = self.make_branch_and_tree('master')
316
self.build_tree_contents([('master/file', 'initial contents\n')])
318
master.commit('one', rev_id='m1')
320
checkout = master.branch.create_checkout('checkout')
321
lightweight = checkout.branch.create_checkout('lightweight',
324
# time to create a mess
325
# add a commit to the master
326
self.build_tree_contents([('master/file', 'master\n')])
327
master.commit('two', rev_id='m2')
328
self.build_tree_contents([('master/file', 'master local changes\n')])
330
# local commit on the checkout
331
self.build_tree_contents([('checkout/file', 'checkout\n')])
332
checkout.commit('tree', rev_id='c2', local=True)
333
self.build_tree_contents([('checkout/file',
334
'checkout local changes\n')])
337
self.build_tree_contents([('lightweight/file',
338
'lightweight local changes\n')])
340
# now update (and get conflicts)
341
out, err = self.run_bzr('update lightweight', retcode=1)
342
self.assertEqual('', out)
343
# NB: these conflicts are actually in the source code
344
self.assertFileEqual('''\
346
lightweight local changes
354
self.build_tree_contents([('lightweight/file',
355
'lightweight+checkout\n')])
356
self.run_bzr('resolve lightweight/file')
358
# check we get the second conflict
359
out, err = self.run_bzr('update lightweight', retcode=1)
360
self.assertEqual('', out)
361
# NB: these conflicts are actually in the source code
362
self.assertFileEqual('''\
208
self.runbzr(['update', 'checkout'])