~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_push.py

  • Committer: Vincent Ladeuil
  • Date: 2012-03-13 16:42:20 UTC
  • mto: This revision was merged to the branch mainline in revision 6512.
  • Revision ID: v.ladeuil+lp@free.fr-20120313164220-atkou2zprhlspmwg
Mention that a given config option cannot be safely handled via both APIs at the same time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007, 2008 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
40
    )
 
41
from bzrlib.tests.matchers import ContainsNoVfsCalls
39
42
from bzrlib.transport import memory
40
43
 
41
44
 
42
 
def load_tests(standard_tests, module, loader):
43
 
    """Multiply tests for the push command."""
44
 
    result = loader.suiteClass()
45
 
 
46
 
    # one for each king of change
47
 
    changes_tests, remaining_tests = tests.split_suite_by_condition(
48
 
        standard_tests, tests.condition_isinstance((
49
 
                TestPushStrictWithChanges,
50
 
                )))
51
 
    changes_scenarios = [
52
 
        ('uncommitted',
53
 
         dict(_changes_type= '_uncommitted_changes')),
54
 
        ('pending-merges',
55
 
         dict(_changes_type= '_pending_merges')),
56
 
        ('out-of-sync-trees',
57
 
         dict(_changes_type= '_out_of_sync_trees')),
58
 
        ]
59
 
    tests.multiply_tests(changes_tests, changes_scenarios, result)
60
 
    # No parametrization for the remaining tests
61
 
    result.addTests(remaining_tests)
62
 
 
63
 
    return result
 
45
load_tests = scenarios.load_tests_apply_scenarios
64
46
 
65
47
 
66
48
class TestPush(tests.TestCaseWithTransport):
75
57
                           ['push', public_url],
76
58
                           working_dir='source')
77
59
 
 
60
    def test_push_suggests_parent_alias(self):
 
61
        """Push suggests using :parent if there is a known parent branch."""
 
62
        tree_a = self.make_branch_and_tree('a')
 
63
        tree_a.commit('this is a commit')
 
64
        tree_b = self.make_branch_and_tree('b')
 
65
 
 
66
        # If there is no parent location set, :parent isn't mentioned.
 
67
        out = self.run_bzr('push', working_dir='a', retcode=3)
 
68
        self.assertEquals(out,
 
69
                ('','bzr: ERROR: No push location known or specified.\n'))
 
70
 
 
71
        # If there is a parent location set, the error suggests :parent.
 
72
        tree_a.branch.set_parent(tree_b.branch.base)
 
73
        out = self.run_bzr('push', working_dir='a', retcode=3)
 
