/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 bzrlib/tests/blackbox/test_pull.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
import sys
22
22
 
23
23
from bzrlib import (
 
24
    branch,
24
25
    debug,
25
26
    remote,
 
27
    tests,
26
28
    urlutils,
27
29
    )
28
30
 
29
31
from bzrlib.branch import Branch
30
32
from bzrlib.directory_service import directories
31
33
from bzrlib.osutils import pathjoin
32
 
from bzrlib.tests.blackbox import ExternalBase
 
34
from bzrlib.tests import (
 
35
    fixtures,
 
36
    script,
 
37
    )
33
38
from bzrlib.uncommit import uncommit
34
39
from bzrlib.workingtree import WorkingTree
35
40
 
36
41
 
37
 
class TestPull(ExternalBase):
 
42
class TestPull(tests.TestCaseWithTransport):
38
43
 
39
44
    def example_branch(self, path='.'):
40
45
        tree = self.make_branch_and_tree(path)
50
55
    def test_pull(self):
51
56
        """Pull changes from one branch to another."""
52
57
        a_tree = self.example_branch('a')
 
58
        base_rev = a_tree.branch.last_revision()
53
59
        os.chdir('a')
54
60
        self.run_bzr('pull', retcode=3)
55
61
        self.run_bzr('missing', retcode=3)
68
74
        self.run_bzr('pull')
69
75
        os.mkdir('subdir')
70
76
        b_tree.add('subdir')
71
 
        b_tree.commit(message='blah', allow_pointless=True)
 
77
        new_rev = b_tree.commit(message='blah', allow_pointless=True)
72
78
 
73
79
        os.chdir('..')
74
80
        a = Branch.open('a')
75
81
        b = Branch.open('b')
76
 
        self.assertEqual(a.revision_history(), b.revision_history()[:-1])
 
82
        self.assertEqual(a.last_revision(), base_rev)
 
83
        self.assertEqual(b.last_revision(), new_rev)
77
84
 
78
85
        os.chdir('a')
79
86
        self.run_bzr('pull ../b')
80
 
        self.assertEqual(a.revision_history(), b.revision_history())
 
87
        self.assertEqual(a.last_revision(), b.last_revision())
81
88
        a_tree.commit(message='blah2', allow_pointless=True)
82
89
        b_tree.commit(message='blah3', allow_pointless=True)
83
90
        # no overwrite
88
95
        os.chdir('overwriteme')
89
96
        self.run_bzr('pull --overwrite ../a')
90
97
        overwritten = Branch.open('.')
91
 
        self.assertEqual(overwritten.revision_history(),
92
 
                         a.revision_history())
 
98
        self.assertEqual(overwritten.last_revision(),
 
99
                         a.last_revision())
93
100
        a_tree.merge_from_branch(b_tree.branch)
94
101
        a_tree.commit(message="blah4", allow_pointless=True)
95
102
        os.chdir('../b/subdir')
96
103
        self.run_bzr('pull ../../a')
97
 
        self.assertEqual(a.revision_history()[-1], b.revision_history()[-1])
 
104
        self.assertEqual(a.last_revision(), b.last_revision())
98
105
        sub_tree = WorkingTree.open_containing('.')[0]
99
106
        sub_tree.commit(message="blah5", allow_pointless=True)
100
107
        sub_tree.commit(message="blah6", allow_pointless=True)
140
147
        self.run_bzr('pull -r 3')
141
148
        self.assertEqual(b.revno(),3)
142
149
        self.run_bzr('pull -r 4')
143
 
        self.assertEqual(a.revision_history(), b.revision_history())
 
150
        self.assertEqual(a.last_revision(), b.last_revision())
144
151
 
 
152
    def test_pull_tags(self):
 
153
        """Tags are updated by pull, and revisions named in those tags are
 
154
        fetched.
 
155
        """
 
156
        # Make a source, sprout a target off it
 
157
        builder = self.make_branch_builder('source')
 
158
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
159
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
160
        target_bzrdir = source.bzrdir.sprout('target')
 
161
        source.tags.set_tag('tag-a', 'rev-2')
 
162
        # Pull from source
 
163
        self.run_bzr('pull -d target source')
 
