~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2009-07-01 10:53:08 UTC
  • mto: This revision was merged to the branch mainline in revision 4504.
  • Revision ID: andrew.bennetts@canonical.com-20090701105308-8892qpe3lhikhe3g
RemoveĀ unusedĀ import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2007, 2008 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
31
31
    workingtree
32
32
    )
33
33
from bzrlib.repofmt import knitrepo
34
 
from bzrlib.tests import (
35
 
    blackbox,
36
 
    http_server,
37
 
    scenarios,
38
 
    test_foreign,
39
 
    test_server,
40
 
    )
 
34
from bzrlib.tests import http_server
41
35
from bzrlib.transport import memory
42
36
 
43
37
 
44
 
load_tests = scenarios.load_tests_apply_scenarios
 
38
def load_tests(standard_tests, module, loader):
 
39
    """Multiply tests for the push command."""
 
40
    result = loader.suiteClass()
 
41
 
 
42
    # one for each king of change
 
43
    changes_tests, remaining_tests = tests.split_suite_by_condition(
 
44
        standard_tests, tests.condition_isinstance((
 
45
                TestPushStrictWithChanges,
 
46
                )))
 
47
    changes_scenarios = [
 
48
        ('uncommitted',
 
49
         dict(_changes_type= '_uncommitted_changes')),
 
50
        ('pending_merges',
 
51
         dict(_changes_type= '_pending_merges')),
 
52
        ]
 
53
    tests.multiply_tests(changes_tests, changes_scenarios, result)
 
54
    # No parametrization for the remaining tests
 
55
    result.addTests(remaining_tests)
 
56
 
 
57
    return result
45
58
 
46
59
 
47
60
class TestPush(tests.TestCaseWithTransport):
104
117
        transport.delete('branch_b/c')
105
118
        out, err = self.run_bzr('push', working_dir='branch_a')
106
119
        path = branch_a.get_push_location()
 
120
        self.assertEquals(out,
 
121
                          'Using saved push location: %s\n'
 
122
                          % urlutils.local_path_from_url(path))
107
123
        self.assertEqual(err,
108
 
                         'Using saved push location: %s\n'
109
124
                         'All changes applied successfully.\n'
110
 
                         'Pushed up to revision 2.\n'
111
 
                         % urlutils.local_path_from_url(path))
 
125
                         'Pushed up to revision 2.\n')
112
126
        self.assertEqual(path,
113
127
                         branch_b.bzrdir.root_transport.base)
114
128
        # test explicit --remember
125
139
        b2 = branch.Branch.open('pushed-location')
126
140
        self.assertEndsWith(b2.base, 'pushed-location/')
127
141
 
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
 
 
139
142
    def test_push_new_branch_revision_count(self):
140
143
        # bzr push of a branch with revisions to a new location
141
144
        # should print the number of revisions equal to the length of the
148
151
        self.assertEqual('', out)
149
152
        self.assertEqual('Created new branch.\n', err)
150
153
 
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
 
 
165
154
    def test_push_only_pushes_history(self):
166
155
        # Knit branches should only push the history for the current revision.
167
156
        format = bzrdir.BzrDirMetaFormat1()
212
201
        t.commit(allow_pointless=True,
213
202
                message='first commit')
214
203
        self.run_bzr('push -d from to-one')
215
 
        self.assertPathExists('to-one')
 
204
        self.failUnlessExists('to-one')
