/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_update.py

  • Committer: Robert Collins
  • Date: 2005-10-19 10:11:57 UTC
  • mfrom: (1185.16.78)
  • mto: This revision was merged to the branch mainline in revision 1470.
  • Revision ID: robertc@robertcollins.net-20051019101157-17438d311e746b4f
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
 
#
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.
7
 
#
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.
12
 
#
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
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
 
18
 
"""Tests for the update command of bzr."""
19
 
 
20
 
import os
21
 
 
22
 
from breezy import (
23
 
    branch,
24
 
    osutils,
25
 
    tests,
26
 
    workingtree,
27
 
    )
28
 
from breezy.bzr import (
29
 
    bzrdir,
30
 
    )
31
 
from breezy.tests.script import ScriptRunner
32
 
 
33
 
 
34
 
class TestUpdate(tests.TestCaseWithTransport):
35
 
 
36
 
    def test_update_standalone_trivial(self):
37
 
        self.make_branch_and_tree('.')
38
 
        out, err = self.run_bzr('update')
39
 
        self.assertEqual(
40
 
            'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
41
 
            err)
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)
48
 
        self.assertEqual('', out)
49
 
 
50
 
    def test_update_standalone_trivial_with_alias_up(self):
51
 
        self.make_branch_and_tree('.')
52
 
        out, err = self.run_bzr('up')
53
 
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
54
 
                         % self.test_dir,
55
 
                         err)
56
 
        self.assertEqual('', out)
57
 
 
58
 
    def test_update_up_to_date_light_checkout(self):
59
 
        self.make_branch_and_tree('branch')
60
 
        self.run_bzr('checkout --lightweight branch checkout')
61
 
        out, err = self.run_bzr('update checkout')
62
 
        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
63
 
                         % osutils.pathjoin(self.test_dir, 'branch'),
64
 
                         err)
65
 
        self.assertEqual('', out)
66
 
 
67
 
    def test_update_up_to_date_checkout(self):
68
 
        self.make_branch_and_tree('branch')
69
 
        self.run_bzr('checkout branch checkout')
70
 
        sr = ScriptRunner()
71
 
        sr.run_script(self, '''
72
 
$ brz update checkout
73
 
2>Tree is up to date at revision 0 of branch .../branch
74
 
''')
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
81
 
        self.run_bzr('checkout --lightweight branch checkout')
82
 
        self.build_tree(['checkout/file'])
83
 
        self.run_bzr('add checkout/file')
84
 
        self.run_bzr('commit -m add-file checkout')
85
 
        # now branch should be out of date
86
 
        out, err = self.run_bzr('update branch')
87
 
        self.assertEqual('', out)
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)
93
 
        self.assertPathExists('branch/file')
94
 
 
95
 
    def test_update_out_of_date_light_checkout(self):
96
 
        self.make_branch_and_tree('branch')
97
 
        # make two checkouts
98
 
        self.run_bzr('checkout --lightweight branch checkout')
99
 
        self.run_bzr('checkout --lightweight branch checkout2')
100
 
        self.build_tree(['checkout/file'])
101
 
        self.run_bzr('add checkout/file')
102
 
        self.run_bzr('commit -m add-file checkout')
103
 
        # now checkout2 should be out of date
104
 
        out, err = self.run_bzr('update checkout2')
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)
110
 
        self.assertEqual('', out)
111
 
 
112
 
    def test_update_conflicts_returns_2(self):
113
 
        self.make_branch_and_tree('branch')
114
 
        # make two checkouts
115
 
        self.run_bzr('checkout --lightweight branch checkout')
116
 
        self.build_tree(['checkout/file'])
117
 
        self.run_bzr('add checkout/file')
118
 
        self.run_bzr('commit -m add-file checkout')
119
 
        self.run_bzr('checkout --lightweight branch checkout2')
120
 
        # now alter file in checkout
121
 
        with open('checkout/file', 'wt') as a_file:
122
 
            a_file.write('Foo')
123
 
        self.run_bzr('commit -m checnge-file checkout')
124
 
        # now checkout2 should be out of date
