/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2012, 2016 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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
22
from breezy import (
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
23
    branch,
24
    osutils,
25
    tests,
26
    workingtree,
27
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
28
from breezy.bzr import (
29
    bzrdir,
30
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
31
from breezy.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(
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
40
            'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
41
            err)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
42
        self.assertEqual('', out)
4879.1.1 by Neil Martinsen-Burrell
update provides feedback on which branch it is up to date with.
43
44
    def test_update_quiet(self):
45
        self.make_branch_and_tree('.')
46
        out, err = self.run_bzr('update --quiet')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
47
        self.assertEqual('', err)
48
        self.assertEqual('', out)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
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')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
53
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
54
                         % self.test_dir,
55
                         err)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
56
        self.assertEqual('', out)
1815.3.4 by Stefan (metze) Metzmacher
add simple test for 'bzr up'
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')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
62
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
63
                         % osutils.pathjoin(self.test_dir, 'branch'),
64
                         err)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
65
        self.assertEqual('', out)
1830.1.1 by John Arbash Meinel
Print up to date even if bound, also always print out current revno.
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, '''
6622.1.29 by Jelmer Vernooij
Fix some more tests.
72
$ brz 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
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
86
        out, err = self.run_bzr('update branch')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
87
        self.assertEqual('', out)
88
        self.assertEqualDiff("""+N  file
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
89
All changes applied successfully.
90
Updated to revision 1 of branch %s
91
""" % osutils.pathjoin(self.test_dir, 'branch',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
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
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
104
        out, err = self.run_bzr('update checkout2')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
105
        self.assertEqualDiff('''+N  file
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
106
All changes applied successfully.
107
Updated to revision 1 of branch %s
108
''' % osutils.pathjoin(self.test_dir, 'branch',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
109
            err)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
110
        self.assertEqual('', out)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
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
6973.7.5 by Jelmer Vernooij
s/file/open.
121
        with open('checkout/file', 'wt') as a_file:
122
            a_file.write('Foo')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
123
        self.run_bzr('commit -m checnge-file checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
124
        # now checkout2 should be out of date
125
        # make a local change to file
6973.7.5 by Jelmer Vernooij
s/file/open.
126
        with open('checkout2/file', 'wt') as a_file:
127
            a_file.write('Bar')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
128
        out, err = self.run_bzr('update checkout2', retcode=1)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
129
        self.assertEqualDiff(''' M  file
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
130
Text conflict in file
131
1 conflicts encountered.
132
Updated to revision 2 of branch %s
133
''' % osutils.pathjoin(self.test_dir, 'branch',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
134
            err)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
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
6973.7.5 by Jelmer Vernooij
s/file/open.
149
        with open('master/file', 'wt') as a_file:
150
            a_file.write('Foo')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
151
        master.add(['file'])
152
        master_tip = master.commit('add file')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
153
        # change child
6973.7.5 by Jelmer Vernooij
s/file/open.
154
        with open('child/file_b', 'wt') as a_file:
155
            a_file.write('Foo')
5954.3.2 by Vincent Ladeuil
Nitpicks.
156
        # get an object form of child
157
        child = workingtree.WorkingTree.open('child')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
158
        child.add(['file_b'])
159
        child_tip = child.commit('add file_b', local=True)
1587.1.11 by Robert Collins
Local commits appear to be working properly.
160
        # check checkout
6973.7.5 by Jelmer Vernooij
s/file/open.
161
        with open('checkout/file_c', 'wt') as a_file:
162
            a_file.write('Foo')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
163
        wt.add(['file_c'])
1587.1.11 by Robert Collins
Local commits appear to be working properly.
164
165
        # now, update checkout ->
166
        # get all three files and a pending merge.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
167
        out, err = self.run_bzr('update checkout')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
168
        self.assertEqual('', out)
169
        self.assertEqualDiff("""+N  file_b
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
170
All changes applied successfully.
4985.3.1 by Gerard Krol
Werkt wel ok
171
+N  file
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
172
All changes applied successfully.
5954.2.4 by Aaron Bentley
Fix broken tests.
173
Updated to revision 2 of branch %s
6622.1.29 by Jelmer Vernooij
Fix some more tests.
174
Your local commits will now show as pending merges with 'brz status', and can be committed with 'brz commit'.
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
175
""" % osutils.pathjoin(self.test_dir, 'master',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
176
            err)
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
177
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
178
        self.assertPathExists('checkout/file')
179
        self.assertPathExists('checkout/file_b')
180
        self.assertPathExists('checkout/file_c')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
181
        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.
182
183
    def test_update_with_merges(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
184
        # Test that 'brz update' works correctly when you have
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
185
        # an update in the master tree, and a lightweight checkout
186
        # which has merged another branch
187
        master = self.make_branch_and_tree('master')
188
        self.build_tree(['master/file'])
189
        master.add(['file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
190
        master.commit('one', rev_id=b'm1')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
191
192
        self.build_tree(['checkout1/'])
193
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
6437.7.3 by Jelmer Vernooij
Use ControlDir.set_branch_reference.
194
        checkout_dir.set_branch_reference(master.branch)
7045.2.2 by Jelmer Vernooij
Fix whoami test.
195
        checkout1 = checkout_dir.create_workingtree(b'm1')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
196
197
        # Create a second branch, with an extra commit
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
198
        other = master.controldir.sprout('other').open_workingtree()
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
199
        self.build_tree(['other/file2'])
200
        other.add(['file2'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
201
        other.commit('other2', rev_id=b'o2')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
202
203
        # Create a new commit in the master branch
204
        self.build_tree(['master/file3'])
205
        master.add(['file3'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
206
        master.commit('f3', rev_id=b'm2')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
207
208
        # Merge the other branch into checkout
209
        os.chdir('checkout1')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
210
        self.run_bzr('merge ../other')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
211
6973.13.2 by Jelmer Vernooij
Fix some more tests.
212
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
213
214
        # At this point, 'commit' should fail, because we are out of date
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
215
        self.run_bzr_error(["please run 'brz update'"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
216
                           'commit -m merged')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
217
218
        # This should not report about local commits being pending
219
        # merges, because they were real merges
220
        out, err = self.run_bzr('update')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
221
        self.assertEqual('', out)
222
        self.assertEqualDiff('''+N  file3
