/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: Canonical.com Patch Queue Manager
  • Date: 2009-08-19 18:04:49 UTC
  • mfrom: (4593.5.43 1.19-known-graph-sorted)
  • Revision ID: pqm@pqm.ubuntu.com-20090819180449-p5dibldf9pcp24n4
(jam) Add VersionedFiles.get_known_graph_ancestry and
        KnownGraph.merge_sort()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 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
 
    test_foreign,
38
 
    test_server,
39
 
    )
 
34
from bzrlib.tests import http_server
40
35
from bzrlib.transport import memory
41
36
 
42
37
 
139
134
 
140
135
    def test_push_without_tree(self):
141
136
        # bzr push from a branch that does not have a checkout should work.
 
137
        self.thisFailsStrictLockCheck()
142
138
        b = self.make_branch('.')
143
139
        out, err = self.run_bzr('push pushed-location')
144
140
        self.assertEqual('', out)
150
146
        # bzr push of a branch with revisions to a new location
151
147
        # should print the number of revisions equal to the length of the
152
148
        # local branch.
 
149
        self.thisFailsStrictLockCheck()
153
150
        t = self.make_branch_and_tree('tree')
154
151
        self.build_tree(['tree/file'])
155
152
        t.add('file')
160
157
 
161
158
    def test_push_only_pushes_history(self):
162
159
        # Knit branches should only push the history for the current revision.
 
160
        self.thisFailsStrictLockCheck()
163
161
        format = bzrdir.BzrDirMetaFormat1()
164
162
        format.repository_format = knitrepo.RepositoryFormatKnit1()
165
163
        shared_repo = self.make_repository('repo', format=format, shared=True)
197
195
        self.assertTrue(pushed_repo.has_revision('b-1'))
198
196
 
199
197
    def test_push_funky_id(self):
 
198
        self.thisFailsStrictLockCheck()
200
199
        t = self.make_branch_and_tree('tree')
201
200
        self.build_tree(['tree/filename'])
202
201
        t.add('filename', 'funky-chars<>%&;"\'')
204
203
        self.run_bzr('push -d tree new-tree')
205
204
 
206
205
    def test_push_dash_d(self):
 
206
        self.thisFailsStrictLockCheck()
207
207
        t = self.make_branch_and_tree('from')
208
208
        t.commit(allow_pointless=True,
209
209
                message='first commit')
258
258
        # upwards without agreement from bzr's network support maintainers.
259
259
        self.assertLength(11, self.hpss_calls)
260
260
 
261
 
    def test_push_smart_incremental_acceptance(self):
262
 
        self.setup_smart_server_with_call_log()
263
 
        t = self.make_branch_and_tree('from')
264
 
        rev_id1 = t.commit(allow_pointless=True, message='first commit')
265
 
        rev_id2 = t.commit(allow_pointless=True, message='second commit')
266
 
        self.run_bzr(
267
 
            ['push', self.get_url('to-one'), '-r1'], working_dir='from')
268
 
        self.reset_smart_call_log()
269
 
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
270
 
        # This figure represent the amount of work to perform this use case. It
271
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
272
 
        # being too low. If rpc_count increases, more network roundtrips have
273
 
        # become necessary for this use case. Please do not adjust this number
274
 
        # upwards without agreement from bzr's network support maintainers.
275
 
        self.assertLength(11, self.hpss_calls)
276
 
 
277
261
    def test_push_smart_with_default_stacking_url_path_segment(self):
278
262
        # If the default stacked-on location is a path element then branches
279
263
        # we push there over the smart server are stacked and their
308
292
 
309
293
    def test_push_create_prefix(self):
310
294
        """'bzr push --create-prefix' will create leading directories."""
 
295
        self.thisFailsStrictLockCheck()
311
296
        tree = self.create_simple_tree()
312
297
 
313
298
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
324
309
 
325
310
        By default, 'bzr push' will not use an existing, non-versioned dir.
326
311
        """
 
312
        self.thisFailsStrictLockCheck()
327
313
        tree = self.create_simple_tree()
328
314
        self.build_tree(['target/'])
329
315
 
340
326
        # The push should have created target/a
341
327
        self.failUnlessExists('target/a')
342
328
 
343
 
    def test_push_use_existing_into_empty_bzrdir(self):
344
 
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
345
 
        fails.
346
 
        """
347
 
        tree = self.create_simple_tree()
348
 
        self.build_tree(['target/', 'target/.bzr/'])
349
 
        self.run_bzr_error(
350
 
            ['Target directory ../target already contains a .bzr directory, '
351
 
             'but it is not valid.'],
352
 
            'push ../target --use-existing-dir', working_dir='tree')
353
 
 
354
329
    def test_push_onto_repo(self):
