/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4988.10.5 by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS
1
# Copyright (C) 2006-2010 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1508.1.24 by Robert Collins
Add update command for use with checkouts.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1508.1.24 by Robert Collins
Add update command for use with checkouts.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1508.1.24 by Robert Collins
Add update command for use with checkouts.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1508.1.24 by Robert Collins
Add update command for use with checkouts.
16
17
18
"""Tests for the update command of bzr."""
19
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
20
import os
21
import re
22
23
from bzrlib import (
24
    branch,
25
    bzrdir,
26
    osutils,
27
    tests,
28
    urlutils,
29
    workingtree,
30
    )
4916.1.3 by Martin Pool
Change test_update_dash_r to use ScriptRunner and work with current UI
31
from bzrlib.tests.script import ScriptRunner
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
32
33
34
class TestUpdate(tests.TestCaseWithTransport):
1508.1.24 by Robert Collins
Add update command for use with checkouts.
35
36
    def test_update_standalone_trivial(self):
2664.7.2 by Daniel Watkins
tests.blackbox.test_update now uses internals where appropriate.
37
        self.make_branch_and_tree('.')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
38
        out, err = self.run_bzr('update')
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
39
        self.assertEqual(
40
            'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
41
            err)
4879.1.1 by Neil Martinsen-Burrell
update provides feedback on which branch it is up to date with.
42
        self.assertEqual('', out)
43
44
    def test_update_quiet(self):
45
        self.make_branch_and_tree('.')
46
        out, err = self.run_bzr('update --quiet')
47
        self.assertEqual('', err)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
48
        self.assertEqual('', out)
49
1815.3.4 by Stefan (metze) Metzmacher
add simple test for 'bzr up'
50
    def test_update_standalone_trivial_with_alias_up(self):
2664.7.2 by Daniel Watkins
tests.blackbox.test_update now uses internals where appropriate.
51
        self.make_branch_and_tree('.')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
52
        out, err = self.run_bzr('up')
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
53
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
54
                         % self.test_dir,
55
                         err)
1815.3.4 by Stefan (metze) Metzmacher
add simple test for 'bzr up'
56
        self.assertEqual('', out)
57
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
58
    def test_update_up_to_date_light_checkout(self):
1508.1.24 by Robert Collins
Add update command for use with checkouts.
59
        self.make_branch_and_tree('branch')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
60
        self.run_bzr('checkout --lightweight branch checkout')
61
        out, err = self.run_bzr('update checkout')
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
62
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
63
                         % osutils.pathjoin(self.test_dir, 'branch'),
64
                         err)
1830.1.1 by John Arbash Meinel
Print up to date even if bound, also always print out current revno.
65
        self.assertEqual('', out)
66
67
    def test_update_up_to_date_checkout(self):
68
        self.make_branch_and_tree('branch')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
69
        self.run_bzr('checkout branch checkout')
4916.1.11 by Martin Pool
Don't show extra message about updating from master; it's fairly redundant
70
        sr = ScriptRunner()
71
        sr.run_script(self, '''
72
$ bzr update checkout
4916.1.15 by Martin Pool
whitespace correction in test
73
2>Tree is up to date at revision 0 of branch .../branch
4916.1.11 by Martin Pool
Don't show extra message about updating from master; it's fairly redundant
74
''')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
75
76
    def test_update_out_of_date_standalone_tree(self):
77
        # FIXME the default format has to change for this to pass
78
        # because it currently uses the branch last-revision marker.
79
        self.make_branch_and_tree('branch')