164
        target = target_bzrdir.open_branch()
 
165
        # The tag is present, and so is its revision.
 
166
        self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
 
167
        target.repository.get_revision('rev-2')
145
168
 
146
169
    def test_overwrite_uptodate(self):
147
170
        # Make sure pull --overwrite overwrites
160
183
        self.build_tree_contents([('a/foo', 'a third change')])
161
184
        a_tree.commit(message='a third change')
162
185
 
163
 
        rev_history_a = a_tree.branch.revision_history()
164
 
        self.assertEqual(len(rev_history_a), 3)
 
186
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
165
187
 
166
188
        b_tree.merge_from_branch(a_tree.branch)
167
189
        b_tree.commit(message='merge')
168
190
 
169
 
        self.assertEqual(len(b_tree.branch.revision_history()), 2)
 
191
        self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
170
192
 
171
193
        os.chdir('b')
172
194
        self.run_bzr('pull --overwrite ../a')
173
 
        rev_history_b = b_tree.branch.revision_history()
174
 
        self.assertEqual(len(rev_history_b), 3)
175
 
 
176
 
        self.assertEqual(rev_history_b, rev_history_a)
 
195
        (last_revinfo_b) = b_tree.branch.last_revision_info()
 
196
        self.assertEqual(last_revinfo_b[0], 3)
 
197
        self.assertEqual(last_revinfo_b[1], a_tree.branch.last_revision())
177
198
 
178
199
    def test_overwrite_children(self):
179
200
        # Make sure pull --overwrite sets the revision-history
191
212
        self.build_tree_contents([('a/foo', 'a third change')])
192
213
        a_tree.commit(message='a third change')
193
214
 
194
 
        self.assertEqual(len(a_tree.branch.revision_history()), 3)
 
215
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
195
216
 
196
217
        b_tree.merge_from_branch(a_tree.branch)
197
218
        b_tree.commit(message='merge')
198
219
 
199
 
        self.assertEqual(len(b_tree.branch.revision_history()), 2)
 
220
        self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
200
221
 
201
222
        self.build_tree_contents([('a/foo', 'a fourth change\n')])
202
223
        a_tree.commit(message='a fourth change')
203
224
 
204
 
        rev_history_a = a_tree.branch.revision_history()
205
 
        self.assertEqual(len(rev_history_a), 4)
 
225
        rev_info_a = a_tree.branch.last_revision_info()
 
226
        self.assertEqual(rev_info_a[0], 4)
206
227
 
207
228
        # With convergence, we could just pull over the
208
229
        # new change, but with --overwrite, we want to switch our history
209
230
        os.chdir('b')
210
231
        self.run_bzr('pull --overwrite ../a')
211
 
        rev_history_b = b_tree.branch.revision_history()
212
 
        self.assertEqual(len(rev_history_b), 4)
213
 
 
214
 
        self.assertEqual(rev_history_b, rev_history_a)
 
232
        rev_info_b = b_tree.branch.last_revision_info()
 
233
        self.assertEqual(rev_info_b[0], 4)
 
234
        self.assertEqual(rev_info_b, rev_info_a)
215
235
 
216
236
    def test_pull_remember(self):
217
237
        """Pull changes from one branch to another and test parent location."""
230
250
        tree_a.commit('commit b')
231
251
        # reset parent
232
252
        parent = branch_b.get_parent()
 
253
        branch_b = branch.Branch.open('branch_b')
 
254
        branch_b.lock_write()
233
255
        branch_b.set_parent(None)
 
256
        branch_b.unlock()
234
257
        self.assertEqual(None, branch_b.get_parent())
235
258
        # test pull for failure without parent set
236
 
        os.chdir('branch_b')
237
 
        out = self.run_bzr('pull', retcode=3)
 
259
        out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
238
260
        self.assertEqual(out,
239
261
                ('','bzr: ERROR: No pull location known or specified.\n'))
240
262
        # test implicit --remember when no parent set, this pull conflicts
241
 
        self.build_tree(['d'])
 
263
        self.build_tree(['branch_b/d'])
242
264
        tree_b.add('d')
243
265
        tree_b.commit('commit d')
244
 
        out = self.run_bzr('pull ../branch_a', retcode=3)
 