74
        self.assertEquals(out,
 
75
            ('','bzr: ERROR: No push location known or specified. '
 
76
                'To push to the parent branch '
 
77
                '(at %s), use \'bzr push :parent\'.\n' %
 
78
                urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
 
79
 
78
80
    def test_push_remember(self):
79
81
        """Push changes from one branch to another and test push location."""
80
82
        transport = self.get_transport()
115
117
        self.assertEquals(out,
116
118
                ('','bzr: ERROR: These branches have diverged.  '
117
119
                 'See "bzr help diverged-branches" for more information.\n'))
 
120
        # Refresh the branch as 'push' modified it
 
121
        branch_a = branch_a.bzrdir.open_branch()
118
122
        self.assertEquals(osutils.abspath(branch_a.get_push_location()),
119
123
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
120
124
 
122
126
        uncommit.uncommit(branch=branch_b, tree=tree_b)
123
127
        transport.delete('branch_b/c')
124
128
        out, err = self.run_bzr('push', working_dir='branch_a')
 
129
        # Refresh the branch as 'push' modified it
 
130
        branch_a = branch_a.bzrdir.open_branch()
125
131
        path = branch_a.get_push_location()
126
 
        self.assertEquals(out,
127
 
                          'Using saved push location: %s\n'
128
 
                          % urlutils.local_path_from_url(path))
129
132
        self.assertEqual(err,
 
133
                         'Using saved push location: %s\n'
130
134
                         'All changes applied successfully.\n'
131
 
                         'Pushed up to revision 2.\n')
 
135
                         'Pushed up to revision 2.\n'
 
136
                         % urlutils.local_path_from_url(path))
132
137
        self.assertEqual(path,
133
138
                         branch_b.bzrdir.root_transport.base)
134
139
        # test explicit --remember
135
140
        self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
 
141
        # Refresh the branch as 'push' modified it
 
142
        branch_a = branch_a.bzrdir.open_branch()
136
143
        self.assertEquals(branch_a.get_push_location(),
137
144
                          branch_c.bzrdir.root_transport.base)
138
145
 
145
152
        b2 = branch.Branch.open('pushed-location')
146
153
        self.assertEndsWith(b2.base, 'pushed-location/')
147
154
 
 
155
    def test_push_no_tree(self):
 
156
        # bzr push --no-tree of a branch with working trees
 
157
        b = self.make_branch_and_tree('push-from')
 
158
        self.build_tree(['push-from/file'])
 
159
        b.add('file')
 
160
        b.commit('commit 1')
 
161
        out, err = self.run_bzr('push --no-tree -d push-from push-to')
 
162
        self.assertEqual('', out)
 
163
        self.assertEqual('Created new branch.\n', err)
 
164
        self.assertPathDoesNotExist('push-to/file')
 
165
 
148
166
    def test_push_new_branch_revision_count(self):
149
167
        # bzr push of a branch with revisions to a new location
150
168
        # should print the number of revisions equal to the length of the
157
175
        self.assertEqual('', out)
158
176
        self.assertEqual('Created new branch.\n', err)
159
177
 
 
178
    def test_push_quiet(self):
 
179
        # test that using -q makes output quiet
 
180
        t = self.make_branch_and_tree('tree')
 
181
        self.build_tree(['tree/file'])
 
182
        t.add('file')
 
183
        t.commit('commit 1')
 
184
        self.run_bzr('push -d tree pushed-to')
 
185
        # Refresh the branch as 'push' modified it and get the push location
 
186
        push_loc = t.branch.bzrdir.open_branch().get_push_location()
 
187
        out, err = self.run_bzr('push', working_dir="tree")
 
188
        self.assertEqual('Using saved push location: %s\n'
 
189
                         'No new revisions or tags to push.\n' %
 
190
                         urlutils.local_path_from_url(push_loc), err)
 
191
        out, err = self.run_bzr('push -q', working_dir="tree")
 
192
        self.assertEqual('', out)
 
193
        self.assertEqual('', err)
 
194
 
160
195
    def test_push_only_pushes_history(self):
161
196
        # Knit branches should only push the history for the current revision.
162
197
        format = bzrdir.BzrDirMetaFormat1()
166
201
 
167
202
        def make_shared_tree(path):
168
203
            shared_repo.bzrdir.root_transport.mkdir(path)
169
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
204
            controldir.ControlDir.create_branch_convenience('repo/' + path)
170
205
            return workingtree.WorkingTree.open('repo/' + path)
171
206
        tree_a = make_shared_tree('a')
172
207
        self.build_tree(['repo/a/file'])
207
242
        t.commit(allow_pointless=True,
208
243
                message='first commit')
209
244
        self.run_bzr('push -d from to-one')
210
 
        self.failUnlessExists('to-one')
 
245
        self.assertPathExists('to-one')
211
246
        self.run_bzr('push -d %s %s'
212
247
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
213
 
        self.failUnlessExists('to-two')
 
248
        self.assertPathExists('to-two')
 
249
 
 
250
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
 
251
        # See https://bugs.launchpad.net/bzr/+bug/465517
 
252
        target_repo = self.make_repository('target')
 
253
        source = self.make_branch_builder('source')
 
254
        source.start_series()
 
255
        source.build_snapshot('A', None, [
 
256
            ('add', ('', 'root-id', 'directory', None))])
 
257
        source.build_snapshot('B', ['A'], [])
 
258
        source.build_snapshot('C', ['A'], [])
 
259
        source.finish_series()
 
260
        self.run_bzr('push target -d source')
 
261
        self.addCleanup(target_repo.lock_read().unlock)
 
262
        # We should have pushed 'C', but not 'B', since it isn't in the
 
263
        # ancestry
 
264
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
214
265
 
215
266
    def test_push_smart_non_stacked_streaming_acceptance(self):
216
267
        self.setup_smart_server_with_call_log()
224
275
        # become necessary for this use case. Please do not adjust this number
225
276
        # upwards without agreement from bzr's network support maintainers.
226
277
        self.assertLength(9, self.hpss_calls)
 
278
        self.assertLength(1, self.hpss_connections)
 
279
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
227
280
 
228
281
    def test_push_smart_stacked_streaming_acceptance(self):
229
282
        self.setup_smart_server_with_call_log()
239
292
        # being too low. If rpc_count increases, more network roundtrips have
240
293
        # become necessary for this use case. Please do not adjust this number
241
294
        # upwards without agreement from bzr's network support maintainers.
242
 
        self.assertLength(14, self.hpss_calls)
 
295
        self.assertLength(15, self.hpss_calls)
 
296
        self.assertLength(1, self.hpss_connections)
 
297
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
243
298
        remote = branch.Branch.open('public')
244
299
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
245
300
 
256
311
        # become necessary for this use case. Please do not adjust this number
257
312
        # upwards without agreement from bzr's network support maintainers.
258
313
        self.assertLength(11, self.hpss_calls)
 
314
        self.assertLength(1, self.hpss_connections)
 
315
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
259
316
 
260
317
    def test_push_smart_incremental_acceptance(self):
261
318
        self.setup_smart_server_with_call_log()
272
329
        # become necessary for this use case. Please do not adjust this number
273
330
        # upwards without agreement from bzr's network support maintainers.
274
331
        self.assertLength(11, self.hpss_calls)
 
332
        self.assertLength(1, self.hpss_connections)
 
333
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
275
334
 
276
335
    def test_push_smart_with_default_stacking_url_path_segment(self):
277
336
        # If the default stacked-on location is a path element then branches
316
375
                     working_dir='tree')
317
376
        new_tree = workingtree.WorkingTree.open('new/tree')
318
377
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
319
 
        self.failUnlessExists('new/tree/a')
 
378
        self.assertPathExists('new/tree/a')
320
379
 
321
380
    def test_push_use_existing(self):
322
381
        """'bzr push --use-existing-dir' can push into an existing dir.
337
396
        new_tree = workingtree.WorkingTree.open('target')
338
397
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
339
398
        # The push should have created target/a
340
 
        self.failUnlessExists('target/a')
 
399
        self.assertPathExists('target/a')
341
400
 
342
401
    def test_push_use_existing_into_empty_bzrdir(self):
343
402
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
454
513
        trunk_public = self.make_branch('public_trunk', format='1.9')
455
514
        trunk_public.pull(trunk_tree.branch)
456
515
        trunk_public_url = self.get_readonly_url('public_trunk')
457
 
        trunk_tree.branch.set_public_branch(trunk_public_url)
 
516
        br = trunk_tree.branch
 
517
        br.set_public_branch(trunk_public_url)
458
518
        # now we do a stacked push, which should determine the public location
459
519
        # for us.
460
520
        out, err = self.run_bzr(['push', '--stacked',
651
711
        self.tree.commit('modify file', rev_id='modified')
652
712
 
653
713
    def set_config_push_strict(self, value):
654
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
655
 
        # should do)
656
 
        conf = self.tree.branch.get_config()
657
 
        conf.set_user_option('push_strict', value)
 
714
        br = branch.Branch.open('local')
 
715
        br.get_config_stack().set('push_strict', value)
658
716
 
659
717
    _default_command = ['push', '../to']
660
718
    _default_wd = 'local'
661
719
    _default_errors = ['Working tree ".*/local/" has uncommitted '
662
720
                       'changes \(See bzr status\)\.',]
663
 
    _default_pushed_revid = 'modified'
 
721
    _default_additional_error = 'Use --no-strict to force the push.\n'
 
722
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
 
723
 
664
724
 
665
725
    def assertPushFails(self, args):
666
 
        self.run_bzr_error(self._default_errors, self._default_command + args,
667
 
                           working_dir=self._default_wd, retcode=3)
 
726
        out, err = self.run_bzr_error(self._default_errors,
 
727
                                      self._default_command + args,
 
728
                                      working_dir=self._default_wd, retcode=3)
 
729
        self.assertContainsRe(err, self._default_additional_error)
668
730
 
669
 
    def assertPushSucceeds(self, args, pushed_revid=None):
670
 
        self.run_bzr(self._default_command + args,
671
 
                     working_dir=self._default_wd)
672
 
        if pushed_revid is None:
673
 
            pushed_revid = self._default_pushed_revid
674
 
        tree_to = workingtree.WorkingTree.open('to')
675
 
        repo_to = tree_to.branch.repository
676
 
        self.assertTrue(repo_to.has_revision(pushed_revid))
677
 
        self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
 
731
    def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
 
732
        if with_warning:
 
733
            error_regexes = self._default_errors
 
734
        else:
 
735
            error_regexes = []
 
736
        out, err = self.run_bzr(self._default_command + args,
 
737
                                working_dir=self._default_wd,
 
738
                                error_regexes=error_regexes)
 
739
        if with_warning:
 
740
            self.assertContainsRe(err, self._default_additional_warning)
 
741
        else:
 
742
            self.assertNotContainsRe(err, self._default_additional_warning)
 
743
        branch_from = branch.Branch.open(self._default_wd)
 
744
        if revid_to_push is None:
 
745
            revid_to_push = branch_from.last_revision()
 
746
        branch_to = branch.Branch.open('to')
 
747
        repo_to = branch_to.repository
 
748
        self.assertTrue(repo_to.has_revision(revid_to_push))
 
749
        self.assertEqual(revid_to_push, branch_to.last_revision())
678
750
 
679
751
 
680
752
 
703
775
        self.assertPushSucceeds([])
704
776
 
705
777
 
 
778
strict_push_change_scenarios = [
 
779
    ('uncommitted',
 
780
        dict(_changes_type= '_uncommitted_changes')),
 
781
    ('pending-merges',
 
782
        dict(_changes_type= '_pending_merges')),
 
783
    ('out-of-sync-trees',
 
784
        dict(_changes_type= '_out_of_sync_trees')),
 
785
    ]
 
786
 
 
787
 
706
788
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
707
789
                                TestPushStrictMixin):
708
790
 
 
791
    scenarios = strict_push_change_scenarios 
709
792
    _changes_type = None # Set by load_tests
710
793
 
711
794
    def setUp(self):
741
824
        self._default_wd = 'checkout'
742
825
        self._default_errors = ["Working tree is out of date, please run"
743
826
                                " 'bzr update'\.",]
744
 
        self._default_pushed_revid = 'modified-in-local'
745
827
 
746
828
    def test_push_default(self):
747
 
        self.assertPushFails([])
 
829
        self.assertPushSucceeds([], with_warning=True)
748
830
 
749
831
    def test_push_with_revision(self):
750
 
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
 
832
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
751
833
 
752
834
    def test_push_no_strict(self):
753
835
        self.assertPushSucceeds(['--no-strict'])
761
843
 
762
844
    def test_push_bogus_config_var_ignored(self):
763
845
        self.set_config_push_strict("I don't want you to be strict")
764
 
        self.assertPushFails([])
 
846
        self.assertPushSucceeds([], with_warning=True)
765
847
 
766
848
    def test_push_no_strict_command_line_override_config(self):
767
849
        self.set_config_push_strict('yES')
774
856
        self.assertPushSucceeds([])
775
857
 
776
858
 
777
 
class TestPushForeign(blackbox.ExternalBase):
 
859
class TestPushForeign(tests.TestCaseWithTransport):
778
860
 
779
861
    def setUp(self):
780
862
        super(TestPushForeign, self).setUp()
795
877
        self.assertEquals("", output)
796
878
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
797
879
            " push to dummy. You may want to use dpush instead.\n")
 
880
 
 
881
 
 
882
class TestPushOutput(script.TestCaseWithTransportAndScript):
 
883
 
 
884
    def test_push_log_format(self):
 
885
        self.run_script("""
 
886
            $ bzr init trunk
 
887
            Created a standalone tree (format: 2a)
 
888
            $ cd trunk
 
889
            $ echo foo > file
 
890
            $ bzr add
 
891
            adding file
 
892
            $ bzr commit -m 'we need some foo'
 
893
            2>Committing to:...trunk/
 
894
            2>added file
 
895
            2>Committed revision 1.
 
896
            $ bzr init ../feature
 
897
            Created a standalone tree (format: 2a)
 
898
            $ bzr push -v ../feature -Olog_format=line
 
899
            Added Revisions:
 
900
            1: jrandom@example.com ...we need some foo
 
901
            2>All changes applied successfully.
 
902
            2>Pushed up to revision 1.
 
903
            """)