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