355
330
        """We should be able to 'bzr push' into an existing bzrdir."""
356
331
        tree = self.create_simple_tree()
383
358
 
384
359
    def test_push_with_revisionspec(self):
385
360
        """We should be able to push a revision older than the tip."""
 
361
        self.thisFailsStrictLockCheck()
386
362
        tree_from = self.make_branch_and_tree('from')
387
363
        tree_from.commit("One.", rev_id="from-1")
388
364
        tree_from.commit("Two.", rev_id="from-2")
424
400
 
425
401
    def test_push_new_branch_stacked_on(self):
426
402
        """Pushing a new branch with --stacked-on creates a stacked branch."""
 
403
        self.thisFailsStrictLockCheck()
427
404
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
428
405
        # we publish branch_tree with a reference to the mainline.
429
406
        out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
436
413
 
437
414
    def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
438
415
        """When the parent has no public url the parent is used as-is."""
 
416
        self.thisFailsStrictLockCheck()
439
417
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
440
418
        # now we do a stacked push, which should determine the public location
441
419
        # for us.
449
427
 
450
428
    def test_push_new_branch_stacked_uses_parent_public(self):
451
429
        """Pushing a new branch with --stacked creates a stacked branch."""
 
430
        self.thisFailsStrictLockCheck()
452
431
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
453
432
        # the trunk is published on a web server
454
433
        self.transport_readonly_server = http_server.HttpServer
533
512
        out, err = self.run_bzr('push -d repo/local remote -r 3')
534
513
 
535
514
    def test_push_verbose_shows_log(self):
 
515
        self.thisFailsStrictLockCheck()
536
516
        tree = self.make_branch_and_tree('source')
537
517
        tree.commit('rev1')
538
518
        out, err = self.run_bzr('push -v -d source target')
546
526
        self.assertNotContainsRe(out, 'rev1')
547
527
 
548
528
    def test_push_from_subdir(self):
 
529
        self.thisFailsStrictLockCheck()
549
530
        t = self.make_branch_and_tree('tree')
550
531
        self.build_tree(['tree/dir/', 'tree/dir/file'])
551
532
        t.add('dir', 'dir/file')
585
566
 
586
567
class RedirectingMemoryServer(memory.MemoryServer):
587
568
 
588
 
    def start_server(self):
 
569
    def setUp(self):
589
570
        self._dirs = {'/': None}
590
571
        self._files = {}
591
572
        self._locks = {}
599
580
        result._locks = self._locks
600
581
        return result
601
582
 
602
 
    def stop_server(self):
 
583
    def tearDown(self):
603
584
        transport.unregister_transport(self._scheme, self._memory_factory)
604
585
 
605
586
 
608
589
    def setUp(self):
609
590
        tests.TestCaseWithTransport.setUp(self)
610
591
        self.memory_server = RedirectingMemoryServer()
611
 
        self.start_server(self.memory_server)
 
592
        self.memory_server.setUp()
 
593
        self.addCleanup(self.memory_server.tearDown)
 
594
 
612
595
        # Make the branch and tree that we'll be pushing.
613
596
        t = self.make_branch_and_tree('tree')
614
597
        self.build_tree(['tree/file'])
661
644
    _default_wd = 'local'
662
645
    _default_errors = ['Working tree ".*/local/" has uncommitted '
663
646
                       'changes \(See bzr status\)\.',]
664
 
    _default_additional_error = 'Use --no-strict to force the push.\n'
665
 
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
666
 
 
 
647
    _default_pushed_revid = 'modified'
667
648
 
668
649
    def assertPushFails(self, args):
669
 
        out, err = self.run_bzr_error(self._default_errors,
670
 
                                      self._default_command + args,
671
 
                                      working_dir=self._default_wd, retcode=3)
672
 
        self.assertContainsRe(err, self._default_additional_error)
 
650
        self.run_bzr_error(self._default_errors, self._default_command + args,
 
651
                           working_dir=self._default_wd, retcode=3)
673
652
 
674
 
    def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
675
 
        if with_warning:
676
 
            error_regexes = self._default_errors
677
 
        else:
678
 
            error_regexes = []
679
 
        out, err = self.run_bzr(self._default_command + args,
680
 
                                working_dir=self._default_wd,
681
 
                                error_regexes=error_regexes)
682
 
        if with_warning:
683
 
            self.assertContainsRe(err, self._default_additional_warning)
684
 
        else:
685
 
            self.assertNotContainsRe(err, self._default_additional_warning)
686
 
        branch_from = branch.Branch.open(self._default_wd)
687
 
        if revid_to_push is None:
688
 
            revid_to_push = branch_from.last_revision()
689
 
        branch_to = branch.Branch.open('to')
