/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_push.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) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-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
22
22
from bzrlib import (
23
23
    branch,
24
24
    bzrdir,
 
25
    controldir,
25
26
    errors,
26
27
    osutils,
27
28
    tests,
32
33
    )
33
34
from bzrlib.repofmt import knitrepo
34
35
from bzrlib.tests import (
35
 
    blackbox,
36
36
    http_server,
 
37
    scenarios,
 
38
    script,
37
39
    test_foreign,
38
 
    test_server,
39
40
    )
40
41
from bzrlib.transport import memory
41
42
 
42
43
 
43
 
def load_tests(standard_tests, module, loader):
44
 
    """Multiply tests for the push command."""
45
 
    result = loader.suiteClass()
46
 
 
47
 
    # one for each king of change
48
 
    changes_tests, remaining_tests = tests.split_suite_by_condition(
49
 
        standard_tests, tests.condition_isinstance((
50
 
                TestPushStrictWithChanges,
51
 
                )))
52
 
    changes_scenarios = [
53
 
        ('uncommitted',
54
 
         dict(_changes_type= '_uncommitted_changes')),
55
 
        ('pending-merges',
56
 
         dict(_changes_type= '_pending_merges')),
57
 
        ('out-of-sync-trees',
58
 
         dict(_changes_type= '_out_of_sync_trees')),
59
 
        ]
60
 
    tests.multiply_tests(changes_tests, changes_scenarios, result)
61
 
    # No parametrization for the remaining tests
62
 
    result.addTests(remaining_tests)
63
 
 
64
 
    return result
 
44
load_tests = scenarios.load_tests_apply_scenarios
65
45
 
66
46
 
67
47
class TestPush(tests.TestCaseWithTransport):
76
56
                           ['push', public_url],
77
57
                           working_dir='source')
78
58
 
 
59
    def test_push_suggests_parent_alias(self):
 
60
        """Push suggests using :parent if there is a known parent branch."""
 
61
        tree_a = self.make_branch_and_tree('a')
 
62
        tree_a.commit('this is a commit')
 
63
        tree_b = self.make_branch_and_tree('b')
 
64
 
 
65
        # If there is no parent location set, :parent isn't mentioned.
 
66
        out = self.run_bzr('push', working_dir='a', retcode=3)
 
67
        self.assertEquals(out,
 
68
                ('','bzr: ERROR: No push location known or specified.\n'))
 
69
 
 
70
        # If there is a parent location set, the error suggests :parent.
 
71
        tree_a.branch.set_parent(tree_b.branch.base)
 
72
        out = self.run_bzr('push', working_dir='a', retcode=3)
 