125
 
        # make a local change to file
126
 
        with open('checkout2/file', 'wt') as a_file:
127
 
            a_file.write('Bar')
128
 
        out, err = self.run_bzr('update checkout2', retcode=1)
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)
135
 
        self.assertEqual('', out)
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.
140
 
        master = self.make_branch_and_tree('master')
141
 
        master.commit('first commit')
142
 
        # make a bound branch
143
 
        self.run_bzr('checkout master child')
144
 
        # check that out
145
 
        self.run_bzr('checkout --lightweight child checkout')
146
 
        # get an object form of the checkout to manipulate
147
 
        wt = workingtree.WorkingTree.open('checkout')
148
 
        # change master
149
 
        with open('master/file', 'wt') as a_file:
150
 
            a_file.write('Foo')
151
 
        master.add(['file'])
152
 
        master_tip = master.commit('add file')
153
 
        # change child
154
 
        with open('child/file_b', 'wt') as a_file:
155
 
            a_file.write('Foo')
156
 
        # get an object form of child
157
 
        child = workingtree.WorkingTree.open('child')
158
 
        child.add(['file_b'])
159
 
        child_tip = child.commit('add file_b', local=True)
160
 
        # check checkout
161
 
        with open('checkout/file_c', 'wt') as a_file:
162
 
            a_file.write('Foo')
163
 
        wt.add(['file_c'])
164
 
 
165
 
        # now, update checkout ->
166
 
        # get all three files and a pending merge.
167
 
        out, err = self.run_bzr('update checkout')
168
 
        self.assertEqual('', out)
169
 
        self.assertEqualDiff("""+N  file_b
170
 
All changes applied successfully.
171
 
+N  file
172
 
All changes applied successfully.
173
 
Updated to revision 2 of branch %s
174
 
Your local commits will now show as pending merges with 'brz status', and can be committed with 'brz commit'.
175
 
""" % osutils.pathjoin(self.test_dir, 'master',),
176
 
            err)
177
 
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
178
 
        self.assertPathExists('checkout/file')
179
 
        self.assertPathExists('checkout/file_b')
180
 
        self.assertPathExists('checkout/file_c')
181
 
        self.assertTrue(wt.has_filename('file_c'))
182
 
 
183
 
    def test_update_with_merges(self):
184
 
        # Test that 'brz update' works correctly when you have
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'])
190
 
        master.commit('one', rev_id=b'm1')
191
 
 
192
 
        self.build_tree(['checkout1/'])
193
 
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
194
 
        checkout_dir.set_branch_reference(master.branch)
195
 
        checkout1 = checkout_dir.create_workingtree(b'm1')
196
 
 
197
 
        # Create a second branch, with an extra commit
198
 
        other = master.controldir.sprout('other').open_workingtree()
199
 
        self.build_tree(['other/file2'])
200
 
        other.add(['file2'])
201
 
        other.commit('other2', rev_id=b'o2')
202
 
 
203
 
        # Create a new commit in the master branch
204
 
        self.build_tree(['master/file3'])
205
 
        master.add(['file3'])
206
 
        master.commit('f3', rev_id=b'm2')
207
 
 
208
 
        # Merge the other branch into checkout
209
 
        os.chdir('checkout1')
210
 
        self.run_bzr('merge ../other')
211
 
 
212
 
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
213
 
 
214
 
        # At this point, 'commit' should fail, because we are out of date
215
 
        self.run_bzr_error(["please run 'brz update'"],
216
 
                           'commit -m merged')
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')
221
 
        self.assertEqual('', out)
222
 
        self.assertEqualDiff('''+N  file3
223
 
All changes applied successfully.
224
 
Updated to revision 2 of branch %s
225
 
''' % osutils.pathjoin(self.test_dir, 'master',),
226
 
            err)
227
 
        # The pending merges should still be there
228
 
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
229
 
 
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'))
234
 
        checkout = readonly_branch.create_checkout('checkout',
235
 
                                                   lightweight=True)
236
 
        tree.commit('empty commit')
237
 
        self.run_bzr('update checkout')