266
        out = self.run_bzr('pull ../branch_a', retcode=3,
 
267
                           working_dir='branch_b')
245
268
        self.assertEqual(out,
246
269
                ('','bzr: ERROR: These branches have diverged.'
247
270
                    ' Use the missing command to see how.\n'
248
271
                    'Use the merge command to reconcile them.\n'))
249
 
        self.assertEqual(branch_b.get_parent(), parent)
 
272
        branch_b = branch.Branch.open('branch_b')
 
273
        self.assertEqual(parent, branch_b.get_parent())
250
274
        # test implicit --remember after resolving previous failure
251
 
        uncommit(branch=branch_b, tree=tree_b)
 
275
        uncommit(branch=tree_b.branch, tree=tree_b)
252
276
        transport.delete('branch_b/d')
253
 
        self.run_bzr('pull')
 
277
        self.run_bzr('pull', working_dir='branch_b')
 
278
        branch_b = branch.Branch.open('branch_b')
254
279
        self.assertEqual(branch_b.get_parent(), parent)
255
280
        # test explicit --remember
256
 
        self.run_bzr('pull ../branch_c --remember')
257
 
        self.assertEqual(branch_b.get_parent(),
258
 
                          branch_c.bzrdir.root_transport.base)
 
281
        self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
 
282
        branch_b = branch.Branch.open('branch_b')
 
283
        self.assertEqual(branch_c.bzrdir.root_transport.base,
 
284
                         branch_b.get_parent())
259
285
 
260
286
    def test_pull_bundle(self):
261
287
        from bzrlib.testament import Testament
286
312
        self.assertEqual(err,
287
313
                ' M  a\nAll changes applied successfully.\n')
288
314
 
289
 
        self.assertEqualDiff(tree_a.branch.revision_history(),
290
 
                             tree_b.branch.revision_history())
 
315
        self.assertEqualDiff(tree_a.branch.last_revision(),
 
316
                             tree_b.branch.last_revision())
291
317
 
292
318
        testament_a = Testament.from_revision(tree_a.branch.repository,
293
319
                                              tree_a.get_parent_ids()[0])
299
325
        # it is legal to attempt to pull an already-merged bundle
300
326
        out, err = self.run_bzr('pull ../bundle')
301
327
        self.assertEqual(err, '')
302
 
        self.assertEqual(out, 'No revisions to pull.\n')
 
328
        self.assertEqual(out, 'No revisions or tags to pull.\n')
303
329
 
304
330
    def test_pull_verbose_no_files(self):
305
331
        """Pull --verbose should not list modified files"""
365
391
        self.assertNotContainsRe(
366
392
            out, r'revno: 1\ncommitter: .*\nbranch nick: source')
367
393
 
 
394
    def test_pull_smart_bound_branch(self):
 
395
        self.setup_smart_server_with_call_log()
 
396
        parent = self.make_branch_and_tree('parent')
 
397
        parent.commit(message='first commit')
 
398
        child = parent.bzrdir.sprout('child').open_workingtree()
 
399
        child.commit(message='second commit')
 
400
        checkout = parent.branch.create_checkout('checkout')
 
401
        self.run_bzr(['pull', self.get_url('child')], working_dir='checkout')
 
402
 
368
403
    def test_pull_smart_stacked_streaming_acceptance(self):
369
404
        """'bzr pull -r 123' works on stacked, smart branches, even when the
370
405
        revision specified by the revno is only present in the fallback
392
427
        # being too low. If rpc_count increases, more network roundtrips have
393
428
        # become necessary for this use case. Please do not adjust this number
394
429
        # upwards without agreement from bzr's network support maintainers.
395
 
        self.assertLength(18, self.hpss_calls)
 
430
        self.assertLength(19, self.hpss_calls)
396
431
        remote = Branch.open('stacked')
397
432
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
398
 
    
 
433
 
399
434
    def test_pull_cross_format_warning(self):
400
435
        """You get a warning for probably slow cross-format pulls.
401
436
        """
453
488
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
454
489
        self.assertContainsRe(err,
455
490
            "(?m)Fetching into experimental format")
 
491
 
 
492
    def test_pull_show_base(self):
 
493
        """bzr pull supports --show-base
 