4879.1.3 by Vincent Ladeuil
Cleanup tests and tweak the text displayed.
223
All changes applied successfully.
224
Updated to revision 2 of branch %s
225
''' % osutils.pathjoin(self.test_dir, 'master',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
226
            err)
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
227
        # The pending merges should still be there
6973.13.2 by Jelmer Vernooij
Fix some more tests.
228
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
229
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
230
    def test_readonly_lightweight_update(self):
231
        """Update a light checkout of a readonly branch"""
232
        tree = self.make_branch_and_tree('branch')
233
        readonly_branch = branch.Branch.open(self.get_readonly_url('branch'))
2255.7.55 by Robert Collins
Whitespace fix.
234
        checkout = readonly_branch.create_checkout('checkout',
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
235
                                                   lightweight=True)
236
        tree.commit('empty commit')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
237
        self.run_bzr('update checkout')
2009.1.4 by Mark Hammond
First attempt to merge .dev and resolve the conflicts (but tests are
238
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
239
    def test_update_with_merge_merged_to_master(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
240
        # Test that 'brz update' works correctly when you have
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
241
        # an update in the master tree, and a [lightweight or otherwise]
242
        # checkout which has merge a revision merged to master already.
243
        master = self.make_branch_and_tree('master')
244
        self.build_tree(['master/file'])
245
        master.add(['file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
246
        master.commit('one', rev_id=b'm1')
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
247
248
        self.build_tree(['checkout1/'])
249
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
6437.7.3 by Jelmer Vernooij
Use ControlDir.set_branch_reference.
250
        checkout_dir.set_branch_reference(master.branch)
7045.2.2 by Jelmer Vernooij
Fix whoami test.
251
        checkout1 = checkout_dir.create_workingtree(b'm1')
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
252
253
        # Create a second branch, with an extra commit
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
254
        other = master.controldir.sprout('other').open_workingtree()
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
255
        self.build_tree(['other/file2'])
256
        other.add(['file2'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
257
        other.commit('other2', rev_id=b'o2')
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
258
259
        # Merge the other branch into checkout -  'start reviewing a patch'
260
        checkout1.merge_from_branch(other.branch)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
261
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
262
263
        # Create a new commit in the master branch - 'someone else lands its'
264
        master.merge_from_branch(other.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
265
        master.commit('f3', rev_id=b'm2')
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
266
267
        # This should not report about local commits being pending
268
        # merges, because they were real merges (but are now gone).
269
        # It should perhaps report on them.
270
        out, err = self.run_bzr('update', working_dir='checkout1')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
271
        self.assertEqual('', out)
272
        self.assertEqualDiff('''All changes applied successfully.
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
273
Updated to revision 2 of branch %s
274
''' % osutils.pathjoin(self.test_dir, 'master',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
275
            err)
5151.1.1 by Robert Collins
``bzr update`` when a pending merge in the working tree has been merged
276
        # The pending merges should still be there
277
        self.assertEqual([], checkout1.get_parent_ids()[1:])
278
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
279
    def test_update_dash_r(self):
280
        master = self.make_branch_and_tree('master')
281
        os.chdir('master')
282
        self.build_tree(['./file1'])
283
        master.add(['file1'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
284
        master.commit('one', rev_id=b'm1')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
285
        self.build_tree(['./file2'])
286
        master.add(['file2'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
287
        master.commit('two', rev_id=b'm2')
2009.1.6 by Mark Hammond
more tweaks of the merge to get the tests passing.
288
4985.3.5 by Gerard Krol
Reverting some unneeded changes.
289
        sr = ScriptRunner()
290
        sr.run_script(self, '''