238
 
 
239
 
    def test_update_with_merge_merged_to_master(self):
240
 
        # Test that 'brz update' works correctly when you have
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'])
246
 
        master.commit('one', rev_id=b'm1')
247
 
 
248
 
        self.build_tree(['checkout1/'])
249
 
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
250
 
        checkout_dir.set_branch_reference(master.branch)
251
 
        checkout1 = checkout_dir.create_workingtree(b'm1')
252
 
 
253
 
        # Create a second branch, with an extra commit
254
 
        other = master.controldir.sprout('other').open_workingtree()
255
 
        self.build_tree(['other/file2'])
256
 
        other.add(['file2'])
257
 
        other.commit('other2', rev_id=b'o2')
258
 
 
259
 
        # Merge the other branch into checkout -  'start reviewing a patch'
260
 
        checkout1.merge_from_branch(other.branch)
261
 
        self.assertEqual([b'o2'], checkout1.get_parent_ids()[1:])
262
 
 
263
 
        # Create a new commit in the master branch - 'someone else lands its'
264
 
        master.merge_from_branch(other.branch)
265
 
        master.commit('f3', rev_id=b'm2')
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')
271
 
        self.assertEqual('', out)
272
 
        self.assertEqualDiff('''All changes applied successfully.
273
 
Updated to revision 2 of branch %s
274
 
''' % osutils.pathjoin(self.test_dir, 'master',),
275
 
            err)
276
 
        # The pending merges should still be there
277
 
        self.assertEqual([], checkout1.get_parent_ids()[1:])
278
 
 
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'])
284
 
        master.commit('one', rev_id=b'm1')
285
 
        self.build_tree(['./file2'])
286
 
        master.add(['file2'])
287
 
        master.commit('two', rev_id=b'm2')
288
 
 
289
 
        sr = ScriptRunner()
290
 
        sr.run_script(self, '''
291
 
$ brz update -r 1
292
 
2>-D  file2
293
 
2>All changes applied successfully.
294
 
2>Updated to revision 1 of .../master
295
 
''')
296
 
        self.assertPathExists('./file1')
297
 
        self.assertPathDoesNotExist('./file2')
298
 
        self.assertEqual([b'm1'], master.get_parent_ids())
299
 
 
300
 
    def test_update_dash_r_outside_history(self):
301
 
        """Ensure that we can update -r to dotted revisions.
302
 
        """
303
 
        master = self.make_branch_and_tree('master')
304
 
        self.build_tree(['master/file1'])
305
 
        master.add(['file1'])
306
 
        master.commit('one', rev_id=b'm1')
307
 
 
308
 
        # Create a second branch, with extra commits
309
 
        other = master.controldir.sprout('other').open_workingtree()
310
 
        self.build_tree(['other/file2', 'other/file3'])
311
 
        other.add(['file2'])
312
 
        other.commit('other2', rev_id=b'o2')
313
 
        other.add(['file3'])
314
 
        other.commit('other3', rev_id=b'o3')
315
 
 
316
 
        os.chdir('master')
317
 
        self.run_bzr('merge ../other')
318
 
        master.commit('merge', rev_id=b'merge')
319
 
 
320
 
        # Switch to o2. file3 was added only in o3 and should be deleted.
321
 
        out, err = self.run_bzr('update -r revid:o2')
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 .*')
325
 
 
326
 
        # Switch back to latest
327
 
        out, err = self.run_bzr('update')
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 .*')
331
 
 
332
 
    def test_update_dash_r_in_master(self):
333
 
        # Test that 'brz update' works correctly when you have
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'])
338
 
        master.commit('one', rev_id=b'm1')
339
 
 
340
 
        self.run_bzr('checkout master checkout')
341
 
 
342
 
        # add a revision in the master.
343
 
        self.build_tree(['master/file2'])
344
 
        master.add(['file2'])
345
 
        master.commit('two', rev_id=b'm2')
346
 
 
347
 
        os.chdir('checkout')
348
 
        sr = ScriptRunner()