80
        # make a checkout
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
81
        self.run_bzr('checkout --lightweight branch checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
82
        self.build_tree(['checkout/file'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
83
        self.run_bzr('add checkout/file')
84
        self.run_bzr('commit -m add-file checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
85
        # now branch should be out of date
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
86
        out,err = self.run_bzr('update branch')
1711.2.107 by John Arbash Meinel
re-enable a skipped update test, and clean it up
87
        self.assertEqual('', out)
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
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',),
92
                         err)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
93
        self.assertPathExists('branch/file')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
94
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
95
    def test_update_out_of_date_light_checkout(self):
1508.1.24 by Robert Collins
Add update command for use with checkouts.
96
        self.make_branch_and_tree('branch')
97
        # make two checkouts
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
98
        self.run_bzr('checkout --lightweight branch checkout')
99
        self.run_bzr('checkout --lightweight branch checkout2')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
100
        self.build_tree(['checkout/file'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
101
        self.run_bzr('add checkout/file')
102
        self.run_bzr('commit -m add-file checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
103
        # now checkout2 should be out of date
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
104
        out,err = self.run_bzr('update checkout2')
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
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',),
109
                         err)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
110
        self.assertEqual('', out)
111
112
    def test_update_conflicts_returns_2(self):
113
        self.make_branch_and_tree('branch')
114
        # make two checkouts
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
115
        self.run_bzr('checkout --lightweight branch checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
116
        self.build_tree(['checkout/file'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
117
        self.run_bzr('add checkout/file')
118
        self.run_bzr('commit -m add-file checkout')
119
        self.run_bzr('checkout --lightweight branch checkout2')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
120
        # now alter file in checkout
121
        a_file = file('checkout/file', 'wt')
122
        a_file.write('Foo')
123
        a_file.close()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
124
        self.run_bzr('commit -m checnge-file checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
125
        # now checkout2 should be out of date
126
        # make a local change to file
127
        a_file = file('checkout2/file', 'wt')
128
        a_file.write('Bar')
129
        a_file.close()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
130
        out,err = self.run_bzr('update checkout2', retcode=1)
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
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',),
136
                         err)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
137
        self.assertEqual('', out)
1587.1.11 by Robert Collins
Local commits appear to be working properly.
138
139
    def test_smoke_update_checkout_bound_branch_local_commits(self):
140
        # smoke test for doing an update of a checkout of a bound
141
        # branch with local commits.
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
142
        master = self.make_branch_and_tree('master')
5954.2.4 by Aaron Bentley
Fix broken tests.
143
        master.commit('first commit')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
144
        # make a bound branch
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
145
        self.run_bzr('checkout master child')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
146
        # check that out
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
147
        self.run_bzr('checkout --lightweight child checkout')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
148
        # get an object form of the checkout to manipulate
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
149
        wt = workingtree.WorkingTree.open('checkout')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
150
        # change master
151
        a_file = file('master/file', 'wt')
152
        a_file.write('Foo')
153
        a_file.close()
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
154
        master.add(['file'])
155
        master_tip = master.commit('add file')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
156
        # change child
157
        a_file = file('child/file_b', 'wt')
158
        a_file.write('Foo')
159
        a_file.close()
5954.3.2 by Vincent Ladeuil
Nitpicks.
160
        # get an object form of child
161
        child = workingtree.WorkingTree.open('child')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
162
        child.add(['file_b'])
163
        child_tip = child.commit('add file_b', local=True)
1587.1.11 by Robert Collins
Local commits appear to be working properly.
164
        # check checkout
165
        a_file = file('checkout/file_c', 'wt')
166
        a_file.write('Foo')
167
        a_file.close()
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
168
        wt.add(['file_c'])
1587.1.11 by Robert Collins
Local commits appear to be working properly.
169
170
        # now, update checkout ->
171
        # get all three files and a pending merge.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
172
        out, err = self.run_bzr('update checkout')
1711.2.108 by John Arbash Meinel
Assert that update informs the user about where their local commits went.
173
        self.assertEqual('', out)
4985.3.1 by Gerard Krol
Werkt wel ok
174
        self.assertEqualDiff("""+N  file_b
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
175
All changes applied successfully.
4985.3.1 by Gerard Krol
Werkt wel ok
176
+N  file
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
177
All changes applied successfully.
5954.2.4 by Aaron Bentley
Fix broken tests.
178
Updated to revision 2 of branch %s
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
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',),
181
                         err)
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
182
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
183
        self.assertPathExists('checkout/file')
184
        self.assertPathExists('checkout/file_b')
185
        self.assertPathExists('checkout/file_c')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
186
        self.assertTrue(wt.has_filename('file_c'))
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
187
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'])
194
        master.add(['file'])
195
        master.commit('one', rev_id='m1')
196
197
        self.build_tree(['checkout1/'])
198
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
199
        branch.BranchReferenceFormat().initialize(checkout_dir,
200
            target_branch=master.branch)
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
201
        checkout1 = checkout_dir.create_workingtree('m1')
202
203
        # Create a second branch, with an extra commit
204
        other = master.bzrdir.sprout('other').open_workingtree()
205
        self.build_tree(['other/file2'])
206
        other.add(['file2'])
207
        other.commit('other2', rev_id='o2')
208
209
        # Create a new commit in the master branch
210
        self.build_tree(['master/file3'])
211
        master.add(['file3'])
212
        master.commit('f3', rev_id='m2')
213
214
        # Merge the other branch into checkout
215
        os.chdir('checkout1')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
216
        self.run_bzr('merge ../other')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
217
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
218
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
219
220
        # At this point, 'commit' should fail, because we are out of date
221
        self.run_bzr_error(["please run 'bzr update'"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
222
                           'commit -m merged')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
223
224
        # This should not report about local commits being pending
225
        # merges, because they were real merges
226
        out, err = self.run_bzr('update')
227
        self.assertEqual('', out)
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
228
        self.assertEqualDiff('''+N  file3
229
All changes applied successfully.
230
Updated to revision 2 of branch %s
231
''' % osutils.pathjoin(self.test_dir, 'master',),
232
                         err)
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
233
        # The pending merges should still be there
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
234
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
235
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
236
    def test_readonly_lightweight_update(self):
237
        """Update a light checkout of a readonly branch"""
238
        tree = self.make_branch_and_tree('branch')
239
        readonly_branch = branch.Branch.open(self.get_readonly_url('branch'))
2255.7.55 by Robert Collins
Whitespace fix.
240
        checkout = readonly_branch.create_checkout('checkout',
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
241
                                                   lightweight=True)
242
        tree.commit('empty commit')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
243
        self.run_bzr('update checkout')
2009.1.4 by Mark Hammond
First attempt to merge .dev and resolve the conflicts (but tests are
244
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
245
    def test_update_with_merge_merged_to_master(self):
246
        # Test that 'bzr update' works correctly when you have
247
        # an update in the master tree, and a [lightweight or otherwise]
248
        # checkout which has merge a revision merged to master already.
249
        master = self.make_branch_and_tree('master')
250
        self.build_tree(['master/file'])
251
        master.add(['file'])
252
        master.commit('one', rev_id='m1')
253
254
        self.build_tree(['checkout1/'])
255
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
256
        branch.BranchReferenceFormat().initialize(checkout_dir,
257
            target_branch=master.branch)
258
        checkout1 = checkout_dir.create_workingtree('m1')
259
260
        # Create a second branch, with an extra commit
261
        other = master.bzrdir.sprout('other').open_workingtree()
262
        self.build_tree(['other/file2'])
263
        other.add(['file2'])
264
        other.commit('other2', rev_id='o2')
265
266
        # Merge the other branch into checkout -  'start reviewing a patch'
267
        checkout1.merge_from_branch(other.branch)
268
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
269
270
        # Create a new commit in the master branch - 'someone else lands its'
271
        master.merge_from_branch(other.branch)
272
        master.commit('f3', rev_id='m2')
273
274
        # This should not report about local commits being pending
275
        # merges, because they were real merges (but are now gone).
276
        # It should perhaps report on them.
277
        out, err = self.run_bzr('update', working_dir='checkout1')
278
        self.assertEqual('', out)
279
        self.assertEqualDiff('''All changes applied successfully.
280
Updated to revision 2 of branch %s
281
''' % osutils.pathjoin(self.test_dir, 'master',),
282
                         err)
283
        # The pending merges should still be there
284
        self.assertEqual([], checkout1.get_parent_ids()[1:])
285
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
286
    def test_update_dash_r(self):
287
        master = self.make_branch_and_tree('master')
288
        os.chdir('master')
289
        self.build_tree(['./file1'])
290
        master.add(['file1'])
291
        master.commit('one', rev_id='m1')
292
        self.build_tree(['./file2'])
293
        master.add(['file2'])
294
        master.commit('two', rev_id='m2')
2009.1.6 by Mark Hammond
more tweaks of the merge to get the tests passing.
295
4985.3.5 by Gerard Krol
Reverting some unneeded changes.
296
        sr = ScriptRunner()
297
        sr.run_script(self, '''
298
$ bzr update -r 1
299
2>-D  file2
300
2>All changes applied successfully.
301
2>Updated to revision 1 of .../master
302
''')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
303
        self.assertPathExists('./file1')
304
        self.assertPathDoesNotExist('./file2')
4916.1.4 by Martin Pool
Check tree parent revision after update -r
305
        self.assertEquals(['m1'], master.get_parent_ids())
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
306
307
    def test_update_dash_r_outside_history(self):
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
308
        """Ensure that we can update -r to dotted revisions.
309
        """
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
310
        master = self.make_branch_and_tree('master')
311
        self.build_tree(['master/file1'])
312
        master.add(['file1'])
313
        master.commit('one', rev_id='m1')
314
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
315
        # Create a second branch, with extra commits
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
316
        other = master.bzrdir.sprout('other').open_workingtree()
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
317
        self.build_tree(['other/file2', 'other/file3'])
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
318
        other.add(['file2'])
319
        other.commit('other2', rev_id='o2')
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
320
        other.add(['file3'])
321
        other.commit('other3', rev_id='o3')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
322
323
        os.chdir('master')
2009.1.6 by Mark Hammond
more tweaks of the merge to get the tests passing.
324
        self.run_bzr('merge ../other')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
325
        master.commit('merge', rev_id='merge')
326
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
327
        # Switch to o2. file3 was added only in o3 and should be deleted.
328
        out, err = self.run_bzr('update -r revid:o2')
329
        self.assertContainsRe(err, '-D\s+file3')
330
        self.assertContainsRe(err, 'All changes applied successfully\.')
331
        self.assertContainsRe(err, 'Updated to revision 1.1.1 of branch .*')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
332
5126.1.3 by Parth Malwankar
updated test for switch from dotted rev to lastest.
333
        # Switch back to latest
334
        out, err = self.run_bzr('update')
335
        self.assertContainsRe(err, '\+N\s+file3')
336
        self.assertContainsRe(err, 'All changes applied successfully\.')
337
        self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
338
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
339
    def test_update_dash_r_in_master(self):
340
        # Test that 'bzr update' works correctly when you have
341
        # an update in the master tree,
342
        master = self.make_branch_and_tree('master')
343
        self.build_tree(['master/file1'])
344
        master.add(['file1'])
345
        master.commit('one', rev_id='m1')
346
2009.1.6 by Mark Hammond
more tweaks of the merge to get the tests passing.
347
        self.run_bzr('checkout master checkout')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
348
349
        # add a revision in the master.
350
        self.build_tree(['master/file2'])
351
        master.add(['file2'])
352
        master.commit('two', rev_id='m2')
353
354
        os.chdir('checkout')
4916.1.5 by Martin Pool
Update test_update_dash_r_in_master for ui changes
355
        sr = ScriptRunner()
356
        sr.run_script(self, '''
357
$ bzr update -r revid:m2
358
2>+N  file2
359
2>All changes applied successfully.
360
2>Updated to revision 2 of branch .../master
361
''')
4985.3.1 by Gerard Krol
Werkt wel ok
362
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
363
    def test_update_show_base(self):
364
        """bzr update support --show-base
365
366
        see https://bugs.launchpad.net/bzr/+bug/202374"""
367
368
        tree=self.make_branch_and_tree('.')
5430.7.2 by Rory Yorke
Changes as per Martin [gz]'s review.
369
370
        f = open('hello','wt')
371
        f.write('foo')
372
        f.close()
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
373
        tree.add('hello')
374
        tree.commit('fie')
5430.7.2 by Rory Yorke
Changes as per Martin [gz]'s review.
375
376
        f = open('hello','wt')
377
        f.write('fee')
378
        f.close()
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
379
        tree.commit('fee')
380
381
        #tree.update() gives no such revision, so ...
382
        self.run_bzr(['update','-r1'])
383
384
        #create conflict
5430.7.2 by Rory Yorke
Changes as per Martin [gz]'s review.
385
        f = open('hello','wt')
386
        f.write('fie')
387
        f.close()
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
388
389
        out, err = self.run_bzr(['update','--show-base'],retcode=1)
390
391
        # check for conflict notification
392
        self.assertContainsString(err,
393
                                  ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
394
        
395
        self.assertEqualDiff('<<<<<<< TREE\n'
396
                             'fie||||||| BASE-REVISION\n'
397
                             'foo=======\n'
398
                             'fee>>>>>>> MERGE-SOURCE\n',
399
                             open('hello').read())
400
4985.3.9 by Gerard Krol
Use assertFileEqual in the tests, instead of opening them and looking at the contents. TODO: check if this does work on Windows (due to possible \r\n line endings)?
401
    def test_update_checkout_prevent_double_merge(self):
402
        """"Launchpad bug 113809 in bzr "update performs two merges"
403
        https://launchpad.net/bugs/113809"""
4985.3.1 by Gerard Krol
Werkt wel ok
404
        master = self.make_branch_and_tree('master')
4985.3.17 by Vincent Ladeuil
Some cleanup.
405
        self.build_tree_contents([('master/file', 'initial contents\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
406
        master.add(['file'])
407
        master.commit('one', rev_id='m1')
408
409
        checkout = master.branch.create_checkout('checkout')
4985.3.10 by Gerard Krol
Reformat long lines
410
        lightweight = checkout.branch.create_checkout('lightweight',
411
                                                      lightweight=True)
4985.3.17 by Vincent Ladeuil
Some cleanup.
412
4985.3.1 by Gerard Krol
Werkt wel ok
413
        # time to create a mess
414
        # add a commit to the master
4985.3.17 by Vincent Ladeuil
Some cleanup.
415
        self.build_tree_contents([('master/file', 'master\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
416
        master.commit('two', rev_id='m2')
4985.3.17 by Vincent Ladeuil
Some cleanup.
417
        self.build_tree_contents([('master/file', 'master local changes\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
418
419
        # local commit on the checkout
4985.3.17 by Vincent Ladeuil
Some cleanup.
420
        self.build_tree_contents([('checkout/file', 'checkout\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
421
        checkout.commit('tree', rev_id='c2', local=True)
4985.3.17 by Vincent Ladeuil
Some cleanup.
422
        self.build_tree_contents([('checkout/file',
423
                                   'checkout local changes\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
424
425
        # lightweight 
4985.3.10 by Gerard Krol
Reformat long lines
426
        self.build_tree_contents([('lightweight/file',
4985.3.17 by Vincent Ladeuil
Some cleanup.
427
                                   'lightweight local changes\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
428
4985.3.9 by Gerard Krol
Use assertFileEqual in the tests, instead of opening them and looking at the contents. TODO: check if this does work on Windows (due to possible \r\n line endings)?
429
        # now update (and get conflicts)
4985.3.1 by Gerard Krol
Werkt wel ok
430
        out, err = self.run_bzr('update lightweight', retcode=1)
431
        self.assertEqual('', out)
5053.1.1 by Martin Pool
Merge 2.1 back to trunk
432
        # NB: these conflicts are actually in the source code
4985.3.17 by Vincent Ladeuil
Some cleanup.
433
        self.assertFileEqual('''\
434
<<<<<<< TREE
435
lightweight local changes
436
=======
437
checkout
438
>>>>>>> MERGE-SOURCE
439
''',
4985.3.10 by Gerard Krol
Reformat long lines
440
                             'lightweight/file')
4985.3.17 by Vincent Ladeuil
Some cleanup.
441
4985.3.1 by Gerard Krol
Werkt wel ok
442
        # resolve it
4985.3.10 by Gerard Krol
Reformat long lines
443
        self.build_tree_contents([('lightweight/file',
4985.3.17 by Vincent Ladeuil
Some cleanup.
444
                                   'lightweight+checkout\n')])
445
        self.run_bzr('resolve lightweight/file')
4985.3.1 by Gerard Krol
Werkt wel ok
446
4985.3.9 by Gerard Krol
Use assertFileEqual in the tests, instead of opening them and looking at the contents. TODO: check if this does work on Windows (due to possible \r\n line endings)?
447
        # check we get the second conflict
4985.3.1 by Gerard Krol
Werkt wel ok
448
        out, err = self.run_bzr('update lightweight', retcode=1)
449
        self.assertEqual('', out)
5053.1.1 by Martin Pool
Merge 2.1 back to trunk
450
        # NB: these conflicts are actually in the source code
4985.3.17 by Vincent Ladeuil
Some cleanup.
451
        self.assertFileEqual('''\
452
<<<<<<< TREE
453
lightweight+checkout
454
=======
455
master
456
>>>>>>> MERGE-SOURCE
457
''',
4985.3.10 by Gerard Krol
Reformat long lines
458
                             'lightweight/file')