73
        self.assertEquals(out,
 
74
            ('','bzr: ERROR: No push location known or specified. '
 
75
                'To push to the parent branch '
 
76
                '(at %s), use \'bzr push :parent\'.\n' %
 
77
                urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
 
78
 
79
79
    def test_push_remember(self):
80
80
        """Push changes from one branch to another and test push location."""
81
81
        transport = self.get_transport()
116
116
        self.assertEquals(out,
117
117
                ('','bzr: ERROR: These branches have diverged.  '
118
118
                 'See "bzr help diverged-branches" for more information.\n'))
 
119
        branch_a = bzrdir.BzrDir.open('branch_a').open_branch()
119
120
        self.assertEquals(osutils.abspath(branch_a.get_push_location()),
120
121
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
121
122
 
123
124
        uncommit.uncommit(branch=branch_b, tree=tree_b)
124
125
        transport.delete('branch_b/c')
125
126
        out, err = self.run_bzr('push', working_dir='branch_a')
 
127
        branch_a = bzrdir.BzrDir.open('branch_a').open_branch()
126
128
        path = branch_a.get_push_location()
127
 
        self.assertEquals(out,
128
 
                          'Using saved push location: %s\n'
129
 
                          % urlutils.local_path_from_url(path))
130
129
        self.assertEqual(err,
 
130
                         'Using saved push location: %s\n'
131
131
                         'All changes applied successfully.\n'
132
 
                         'Pushed up to revision 2.\n')
 
132
                         'Pushed up to revision 2.\n'
 
133
                         % urlutils.local_path_from_url(path))
133
134
        self.assertEqual(path,
134
135
                         branch_b.bzrdir.root_transport.base)
135
136
        # test explicit --remember
136
137
        self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
 
138
        branch_a = bzrdir.BzrDir.open('branch_a').open_branch()
137
139
        self.assertEquals(branch_a.get_push_location(),
138
140
                          branch_c.bzrdir.root_transport.base)
139
141
 
146
148
        b2 = branch.Branch.open('pushed-location')
147
149
        self.assertEndsWith(b2.base, 'pushed-location/')
148
150
 
 
151
    def test_push_no_tree(self):
 
152
        # bzr push --no-tree of a branch with working trees
 
153
        b = self.make_branch_and_tree('push-from')
 
154
        self.build_tree(['push-from/file'])
 
155
        b.add('file')
 
156
        b.commit('commit 1')
 
157
        out, err = self.run_bzr('push --no-tree -d push-from push-to')
 
158
        self.assertEqual('', out)
 
159
        self.assertEqual('Created new branch.\n', err)
 
160
        self.assertPathDoesNotExist('push-to/file')
 
161
 
149
162
    def test_push_new_branch_revision_count(self):
150
163
        # bzr push of a branch with revisions to a new location
151
164
        # should print the number of revisions equal to the length of the
158
171
        self.assertEqual('', out)
159
172
        self.assertEqual('Created new branch.\n', err)
160
173
 
 
174
    def test_push_quiet(self):
 
175
        # test that using -q makes output quiet
 
176
        t = self.make_branch_and_tree('tree')
 
177
        self.build_tree(['tree/file'])
 
178
        t.add('file')
 
179
        t.commit('commit 1')
 
180
        self.run_bzr('push -d tree pushed-to')
 
181
        path = bzrdir.BzrDir.open('tree').open_branch().get_push_location()
 
182
        out, err = self.run_bzr('push', working_dir="tree")
 
183
        self.assertEqual('Using saved push location: %s\n'
 
184
                         'No new revisions or tags to push.\n' %
 
185
                         urlutils.local_path_from_url(path), err)
 
186
        out, err = self.run_bzr('push -q', working_dir="tree")
 
187
        self.assertEqual('', out)
 
188
        self.assertEqual('', err)
 
189
 
161
190
    def test_push_only_pushes_history(self):
162
191
        # Knit branches should only push the history for the current revision.
163
192
        format = bzrdir.BzrDirMetaFormat1()
167
196
 
168
197
        def make_shared_tree(path):
169
198
            shared_repo.bzrdir.root_transport.mkdir(path)
170
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
199
            controldir.ControlDir.create_branch_convenience('repo/' + path)
171
200
            return workingtree.WorkingTree.open('repo/' + path)
172
201
        tree_a = make_shared_tree('a')
173
202
        self.build_tree(['repo/a/file'])
208
237
        t.commit(allow_pointless=True,
209
238
                message='first commit')
210
239
        self.run_bzr('push -d from to-one')
211
 
        self.failUnlessExists('to-one')
 
240
        self.assertPathExists('to-one')
212
241
        self.run_bzr('push -d %s %s'
213
242
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
 
        self.failUnlessExists('to-two')
 
243
        self.assertPathExists('to-two')
 
244
 
 
245
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
 
246
        # See https://bugs.launchpad.net/bzr/+bug/465517
 
247
        target_repo = self.make_repository('target')
 
248
        source = self.make_branch_builder('source')
 
249
        source.start_series()
 
250
        source.build_snapshot('A', None, [
 
251
            ('add', ('', 'root-id', 'directory', None))])
 
252
        source.build_snapshot('B', ['A'], [])
 
253
        source.build_snapshot('C', ['A'], [])
 
254
        source.finish_series()
 
255
        self.run_bzr('push target -d source')
 
256
        self.addCleanup(target_repo.lock_read().unlock)
 
257
        # We should have pushed 'C', but not 'B', since it isn't in the
 
258
        # ancestry
 
259
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
215
260
 
216
261
    def test_push_smart_non_stacked_streaming_acceptance(self):
217
262
        self.setup_smart_server_with_call_log()
240
285
        # being too low. If rpc_count increases, more network roundtrips have
241
286
        # become necessary for this use case. Please do not adjust this number
242
287
        # upwards without agreement from bzr's network support maintainers.
243
 
        self.assertLength(14, self.hpss_calls)
 
288
        self.assertLength(15, self.hpss_calls)
244
289
        remote = branch.Branch.open('public')
245
290
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
246
291
 
317
362
                     working_dir='tree')
318
363
        new_tree = workingtree.WorkingTree.open('new/tree')
319
364
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
 
        self.failUnlessExists('new/tree/a')
 
365
        self.assertPathExists('new/tree/a')
321
366
 
322
367
    def test_push_use_existing(self):
323
368
        """'bzr push --use-existing-dir' can push into an existing dir.
338
383
        new_tree = workingtree.WorkingTree.open('target')
339
384
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
385
        # The push should have created target/a
341
 
        self.failUnlessExists('target/a')
 
386
        self.assertPathExists('target/a')
342
387
 
343
388
    def test_push_use_existing_into_empty_bzrdir(self):
344
389
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
455
500
        trunk_public = self.make_branch('public_trunk', format='1.9')
456
501
        trunk_public.pull(trunk_tree.branch)
457
502
        trunk_public_url = self.get_readonly_url('public_trunk')
458
 
        trunk_tree.branch.set_public_branch(trunk_public_url)
 
503
        br = trunk_tree.branch
 
504
        br.lock_write()
 
505
        try:
 
506
            br.set_public_branch(trunk_public_url)
 
507
        finally:
 
508
            br.unlock()
459
509
        # now we do a stacked push, which should determine the public location
460
510
        # for us.
461
511
        out, err = self.run_bzr(['push', '--stacked',
652
702
        self.tree.commit('modify file', rev_id='modified')
653
703
 
654
704
    def set_config_push_strict(self, value):
655
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
656
 
        # should do)
657
 
        conf = self.tree.branch.get_config()
658
 
        conf.set_user_option('push_strict', value)
 
705
        br = branch.Branch.open('local')
 
706
        br.lock_write()
 
707
        try:
 
708
            conf = br.get_config_stack()
 
709
            conf.set('push_strict', value)
 
710
        finally:
 
711
            br.unlock()
659
712
 
660
713
    _default_command = ['push', '../to']
661
714
    _default_wd = 'local'
718
771
        self.assertPushSucceeds([])
719
772
 
720
773
 
 
774
strict_push_change_scenarios = [
 
775
    ('uncommitted',
 
776
        dict(_changes_type= '_uncommitted_changes')),
 
777
    ('pending-merges',
 
778
        dict(_changes_type= '_pending_merges')),
 
779
    ('out-of-sync-trees',
 
780
        dict(_changes_type= '_out_of_sync_trees')),
 
781
    ]
 
782
 
 
783
 
721
784
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
785
                                TestPushStrictMixin):
723
786
 
 
787
    scenarios = strict_push_change_scenarios 
724
788
    _changes_type = None # Set by load_tests
725
789
 
726
790
    def setUp(self):
788
852
        self.assertPushSucceeds([])
789
853
 
790
854
 
791
 
class TestPushForeign(blackbox.ExternalBase):
 
855
class TestPushForeign(tests.TestCaseWithTransport):
792
856
 
793
857
    def setUp(self):
794
858
        super(TestPushForeign, self).setUp()
809
873
        self.assertEquals("", output)
810
874
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
875
            " push to dummy. You may want to use dpush instead.\n")
 
876
 
 
877
 
 
878
class TestPushOutput(script.TestCaseWithTransportAndScript):
 
879
 
 
880
    def test_push_log_format(self):
 
881
        self.run_script("""
 
882
            $ bzr init trunk
 
883
            Created a standalone tree (format: 2a)
 
884
            $ cd trunk
 
885
            $ echo foo > file
 
886
            $ bzr add
 
887
            adding file
 
888
            $ bzr commit -m 'we need some foo'
 
889
            2>Committing to:...trunk/
 
890
            2>added file
 
891
            2>Committed revision 1.
 
892
            $ bzr init ../feature
 
893
            Created a standalone tree (format: 2a)
 
894
            $ bzr push -v ../feature -Olog_format=line
 
895
            Added Revisions:
 
896
            1: jrandom@example.com ...we need some foo
 
897
            2>All changes applied successfully.
 
898
            2>Pushed up to revision 1.
 
899
            """)