~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
34
34
from bzrlib.tests import (
35
35
    blackbox,
36
36
    http_server,
 
37
    scenarios,
37
38
    test_foreign,
 
39
    test_server,
38
40
    )
39
41
from bzrlib.transport import memory
40
42
 
41
43
 
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
 
44
load_tests = scenarios.load_tests_apply_scenarios
64
45
 
65
46
 
66
47
class TestPush(tests.TestCaseWithTransport):
123
104
        transport.delete('branch_b/c')
124
105
        out, err = self.run_bzr('push', working_dir='branch_a')
125
106
        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
107
        self.assertEqual(err,
 
108
                         'Using saved push location: %s\n'
130
109
                         'All changes applied successfully.\n'
131
 
                         'Pushed up to revision 2.\n')
 
110
                         'Pushed up to revision 2.\n'
 
111
                         % urlutils.local_path_from_url(path))
132
112
        self.assertEqual(path,
133
113
                         branch_b.bzrdir.root_transport.base)
134
114
        # test explicit --remember
145
125
        b2 = branch.Branch.open('pushed-location')
146
126
        self.assertEndsWith(b2.base, 'pushed-location/')
147
127
 
 
128
    def test_push_no_tree(self):
 
129
        # bzr push --no-tree of a branch with working trees
 
130
        b = self.make_branch_and_tree('push-from')
 
131
        self.build_tree(['push-from/file'])
 
132
        b.add('file')
 
133
        b.commit('commit 1')
 
134
        out, err = self.run_bzr('push --no-tree -d push-from push-to')
 
135
        self.assertEqual('', out)
 
136
        self.assertEqual('Created new branch.\n', err)
 
137
        self.assertPathDoesNotExist('push-to/file')
 
138
 
148
139
    def test_push_new_branch_revision_count(self):
149
140
        # bzr push of a branch with revisions to a new location
150
141
        # should print the number of revisions equal to the length of the
157
148
        self.assertEqual('', out)
158
149
        self.assertEqual('Created new branch.\n', err)
159
150
 
 
151
    def test_push_quiet(self):
 
152
        # test that using -q makes output quiet
 
153
        t = self.make_branch_and_tree('tree')
 
154
        self.build_tree(['tree/file'])
 
155
        t.add('file')
 
156
        t.commit('commit 1')
 
157
        self.run_bzr('push -d tree pushed-to')
 
158
        path = t.branch.get_push_location()
 
159
        out, err = self.run_bzr('push', working_dir="tree")
 
160
        self.assertEqual('Using saved push location: %s\nNo new revisions to push.\n' % urlutils.local_path_from_url(path), err)
 
161
        out, err = self.run_bzr('push -q', working_dir="tree")
 
162
        self.assertEqual('', out)
 
163
        self.assertEqual('', err)
 
164
 
160
165
    def test_push_only_pushes_history(self):
161
166
        # Knit branches should only push the history for the current revision.
162
167
        format = bzrdir.BzrDirMetaFormat1()
207
212
        t.commit(allow_pointless=True,
208
213
                message='first commit')
209
214
        self.run_bzr('push -d from to-one')
210
 
        self.failUnlessExists('to-one')
 
215
        self.assertPathExists('to-one')
211
216
        self.run_bzr('push -d %s %s'
212
217
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
213
 
        self.failUnlessExists('to-two')
 
218
        self.assertPathExists('to-two')
 
219
 
 
220
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
 
221
        # See https://bugs.launchpad.net/bzr/+bug/465517
 
222
        target_repo = self.make_repository('target')
 
223
        source = self.make_branch_builder('source')
 
224
        source.start_series()
 
225
        source.build_snapshot('A', None, [
 
226
            ('add', ('', 'root-id', 'directory', None))])
 
227
        source.build_snapshot('B', ['A'], [])
 
228
        source.build_snapshot('C', ['A'], [])
 
229
        source.finish_series()
 
230
        self.run_bzr('push target -d source')
 
231
        self.addCleanup(target_repo.lock_read().unlock)
 
232
        # We should have pushed 'C', but not 'B', since it isn't in the
 
233
        # ancestry
 
234
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
214
235
 
215
236
    def test_push_smart_non_stacked_streaming_acceptance(self):
216
237
        self.setup_smart_server_with_call_log()
239
260
        # being too low. If rpc_count increases, more network roundtrips have
240
261
        # become necessary for this use case. Please do not adjust this number
241
262
        # upwards without agreement from bzr's network support maintainers.
242
 
        self.assertLength(14, self.hpss_calls)
 
263
        self.assertLength(13, self.hpss_calls)
243
264
        remote = branch.Branch.open('public')
244
265
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
245
266
 
316
337
                     working_dir='tree')