494
 
 
495
        see https://bugs.launchpad.net/bzr/+bug/202374"""
 
496
        # create two trees with conflicts, setup conflict, check that
 
497
        # conflicted file looks correct
 
498
        a_tree = self.example_branch('a')
 
499
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
500
 
 
501
        f = open(pathjoin('a', 'hello'),'wt')
 
502
        f.write('fee')
 
503
        f.close()
 
504
        a_tree.commit('fee')
 
505
 
 
506
        f = open(pathjoin('b', 'hello'),'wt')
 
507
        f.write('fie')
 
508
        f.close()
 
509
 
 
510
        out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
 
511
 
 
512
        # check for message here
 
513
        self.assertEqual(err,
 
514
                         ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
 
515
 
 
516
        self.assertEqualDiff('<<<<<<< TREE\n'
 
517
                             'fie||||||| BASE-REVISION\n'
 
518
                             'foo=======\n'
 
519
                             'fee>>>>>>> MERGE-SOURCE\n',
 
520
                             open(pathjoin('b', 'hello')).read())
 
521
 
 
522
    def test_pull_show_base_working_tree_only(self):
 
523
        """--show-base only allowed if there's a working tree
 
524
 
 
525
        see https://bugs.launchpad.net/bzr/+bug/202374"""
 
526
        # create a branch, see that --show-base fails
 
527
        self.make_branch('from')
 
528
        self.make_branch('to')
 
529
        out=self.run_bzr(['pull','-d','to','from','--show-base'],retcode=3)
 
530
        self.assertEqual(out,
 
531
                         ('','bzr: ERROR: Need working tree for --show-base.\n'))
 
532
 
 
533
    def test_pull_tag_conflicts(self):
 
534
        """pulling tags with conflicts will change the exit code"""
 
535
        # create a branch, see that --show-base fails
 
536
        from_tree = self.make_branch_and_tree('from')
 
537
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
538
        to_tree = self.make_branch_and_tree('to')
 
539
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
 
540
        out = self.run_bzr(['pull','-d','to','from'],retcode=1)
 
541
        self.assertEqual(out,
 
542
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
 
543
 
 
544
    def test_pull_tag_notification(self):
 
545
        """pulling tags with conflicts will change the exit code"""
 
546
        # create a branch, see that --show-base fails
 
547
        from_tree = self.make_branch_and_tree('from')
 
548
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
549
        to_tree = self.make_branch_and_tree('to')
 
550
        out = self.run_bzr(['pull', '-d', 'to', 'from'])
 
551
        self.assertEqual(out,
 
552
            ('1 tag(s) updated.\n', ''))
 
553
 
 
554
    def test_pull_tag_overwrite(self):
 
555
        """pulling tags with --overwrite only reports changed tags."""
 
556
        # create a branch, see that --show-base fails
 
557
        from_tree = self.make_branch_and_tree('from')
 
558
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
559
        to_tree = self.make_branch_and_tree('to')
 
560
        to_tree.branch.tags.set_tag("mytag", "somerevid")
 
561
        out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
 
562
        self.assertEqual(out,
 
563
            ('No revisions or tags to pull.\n', ''))
 
564
 
 
565
 
 
566
class TestPullOutput(script.TestCaseWithTransportAndScript):
 
567
 
 
568
    def test_pull_log_format(self):
 
569
        self.run_script("""
 
570
            $ bzr init trunk
 
571
            Created a standalone tree (format: 2a)
 
572
            $ cd trunk
 
573
            $ echo foo > file
 
574
            $ bzr add
 
575
            adding file
 
576
            $ bzr commit -m 'we need some foo'
 
577
            2>Committing to:...trunk/
 
578
            2>added file
 
579
            2>Committed revision 1.
 
580
            $ cd ..
 
581
            $ bzr init feature
 
582
            Created a standalone tree (format: 2a)
 
583
            $ cd feature
 
584
            $ bzr pull -v ../trunk -Olog_format=line
 
585
            Now on revision 1.
 
586
            Added Revisions:
 
587
            1: jrandom@example.com ...we need some foo
 
588
            2>+N  file
 
589
            2>All changes applied successfully.
 
590
            """)