690
 
        repo_to = branch_to.repository
691
 
        self.assertTrue(repo_to.has_revision(revid_to_push))
692
 
        self.assertEqual(revid_to_push, branch_to.last_revision())
 
653
    def assertPushSucceeds(self, args, pushed_revid=None):
 
654
        self.run_bzr(self._default_command + args,
 
655
                     working_dir=self._default_wd)
 
656
        if pushed_revid is None:
 
657
            pushed_revid = self._default_pushed_revid
 
658
        tree_to = workingtree.WorkingTree.open('to')
 
659
        repo_to = tree_to.branch.repository
 
660
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
661
        self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
693
662
 
694
663
 
695
664
 
701
670
        self.make_local_branch_and_tree()
702
671
 
703
672
    def test_push_default(self):
 
673
        self.thisFailsStrictLockCheck()
704
674
        self.assertPushSucceeds([])
705
675
 
706
676
    def test_push_strict(self):
 
677
        self.thisFailsStrictLockCheck()
707
678
        self.assertPushSucceeds(['--strict'])
708
679
 
709
680
    def test_push_no_strict(self):
 
681
        self.thisFailsStrictLockCheck()
710
682
        self.assertPushSucceeds(['--no-strict'])
711
683
 
712
684
    def test_push_config_var_strict(self):
 
685
        self.thisFailsStrictLockCheck()
713
686
        self.set_config_push_strict('true')
714
687
        self.assertPushSucceeds([])
715
688
 
716
689
    def test_push_config_var_no_strict(self):
 
690
        self.thisFailsStrictLockCheck()
717
691
        self.set_config_push_strict('false')
718
692
        self.assertPushSucceeds([])
719
693
 
725
699
 
726
700
    def setUp(self):
727
701
        super(TestPushStrictWithChanges, self).setUp()
728
 
        # Apply the changes defined in load_tests: one of _uncommitted_changes,
729
 
        # _pending_merges or _out_of_sync_trees
730
702
        getattr(self, self._changes_type)()
731
703
 
732
704
    def _uncommitted_changes(self):
756
728
        self._default_wd = 'checkout'
757
729
        self._default_errors = ["Working tree is out of date, please run"
758
730
                                " 'bzr update'\.",]
 
731
        self._default_pushed_revid = 'modified-in-local'
759
732
 
760
733
    def test_push_default(self):
761
 
        self.assertPushSucceeds([], with_warning=True)
 
734
        self.assertPushFails([])
762
735
 
763
736
    def test_push_with_revision(self):
764
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
 
737
        self.thisFailsStrictLockCheck()
 
738
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
765
739
 
766
740
    def test_push_no_strict(self):
 
741
        self.thisFailsStrictLockCheck()
767
742
        self.assertPushSucceeds(['--no-strict'])
768
743
 
769
744
    def test_push_strict_with_changes(self):
775
750
 
776
751
    def test_push_bogus_config_var_ignored(self):
777
752
        self.set_config_push_strict("I don't want you to be strict")
778
 
        self.assertPushSucceeds([], with_warning=True)
 
753
        self.assertPushFails([])
779
754
 
780
755
    def test_push_no_strict_command_line_override_config(self):
 
756
        self.thisFailsStrictLockCheck()
781
757
        self.set_config_push_strict('yES')
782
758
        self.assertPushFails([])
783
759
        self.assertPushSucceeds(['--no-strict'])
784
760
 
785
761
    def test_push_strict_command_line_override_config(self):
 
762
        self.thisFailsStrictLockCheck()
786
763
        self.set_config_push_strict('oFF')
787
764
        self.assertPushFails(['--strict'])
788
765
        self.assertPushSucceeds([])
789
 
 
790
 
 
791
 
class TestPushForeign(blackbox.ExternalBase):
792
 
 
793
 
    def setUp(self):
794
 
        super(TestPushForeign, self).setUp()
795
 
        test_foreign.register_dummy_foreign_for_test(self)
796
 
 
797
 
    def make_dummy_builder(self, relpath):
798
 
        builder = self.make_branch_builder(
799
 
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
800
 
        builder.build_snapshot('revid', None,
801
 
            [('add', ('', 'TREE_ROOT', 'directory', None)),
802
 
             ('add', ('foo', 'fooid', 'file', 'bar'))])
803
 
        return builder
804
 
 
805
 
    def test_no_roundtripping(self):
806
 
        target_branch = self.make_dummy_builder('dp').get_branch()
807
 
        source_tree = self.make_branch_and_tree("dc")
808
 
        output, error = self.run_bzr("push -d dc dp", retcode=3)
809
 
        self.assertEquals("", output)
810
 
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
 
            " push to dummy. You may want to use dpush instead.\n")