6622.1.29 by Jelmer Vernooij
Fix some more tests.
291
$ brz update -r 1
4985.3.5 by Gerard Krol
Reverting some unneeded changes.
292
2>-D  file2
293
2>All changes applied successfully.
294
2>Updated to revision 1 of .../master
295
''')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
296
        self.assertPathExists('./file1')
297
        self.assertPathDoesNotExist('./file2')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
298
        self.assertEqual([b'm1'], master.get_parent_ids())
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
299
300
    def test_update_dash_r_outside_history(self):
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
301
        """Ensure that we can update -r to dotted revisions.
302
        """
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
303
        master = self.make_branch_and_tree('master')
304
        self.build_tree(['master/file1'])
305
        master.add(['file1'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
306
        master.commit('one', rev_id=b'm1')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
307
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
308
        # Create a second branch, with extra commits
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
309
        other = master.controldir.sprout('other').open_workingtree()
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
310
        self.build_tree(['other/file2', 'other/file3'])
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
311
        other.add(['file2'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
312
        other.commit('other2', rev_id=b'o2')
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
313
        other.add(['file3'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
314
        other.commit('other3', rev_id=b'o3')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
315
316
        os.chdir('master')
2009.1.6 by Mark Hammond
more tweaks of the merge to get the tests passing.
317
        self.run_bzr('merge ../other')
6855.4.1 by Jelmer Vernooij
Yet more bees.
318
        master.commit('merge', rev_id=b'merge')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
319
5126.1.1 by Parth Malwankar
update -r now supports dotted revision.
320
        # Switch to o2. file3 was added only in o3 and should be deleted.
321
        out, err = self.run_bzr('update -r revid:o2')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
322
        self.assertContainsRe(err, '-D\\s+file3')
323
        self.assertContainsRe(err, 'All changes applied successfully\\.')
324
        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.
325
5126.1.3 by Parth Malwankar
updated test for switch from dotted rev to lastest.
326
        # Switch back to latest
327
        out, err = self.run_bzr('update')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
328
        self.assertContainsRe(err, '\\+N\\s+file3')
329
        self.assertContainsRe(err, 'All changes applied successfully\\.')
330
        self.assertContainsRe(err, 'Updated to revision 2 of branch .*')
5126.1.3 by Parth Malwankar
updated test for switch from dotted rev to lastest.
331
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
332
    def test_update_dash_r_in_master(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
333
        # Test that 'brz update' works correctly when you have
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
334
        # an update in the master tree,
335
        master = self.make_branch_and_tree('master')
336
        self.build_tree(['master/file1'])
337
        master.add(['file1'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
338
        master.commit('one', rev_id=b'm1')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
339
2009.1.6 by Mark Hammond
more tweaks of the merge to get the tests passing.
340
        self.run_bzr('checkout master checkout')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
341
342
        # add a revision in the master.
343
        self.build_tree(['master/file2'])
344
        master.add(['file2'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
345
        master.commit('two', rev_id=b'm2')
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
346
347
        os.chdir('checkout')
4916.1.5 by Martin Pool
Update test_update_dash_r_in_master for ui changes
348
        sr = ScriptRunner()
349
        sr.run_script(self, '''