349
 
        sr.run_script(self, '''
350
 
$ brz update -r revid:m2
351
 
2>+N  file2
352
 
2>All changes applied successfully.
353
 
2>Updated to revision 2 of branch .../master
354
 
''')
355
 
 
356
 
    def test_update_show_base(self):
357
 
        """brz update support --show-base
358
 
 
359
 
        see https://bugs.launchpad.net/bzr/+bug/202374"""
360
 
 
361
 
        tree = self.make_branch_and_tree('.')
362
 
 
363
 
        with open('hello', 'wt') as f:
364
 
            f.write('foo')
365
 
        tree.add('hello')
366
 
        tree.commit('fie')
367
 
 
368
 
        with open('hello', 'wt') as f:
369
 
            f.write('fee')
370
 
        tree.commit('fee')
371
 
 
372
 
        # tree.update() gives no such revision, so ...
373
 
        self.run_bzr(['update', '-r1'])
374
 
 
375
 
        # create conflict
376
 
        with open('hello', 'wt') as f:
377
 
            f.write('fie')
378
 
 
379
 
        out, err = self.run_bzr(['update', '--show-base'], retcode=1)
380
 
 
381
 
        # check for conflict notification
382
 
        self.assertContainsString(err,
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())
390
 
 
391
 
    def test_update_checkout_prevent_double_merge(self):
392
 
        """"Launchpad bug 113809 in brz "update performs two merges"
393
 
        https://launchpad.net/bugs/113809"""
394
 
        master = self.make_branch_and_tree('master')
395
 
        self.build_tree_contents([('master/file', b'initial contents\n')])
396
 
        master.add(['file'])
397
 
        master.commit('one', rev_id=b'm1')
398
 
 
399
 
        checkout = master.branch.create_checkout('checkout')
400
 
        lightweight = checkout.branch.create_checkout('lightweight',
401
 
                                                      lightweight=True)
402
 
 
403
 
        # time to create a mess
404
 
        # add a commit to the master
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')])
408
 
 
409
 
        # local commit on the checkout
410
 
        self.build_tree_contents([('checkout/file', b'checkout\n')])
411
 
        checkout.commit('tree', rev_id=b'c2', local=True)
412
 
        self.build_tree_contents([('checkout/file',
413
 
                                   b'checkout local changes\n')])
414
 
 
415
 
        # lightweight
416
 
        self.build_tree_contents([('lightweight/file',
417
 
                                   b'lightweight local changes\n')])
418
 
 
419
 
        # now update (and get conflicts)
420
 
        out, err = self.run_bzr('update lightweight', retcode=1)
421
 
        self.assertEqual('', out)
422
 
        # NB: these conflicts are actually in the source code
423
 
        self.assertFileEqual('''\
424
 
<<<<<<< TREE
425
 
lightweight local changes
426
 
=======
427
 
checkout
428
 
>>>>>>> MERGE-SOURCE
429
 
''',
430
 
                             'lightweight/file')
431
 
 
432
 
        # resolve it
433
 
        self.build_tree_contents([('lightweight/file',
434
 
                                   b'lightweight+checkout\n')])
435
 
        self.run_bzr('resolve lightweight/file')
436
 
 
437
 
        # check we get the second conflict
438
 
        out, err = self.run_bzr('update lightweight', retcode=1)
439
 
        self.assertEqual('', out)
440
 
        # NB: these conflicts are actually in the source code
441
 
        self.assertFileEqual('''\
442
 
<<<<<<< TREE
443
 
lightweight+checkout
444
 
=======
445
 
master
446
 
>>>>>>> MERGE-SOURCE
447
 
''',
448
 
                             'lightweight/file')
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/',),
460
 
                                  ('a/file', b'content')])
461
 
        sr = ScriptRunner()
462
 
        sr.run_script(self, '''
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 .
468
 
            2>Tree is up to date at revision 0 of branch ...
469
 
            $ cd a
470
 
            $ brz update .
471
 
            2>brz: ERROR: brz update can only update a whole tree, not a file or subdirectory
472
 
            # however, you can update the whole tree from a subdirectory
473
 
            $ brz update
474
 
            2>Tree is up to date at revision 0 of branch ...
475
 
            ''')