216
205
        self.run_bzr('push -d %s %s'
217
206
            % tuple(map(urlutils.local_path_to_url, ['from', '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()))
 
207
        self.failUnlessExists('to-two')
235
208
 
236
209
    def test_push_smart_non_stacked_streaming_acceptance(self):
237
210
        self.setup_smart_server_with_call_log()
260
233
        # being too low. If rpc_count increases, more network roundtrips have
261
234
        # become necessary for this use case. Please do not adjust this number
262
235
        # upwards without agreement from bzr's network support maintainers.
263
 
        self.assertLength(13, self.hpss_calls)
 
236
        self.assertLength(14, self.hpss_calls)
264
237
        remote = branch.Branch.open('public')
265
238
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
266
239
 
267
 
    def test_push_smart_tags_streaming_acceptance(self):
268
 
        self.setup_smart_server_with_call_log()
269
 
        t = self.make_branch_and_tree('from')
270
 
        rev_id = t.commit(allow_pointless=True, message='first commit')
271
 
        t.branch.tags.set_tag('new-tag', rev_id)
272
 
        self.reset_smart_call_log()
273
 
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
274
 
        # This figure represent the amount of work to perform this use case. It
275
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
276
 
        # being too low. If rpc_count increases, more network roundtrips have
277
 
        # become necessary for this use case. Please do not adjust this number
278
 
        # upwards without agreement from bzr's network support maintainers.
279
 
        self.assertLength(11, self.hpss_calls)
280
 
 
281
 
    def test_push_smart_incremental_acceptance(self):
282
 
        self.setup_smart_server_with_call_log()
283
 
        t = self.make_branch_and_tree('from')
284
 
        rev_id1 = t.commit(allow_pointless=True, message='first commit')
285
 
        rev_id2 = t.commit(allow_pointless=True, message='second commit')
286
 
        self.run_bzr(
287
 
            ['push', self.get_url('to-one'), '-r1'], working_dir='from')
288
 
        self.reset_smart_call_log()
289
 
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
290
 
        # This figure represent the amount of work to perform this use case. It
291
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
292
 
        # being too low. If rpc_count increases, more network roundtrips have
293
 
        # become necessary for this use case. Please do not adjust this number
294
 
        # upwards without agreement from bzr's network support maintainers.
295
 
        self.assertLength(11, self.hpss_calls)
296
 
 
297
240
    def test_push_smart_with_default_stacking_url_path_segment(self):
298
241
        # If the default stacked-on location is a path element then branches
299
242
        # we push there over the smart server are stacked and their
337
280
                     working_dir='tree')
338
281
        new_tree = workingtree.WorkingTree.open('new/tree')
339
282
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
 
        self.assertPathExists('new/tree/a')
 
283
        self.failUnlessExists('new/tree/a')
341
284
 
342
285
    def test_push_use_existing(self):
343
286
        """'bzr push --use-existing-dir' can push into an existing dir.
358
301
        new_tree = workingtree.WorkingTree.open('target')
359
302
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
360
303
        # The push should have created target/a
361
 
        self.assertPathExists('target/a')
362
 
 
363
 
    def test_push_use_existing_into_empty_bzrdir(self):
364
 
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
365
 
        fails.
366
 
        """
367
 
        tree = self.create_simple_tree()
368
 
        self.build_tree(['target/', 'target/.bzr/'])
369
 
        self.run_bzr_error(
370
 
            ['Target directory ../target already contains a .bzr directory, '
371
 
             'but it is not valid.'],
372
 
            'push ../target --use-existing-dir', working_dir='tree')
 
304
        self.failUnlessExists('target/a')
373
305
 
374
306
    def test_push_onto_repo(self):
375
307
        """We should be able to 'bzr push' into an existing bzrdir."""
578
510
class RedirectingMemoryTransport(memory.MemoryTransport):
579
511
 
580
512
    def mkdir(self, relpath, mode=None):
 
513
        from bzrlib.trace import mutter
581
514
        if self._cwd == '/source/':
582
515
            raise errors.RedirectRequested(self.abspath(relpath),
583
516
                                           self.abspath('../target'),
590
523
            return super(RedirectingMemoryTransport, self).mkdir(
591
524
                relpath, mode)
592
525
 
593
 
    def get(self, relpath):
594
 
        if self.clone(relpath)._cwd == '/infinite-loop/':
595
 
            raise errors.RedirectRequested(self.abspath(relpath),
596
 
                                           self.abspath('../infinite-loop'),
597
 
                                           is_permanent=True)
598
 
        else:
599
 
            return super(RedirectingMemoryTransport, self).get(relpath)
600
 
 
601
526
    def _redirected_to(self, source, target):
602
527
        # We do accept redirections
603
528
        return transport.get_transport(target)
605
530
 
606
531
class RedirectingMemoryServer(memory.MemoryServer):
607
532
 
608
 
    def start_server(self):
 
533
    def setUp(self):
609
534
        self._dirs = {'/': None}
610
535
        self._files = {}
611
536
        self._locks = {}
619
544
        result._locks = self._locks
620
545
        return result
621
546
 
622
 
    def stop_server(self):
 
547
    def tearDown(self):
623
548
        transport.unregister_transport(self._scheme, self._memory_factory)
624
549
 
625
550
 
628
553
    def setUp(self):
629
554
        tests.TestCaseWithTransport.setUp(self)
630
555
        self.memory_server = RedirectingMemoryServer()
631
 
        self.start_server(self.memory_server)
 
556
        self.memory_server.setUp()
 
557
        self.addCleanup(self.memory_server.tearDown)
 
558
 
632
559
        # Make the branch and tree that we'll be pushing.
633
560
        t = self.make_branch_and_tree('tree')
634
561
        self.build_tree(['tree/file'])
661
588
        self.assertEqual('', out)
662
589
 
663
590
 
664
 
class TestPushStrictMixin(object):
 
591
class TestPushStrict(tests.TestCaseWithTransport):
665
592
 
666
593
    def make_local_branch_and_tree(self):
667
594
        self.tree = self.make_branch_and_tree('local')
677
604
        conf = self.tree.branch.get_config()
678
605
        conf.set_user_option('push_strict', value)
679
606
 
680
 
    _default_command = ['push', '../to']
681
 
    _default_wd = 'local'
682
 
    _default_errors = ['Working tree ".*/local/" has uncommitted '
683
 
                       'changes \(See bzr status\)\.',]
684
 
    _default_additional_error = 'Use --no-strict to force the push.\n'
685
 
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
686
 
 
687
 
 
688
607
    def assertPushFails(self, args):
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)
693
 
 
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())
713
 
 
714
 
 
715
 
 
716
 
class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
717
 
                                   TestPushStrictMixin):
 
608
        self.run_bzr_error(['Working tree ".*/local/"'
 
609
                            ' has uncommitted changes \(See bzr status\)\.',],
 
610
                           ['push', '../to'] + args,
 
611
                           working_dir='local', retcode=3)
 
612
 
 
613
    def assertPushSucceeds(self, args, pushed_revid=None):
 
614
        self.run_bzr(['push', '../to'] + args,
 
615
                     working_dir='local')
 
616
        if pushed_revid is None:
 
617
            pushed_revid = 'modified'
 
618
        tree_to = workingtree.WorkingTree.open('to')
 
619
        repo_to = tree_to.branch.repository
 
620
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
621
        self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
 
622
 
 
623
 
 
624
 
 
625
class TestPushStrictWithoutChanges(TestPushStrict):
718
626
 
719
627
    def setUp(self):
720
628
        super(TestPushStrictWithoutChanges, self).setUp()
738
646
        self.assertPushSucceeds([])
739
647
 
740
648
 
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
 
 
751
 
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
752
 
                                TestPushStrictMixin):