6622.1.29 by Jelmer Vernooij
Fix some more tests.
350
$ brz update -r revid:m2
4916.1.5 by Martin Pool
Update test_update_dash_r_in_master for ui changes
351
2>+N  file2
352
2>All changes applied successfully.
353
2>Updated to revision 2 of branch .../master
354
''')
4985.3.1 by Gerard Krol
Werkt wel ok
355
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
356
    def test_update_show_base(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
357
        """brz update support --show-base
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
358
359
        see https://bugs.launchpad.net/bzr/+bug/202374"""
360
7143.15.2 by Jelmer Vernooij
Run autopep8.
361
        tree = self.make_branch_and_tree('.')
5430.7.2 by Rory Yorke
Changes as per Martin [gz]'s review.
362
6973.7.5 by Jelmer Vernooij
s/file/open.
363
        with open('hello', 'wt') as f:
364
            f.write('foo')
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
365
        tree.add('hello')
366
        tree.commit('fie')
5430.7.2 by Rory Yorke
Changes as per Martin [gz]'s review.
367
6973.7.5 by Jelmer Vernooij
s/file/open.
368
        with open('hello', 'wt') as f:
369
            f.write('fee')
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
370
        tree.commit('fee')
371
7143.15.2 by Jelmer Vernooij
Run autopep8.
372
        # tree.update() gives no such revision, so ...
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
373
        self.run_bzr(['update', '-r1'])
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
374
7143.15.2 by Jelmer Vernooij
Run autopep8.
375
        # create conflict
6973.7.5 by Jelmer Vernooij
s/file/open.
376
        with open('hello', 'wt') as f:
377
            f.write('fie')
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
378
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
379
        out, err = self.run_bzr(['update', '--show-base'], retcode=1)
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
380
381
        # check for conflict notification
382
        self.assertContainsString(err,
7045.4.8 by Jelmer Vernooij
Fix another 128 tests on python 3.
383
                                  ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
384
        with open('hello', 'rb') as f:
385
            self.assertEqualDiff(b'<<<<<<< TREE\n'
386
                                 b'fie||||||| BASE-REVISION\n'
387
                                 b'foo=======\n'
388
                                 b'fee>>>>>>> MERGE-SOURCE\n',
389
                                 f.read())
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
390
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)?
391
    def test_update_checkout_prevent_double_merge(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
392
        """"Launchpad bug 113809 in brz "update performs two merges"
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)?
393
        https://launchpad.net/bugs/113809"""
4985.3.1 by Gerard Krol
Werkt wel ok
394
        master = self.make_branch_and_tree('master')
6855.4.1 by Jelmer Vernooij
Yet more bees.
395
        self.build_tree_contents([('master/file', b'initial contents\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
396
        master.add(['file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
397
        master.commit('one', rev_id=b'm1')
4985.3.1 by Gerard Krol
Werkt wel ok
398
399
        checkout = master.branch.create_checkout('checkout')
4985.3.10 by Gerard Krol
Reformat long lines
400
        lightweight = checkout.branch.create_checkout('lightweight',
401
                                                      lightweight=True)
4985.3.17 by Vincent Ladeuil
Some cleanup.
402
4985.3.1 by Gerard Krol
Werkt wel ok
403
        # time to create a mess
404
        # add a commit to the master
6855.4.1 by Jelmer Vernooij
Yet more bees.
405
        self.build_tree_contents([('master/file', b'master\n')])
406
        master.commit('two', rev_id=b'm2')
407
        self.build_tree_contents([('master/file', b'master local changes\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
408
409
        # local commit on the checkout
6855.4.1 by Jelmer Vernooij
Yet more bees.
410
        self.build_tree_contents([('checkout/file', b'checkout\n')])
411
        checkout.commit('tree', rev_id=b'c2', local=True)
4985.3.17 by Vincent Ladeuil
Some cleanup.
412
        self.build_tree_contents([('checkout/file',
6855.4.1 by Jelmer Vernooij
Yet more bees.
413
                                   b'checkout local changes\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
414
7143.15.2 by Jelmer Vernooij
Run autopep8.
415
        # lightweight
4985.3.10 by Gerard Krol
Reformat long lines
416
        self.build_tree_contents([('lightweight/file',
6855.4.1 by Jelmer Vernooij
Yet more bees.
417
                                   b'lightweight local changes\n')])
4985.3.1 by Gerard Krol
Werkt wel ok
418
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)?
419
        # now update (and get conflicts)
4985.3.1 by Gerard Krol
Werkt wel ok
420
        out, err = self.run_bzr('update lightweight', retcode=1)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
421
        self.assertEqual('', out)
5053.1.1 by Martin Pool
Merge 2.1 back to trunk
422
        # NB: these conflicts are actually in the source code
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
423
        self.assertFileEqual('''\
