19
19
"""Tests for the update command of bzr."""
23
from bzrlib import branch, bzrdir
24
from bzrlib.tests.blackbox import ExternalBase
25
from bzrlib.workingtree import WorkingTree
28
class TestUpdate(ExternalBase):
34
class TestUpdate(tests.TestCaseWithTransport):
30
36
def test_update_standalone_trivial(self):
31
37
self.make_branch_and_tree('.')
32
38
out, err = self.run_bzr('update')
33
self.assertEqual('Tree is up to date at revision 0.\n', err)
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)
34
48
self.assertEqual('', out)
36
50
def test_update_standalone_trivial_with_alias_up(self):
37
51
self.make_branch_and_tree('.')
38
52
out, err = self.run_bzr('up')
39
self.assertEqual('Tree is up to date at revision 0.\n', err)
53
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
40
56
self.assertEqual('', out)
42
58
def test_update_up_to_date_light_checkout(self):
43
59
self.make_branch_and_tree('branch')
44
60
self.run_bzr('checkout --lightweight branch checkout')
45
61
out, err = self.run_bzr('update checkout')
46
self.assertEqual('Tree is up to date at revision 0.\n', err)
62
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
63
% osutils.pathjoin(self.test_dir, 'branch'),
47
65
self.assertEqual('', out)
49
67
def test_update_up_to_date_checkout(self):
50
68
self.make_branch_and_tree('branch')
51
69
self.run_bzr('checkout branch checkout')
52
70
out, err = self.run_bzr('update checkout')
53
self.assertEqual('Tree is up to date at revision 0.\n', err)
71
self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
72
% osutils.pathjoin(self.test_dir, 'branch'),
54
74
self.assertEqual('', out)
56
76
def test_update_out_of_date_standalone_tree(self):
65
85
# now branch should be out of date
66
86
out,err = self.run_bzr('update branch')
67
87
self.assertEqual('', out)
68
self.assertContainsRe(err, '\+N file')
69
self.assertEndsWith(err, 'All changes applied successfully.\n'
70
'Updated to revision 1.\n')
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',),
71
93
self.failUnlessExists('branch/file')
73
95
def test_update_out_of_date_light_checkout(self):
80
102
self.run_bzr('commit -m add-file checkout')
81
103
# now checkout2 should be out of date
82
104
out,err = self.run_bzr('update checkout2')
83
self.assertContainsRe(err, '\+N file')
84
self.assertEndsWith(err, 'All changes applied successfully.\n'
85
'Updated to revision 1.\n')
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',),
86
110
self.assertEqual('', out)
88
112
def test_update_conflicts_returns_2(self):
104
128
a_file.write('Bar')
106
130
out,err = self.run_bzr('update checkout2', retcode=1)
107
self.assertContainsRe(err, 'M file')
108
self.assertEqual(['1 conflicts encountered.',
109
'Updated to revision 2.'],
110
err.split('\n')[-3:-1])
111
self.assertContainsRe(err, 'Text conflict in file\n')
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',),
112
137
self.assertEqual('', out)
114
139
def test_smoke_update_checkout_bound_branch_local_commits(self):
118
143
# make a bound branch
119
144
self.run_bzr('checkout master child')
120
145
# get an object form of child
121
child = WorkingTree.open('child')
146
child = workingtree.WorkingTree.open('child')
123
148
self.run_bzr('checkout --lightweight child checkout')
124
149
# get an object form of the checkout to manipulate
125
wt = WorkingTree.open('checkout')
150
wt = workingtree.WorkingTree.open('checkout')
127
152
a_file = file('master/file', 'wt')
128
153
a_file.write('Foo')
145
170
# get all three files and a pending merge.
146
171
out, err = self.run_bzr('update checkout')
147
172
self.assertEqual('', out)
148
self.assertContainsRe(err, '\+N file')
149
self.assertContainsRe(err, '\+N file_b')
150
self.assertContainsRe(err, 'Updated to revision 1.\n'
151
'Your local commits will now show as'
173
self.assertEqualDiff("""+N file
174
All changes applied successfully.
176
All changes applied successfully.
177
Updated to revision 1 of branch %s
178
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
179
""" % osutils.pathjoin(self.test_dir, 'master',),
153
181
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
154
182
self.failUnlessExists('checkout/file')
155
183
self.failUnlessExists('checkout/file_b')
195
223
# merges, because they were real merges
196
224
out, err = self.run_bzr('update')
197
225
self.assertEqual('', out)
198
self.assertEndsWith(err, 'All changes applied successfully.\n'
199
'Updated to revision 2.\n')
200
self.assertContainsRe(err, r'\+N file3')
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',),
201
231
# The pending merges should still be there
202
232
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])