29
29
class TestUpdate(ExternalBase):
31
31
def test_update_standalone_trivial(self):
33
out, err = self.run_bzr('update')
33
out, err = self.runbzr('update')
34
34
self.assertEqual('Tree is up to date at revision 0.\n', err)
35
35
self.assertEqual('', out)
37
37
def test_update_standalone_trivial_with_alias_up(self):
39
out, err = self.run_bzr('up')
39
out, err = self.runbzr('up')
40
40
self.assertEqual('Tree is up to date at revision 0.\n', err)
41
41
self.assertEqual('', out)
43
43
def test_update_up_to_date_light_checkout(self):
44
44
self.make_branch_and_tree('branch')
45
self.run_bzr('checkout --lightweight branch checkout')
46
out, err = self.run_bzr('update checkout')
45
self.runbzr('checkout --lightweight branch checkout')
46
out, err = self.runbzr('update checkout')
47
47
self.assertEqual('Tree is up to date at revision 0.\n', err)
48
48
self.assertEqual('', out)
50
50
def test_update_up_to_date_checkout(self):
51
51
self.make_branch_and_tree('branch')
52
self.run_bzr('checkout branch checkout')
53
out, err = self.run_bzr('update checkout')
52
self.run_bzr('checkout', 'branch', 'checkout')
53
out, err = self.run_bzr('update', 'checkout')
54
54
self.assertEqual('Tree is up to date at revision 0.\n', err)
55
55
self.assertEqual('', out)
59
59
# because it currently uses the branch last-revision marker.
60
60
self.make_branch_and_tree('branch')
62
self.run_bzr('checkout --lightweight branch checkout')
62
self.runbzr('checkout --lightweight branch checkout')
63
63
self.build_tree(['checkout/file'])
64
self.run_bzr('add checkout/file')
65
self.run_bzr('commit -m add-file checkout')
64
self.runbzr('add checkout/file')
65
self.runbzr('commit -m add-file checkout')
66
66
# now branch should be out of date
67
out,err = self.run_bzr('update branch')
67
out,err = self.runbzr('update branch')
68
68
self.assertEqual('', out)
69
self.assertContainsRe(err, '\+N file')
70
self.assertEndsWith(err, 'All changes applied successfully.\n'
71
'Updated to revision 1.\n')
69
self.assertEqual('All changes applied successfully.\n'
70
'Updated to revision 1.\n', err)
72
71
self.failUnlessExists('branch/file')
74
73
def test_update_out_of_date_light_checkout(self):
75
74
self.make_branch_and_tree('branch')
76
75
# make two checkouts
77
self.run_bzr('checkout --lightweight branch checkout')
78
self.run_bzr('checkout --lightweight branch checkout2')
76
self.runbzr('checkout --lightweight branch checkout')
77
self.runbzr('checkout --lightweight branch checkout2')
79
78
self.build_tree(['checkout/file'])
80
self.run_bzr('add checkout/file')
81
self.run_bzr('commit -m add-file checkout')
79
self.runbzr('add checkout/file')
80
self.runbzr('commit -m add-file checkout')
82
81
# now checkout2 should be out of date
83
out,err = self.run_bzr('update checkout2')
84
self.assertContainsRe(err, '\+N file')
85
self.assertEndsWith(err, 'All changes applied successfully.\n'
86
'Updated to revision 1.\n')
82
out,err = self.runbzr('update checkout2')
83
self.assertEqual('All changes applied successfully.\n'
84
'Updated to revision 1.\n',
87
86
self.assertEqual('', out)
89
88
def test_update_conflicts_returns_2(self):
90
89
self.make_branch_and_tree('branch')
91
90
# make two checkouts
92
self.run_bzr('checkout --lightweight branch checkout')
91
self.runbzr('checkout --lightweight branch checkout')
93
92
self.build_tree(['checkout/file'])
94
self.run_bzr('add checkout/file')
95
self.run_bzr('commit -m add-file checkout')
96
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')
97
96
# now alter file in checkout
98
97
a_file = file('checkout/file', 'wt')
99
98
a_file.write('Foo')
101
self.run_bzr('commit -m checnge-file checkout')
100
self.runbzr('commit -m checnge-file checkout')
102
101
# now checkout2 should be out of date
103
102
# make a local change to file
104
103
a_file = file('checkout2/file', 'wt')
105
104
a_file.write('Bar')
107
out,err = self.run_bzr('update checkout2', retcode=1)
108
self.assertContainsRe(err, 'M file')
106
out,err = self.runbzr('update checkout2', retcode=1)
109
107
self.assertEqual(['1 conflicts encountered.',
110
108
'Updated to revision 2.'],
111
err.split('\n')[-3:-1])
109
err.split('\n')[1:3])
112
110
self.assertContainsRe(err, 'Text conflict in file\n')
113
111
self.assertEqual('', out)
115
113
def test_smoke_update_checkout_bound_branch_local_commits(self):
116
114
# smoke test for doing an update of a checkout of a bound
117
115
# branch with local commits.
118
master = self.make_branch_and_tree('master')
116
self.make_branch_and_tree('master')
119
117
# make a bound branch
120
self.run_bzr('checkout master child')
121
# get an object form of child
122
child = WorkingTree.open('child')
118
self.run_bzr('checkout', 'master', 'child')
124
self.run_bzr('checkout --lightweight child checkout')
125
# get an object form of the checkout to manipulate
126
wt = WorkingTree.open('checkout')
120
self.run_bzr('checkout', '--lightweight', 'child', 'checkout')
128
122
a_file = file('master/file', 'wt')
129
123
a_file.write('Foo')
132
master_tip = master.commit('add file')
125
self.run_bzr('add', 'master')
126
self.run_bzr('commit', '-m', 'add file', 'master')
134
128
a_file = file('child/file_b', 'wt')
135
129
a_file.write('Foo')
137
child.add(['file_b'])
138
child_tip = child.commit('add file_b', local=True)
131
self.run_bzr('add', 'child')
132
self.run_bzr('commit', '--local', '-m', 'add file_b', 'child')
140
134
a_file = file('checkout/file_c', 'wt')
141
135
a_file.write('Foo')
137
self.run_bzr('add', 'checkout')
145
139
# now, update checkout ->
146
140
# get all three files and a pending merge.
147
out, err = self.run_bzr('update checkout')
141
out, err = self.run_bzr('update', 'checkout')
148
142
self.assertEqual('', out)
149
self.assertContainsRe(err, '\+N file')
150
self.assertContainsRe(err, '\+N file_b')
151
143
self.assertContainsRe(err, 'Updated to revision 1.\n'
152
144
'Your local commits will now show as'
153
145
' pending merges')
154
self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
146
wt = WorkingTree.open('checkout')
147
self.assertNotEqual([], wt.pending_merges())
155
148
self.failUnlessExists('checkout/file')
156
149
self.failUnlessExists('checkout/file_b')
157
150
self.failUnlessExists('checkout/file_c')
185
178
# Merge the other branch into checkout
186
179
os.chdir('checkout1')
187
self.run_bzr('merge ../other')
180
self.run_bzr('merge', '../other')
189
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
182
self.assertEqual(['o2'], checkout1.pending_merges())
191
184
# At this point, 'commit' should fail, because we are out of date
192
185
self.run_bzr_error(["please run 'bzr update'"],
186
'commit', '-m', 'merged')
195
188
# This should not report about local commits being pending
196
189
# merges, because they were real merges
197
190
out, err = self.run_bzr('update')
198
191
self.assertEqual('', out)
199
self.assertEndsWith(err, 'All changes applied successfully.\n'
200
'Updated to revision 2.\n')
201
self.assertContainsRe(err, r'\+N file3')
192
self.assertEqual('All changes applied successfully.\n'
193
'Updated to revision 2.\n', err)
202
195
# The pending merges should still be there
203
self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
205
def test_readonly_lightweight_update(self):
206
"""Update a light checkout of a readonly branch"""
207
tree = self.make_branch_and_tree('branch')
208
readonly_branch = branch.Branch.open(self.get_readonly_url('branch'))
209
checkout = readonly_branch.create_checkout('checkout',
211
tree.commit('empty commit')
212
self.run_bzr('update checkout')
196
self.assertEqual(['o2'], checkout1.pending_merges())