4985.3.17 by Vincent Ladeuil
Some cleanup.
424
<<<<<<< TREE
425
lightweight local changes
426
=======
427
checkout
428
>>>>>>> MERGE-SOURCE
429
''',
4985.3.10 by Gerard Krol
Reformat long lines
430
                             'lightweight/file')
4985.3.17 by Vincent Ladeuil
Some cleanup.
431
4985.3.1 by Gerard Krol
Werkt wel ok
432
        # resolve it
4985.3.10 by Gerard Krol
Reformat long lines
433
        self.build_tree_contents([('lightweight/file',
6855.4.1 by Jelmer Vernooij
Yet more bees.
434
                                   b'lightweight+checkout\n')])
4985.3.17 by Vincent Ladeuil
Some cleanup.
435
        self.run_bzr('resolve lightweight/file')
4985.3.1 by Gerard Krol
Werkt wel ok
436
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)?
437
        # check we get the second conflict
4985.3.1 by Gerard Krol
Werkt wel ok
438
        out, err = self.run_bzr('update lightweight', retcode=1)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
439
        self.assertEqual('', out)
5053.1.1 by Martin Pool
Merge 2.1 back to trunk
440
        # NB: these conflicts are actually in the source code
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
441
        self.assertFileEqual('''\
4985.3.17 by Vincent Ladeuil
Some cleanup.
442
<<<<<<< TREE
443
lightweight+checkout
444
=======
445
master
446
>>>>>>> MERGE-SOURCE
447
''',
4985.3.10 by Gerard Krol
Reformat long lines
448
                             'lightweight/file')
6178.1.1 by Martin Pool
'bzr update' makes it clear it will only upgrade the whole tree
449
450
    def test_no_upgrade_single_file(self):
451
        """There's one basis revision per tree.
452
453
        Since you can't actually change the basis for a single file at the
454
        moment, we don't let you think you can.
455
456
        See bug 557886.
457
        """
458
        self.make_branch_and_tree('.')
459
        self.build_tree_contents([('a/',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
460
                                  ('a/file', b'content')])
6178.1.1 by Martin Pool
'bzr update' makes it clear it will only upgrade the whole tree
461
        sr = ScriptRunner()
462
        sr.run_script(self, '''
6622.1.29 by Jelmer Vernooij
Fix some more tests.
463
            $ brz update ./a
464
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
465
            $ brz update ./a/file
466
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
467
            $ brz update .
6178.1.1 by Martin Pool
'bzr update' makes it clear it will only upgrade the whole tree
468
            2>Tree is up to date at revision 0 of branch ...
6178.1.3 by Martin Pool
'update' with no arguments from a tree subdirectory now works and is tested (thanks vila)
469
            $ cd a
6622.1.29 by Jelmer Vernooij
Fix some more tests.
470
            $ brz update .
471
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
6178.1.3 by Martin Pool
'update' with no arguments from a tree subdirectory now works and is tested (thanks vila)
472
            # however, you can update the whole tree from a subdirectory
6622.1.29 by Jelmer Vernooij
Fix some more tests.
473
            $ brz update
6178.1.3 by Martin Pool
'update' with no arguments from a tree subdirectory now works and is tested (thanks vila)
474
            2>Tree is up to date at revision 0 of branch ...
6178.1.1 by Martin Pool
'bzr update' makes it clear it will only upgrade the whole tree
475
            ''')