753
 
 
754
 
    scenarios = strict_push_change_scenarios 
 
649
class TestPushStrictWithChanges(TestPushStrict):
 
650
 
755
651
    _changes_type = None # Set by load_tests
756
652
 
757
653
    def setUp(self):
758
654
        super(TestPushStrictWithChanges, self).setUp()
759
 
        # Apply the changes defined in load_tests: one of _uncommitted_changes,
760
 
        # _pending_merges or _out_of_sync_trees
761
655
        getattr(self, self._changes_type)()
762
656
 
763
657
    def _uncommitted_changes(self):
777
671
        self.tree.merge_from_branch(other_tree.branch)
778
672
        self.tree.revert(filenames=['other-file'], backups=False)
779
673
 
780
 
    def _out_of_sync_trees(self):
781
 
        self.make_local_branch_and_tree()
782
 
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
783
 
        # Make a change and commit it
784
 
        self.build_tree_contents([('local/file', 'modified in local')])
785
 
        self.tree.commit('modify file', rev_id='modified-in-local')
786
 
        # Exercise commands from the checkout directory
787
 
        self._default_wd = 'checkout'
788
 
        self._default_errors = ["Working tree is out of date, please run"
789
 
                                " 'bzr update'\.",]
790
 
 
791
674
    def test_push_default(self):
792
 
        self.assertPushSucceeds([], with_warning=True)
 
675
        self.assertPushFails([])
793
676
 
794
677
    def test_push_with_revision(self):
795
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
 
678
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
796
679
 
797
680
    def test_push_no_strict(self):
798
681
        self.assertPushSucceeds(['--no-strict'])
806
689
 
807
690
    def test_push_bogus_config_var_ignored(self):
808
691
        self.set_config_push_strict("I don't want you to be strict")
809
 
        self.assertPushSucceeds([], with_warning=True)
 
692
        self.assertPushFails([])
810
693
 
811
694
    def test_push_no_strict_command_line_override_config(self):
812
695
        self.set_config_push_strict('yES')
817
700
        self.set_config_push_strict('oFF')
818
701
        self.assertPushFails(['--strict'])
819
702
        self.assertPushSucceeds([])
820
 
 
821
 
 
822
 
class TestPushForeign(tests.TestCaseWithTransport):
823
 
 
824
 
    def setUp(self):
825
 
        super(TestPushForeign, self).setUp()
826
 
        test_foreign.register_dummy_foreign_for_test(self)
827
 
 
828
 
    def make_dummy_builder(self, relpath):
829
 
        builder = self.make_branch_builder(
830
 
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
831
 
        builder.build_snapshot('revid', None,
832
 
            [('add', ('', 'TREE_ROOT', 'directory', None)),
833
 
             ('add', ('foo', 'fooid', 'file', 'bar'))])
834
 
        return builder
835
 
 
836
 
    def test_no_roundtripping(self):
837
 
        target_branch = self.make_dummy_builder('dp').get_branch()
838
 
        source_tree = self.make_branch_and_tree("dc")
839
 
        output, error = self.run_bzr("push -d dc dp", retcode=3)
840
 
        self.assertEquals("", output)
841
 
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
842
 
            " push to dummy. You may want to use dpush instead.\n")