317
338
        new_tree = workingtree.WorkingTree.open('new/tree')
318
339
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
319
 
        self.failUnlessExists('new/tree/a')
 
340
        self.assertPathExists('new/tree/a')
320
341
 
321
342
    def test_push_use_existing(self):
322
343
        """'bzr push --use-existing-dir' can push into an existing dir.
337
358
        new_tree = workingtree.WorkingTree.open('target')
338
359
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
339
360
        # The push should have created target/a
340
 
        self.failUnlessExists('target/a')
 
361
        self.assertPathExists('target/a')
341
362
 
342
363
    def test_push_use_existing_into_empty_bzrdir(self):
343
364
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
660
681
    _default_wd = 'local'
661
682
    _default_errors = ['Working tree ".*/local/" has uncommitted '
662
683
                       'changes \(See bzr status\)\.',]
663
 
    _default_pushed_revid = 'modified'
 
684
    _default_additional_error = 'Use --no-strict to force the push.\n'
 
685
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
 
686
 
664
687
 
665
688
    def assertPushFails(self, args):
666
 
        self.run_bzr_error(self._default_errors, self._default_command + args,
667
 
                           working_dir=self._default_wd, retcode=3)
 
689
        out, err = self.run_bzr_error(self._default_errors,
 
690
                                      self._default_command + args,
 
691
                                      working_dir=self._default_wd, retcode=3)
 
692
        self.assertContainsRe(err, self._default_additional_error)
668
693
 
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)
 
694
    def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
 
695
        if with_warning:
 
696
            error_regexes = self._default_errors
 
697
        else:
 
698
            error_regexes = []
 
699
        out, err = self.run_bzr(self._default_command + args,
 
700
                                working_dir=self._default_wd,
 
701
                                error_regexes=error_regexes)
 
702
        if with_warning:
 
703
            self.assertContainsRe(err, self._default_additional_warning)
 
704
        else:
 
705
            self.assertNotContainsRe(err, self._default_additional_warning)
 
706
        branch_from = branch.Branch.open(self._default_wd)
 
707
        if revid_to_push is None:
 
708
            revid_to_push = branch_from.last_revision()
 
709
        branch_to = branch.Branch.open('to')
 
710
        repo_to = branch_to.repository
 
711
        self.assertTrue(repo_to.has_revision(revid_to_push))
 
712
        self.assertEqual(revid_to_push, branch_to.last_revision())
678
713
 
679
714
 
680
715
 
703
738
        self.assertPushSucceeds([])
704
739
 
705
740
 
 
741
strict_push_change_scenarios = [
 
742
    ('uncommitted',
 
743
        dict(_changes_type= '_uncommitted_changes')),
 
744
    ('pending-merges',
 
745
        dict(_changes_type= '_pending_merges')),
 
746
    ('out-of-sync-trees',
 
747
        dict(_changes_type= '_out_of_sync_trees')),
 
748
    ]
 
749
 
 
750
 
706
751
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
707
752
                                TestPushStrictMixin):
708
753
 
 
754
    scenarios = strict_push_change_scenarios 
709
755
    _changes_type = None # Set by load_tests
710
756
 
711
757
    def setUp(self):
741
787
        self._default_wd = 'checkout'
742
788
        self._default_errors = ["Working tree is out of date, please run"
743
789
                                " 'bzr update'\.",]
744
 
        self._default_pushed_revid = 'modified-in-local'
745
790
 
746
791
    def test_push_default(self):
747
 
        self.assertPushFails([])
 
792
        self.assertPushSucceeds([], with_warning=True)
748
793
 
749
794
    def test_push_with_revision(self):
750
 
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
 
795
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
751
796
 
752
797
    def test_push_no_strict(self):
753
798
        self.assertPushSucceeds(['--no-strict'])
761
806
 
762
807
    def test_push_bogus_config_var_ignored(self):
763
808
        self.set_config_push_strict("I don't want you to be strict")
764
 
        self.assertPushFails([])
 
809
        self.assertPushSucceeds([], with_warning=True)
765
810
 
766
811
    def test_push_no_strict_command_line_override_config(self):
767
812
        self.set_config_push_strict('yES')
774
819
        self.assertPushSucceeds([])
775
820
 
776
821
 
777
 
class TestPushForeign(blackbox.ExternalBase):
 
822
class TestPushForeign(tests.TestCaseWithTransport):
778
823
 
779
824
    def setUp(self):
780
825
        super(TestPushForeign, self).setUp()