~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2009-06-19 09:06:56 UTC
  • mfrom: (4463 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4464.
  • Revision ID: mbp@sourcefrog.net-20090619090656-d5weqeecyscv8kqp
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
                           working_dir='branch_a', retcode=3)
87
87
        self.assertEquals(out,
88
88
                ('','bzr: ERROR: These branches have diverged.  '
89
 
                    'Try using "merge" and then "push".\n'))
 
89
                 'See "bzr help diverged-branches" for more information.\n'))
90
90
        self.assertEquals(osutils.abspath(branch_a.get_push_location()),
91
91
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
92
92
 
215
215
        remote = branch.Branch.open('public')
216
216
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
217
217
 
 
218
    def test_push_smart_with_default_stacking_url_path_segment(self):
 
219
        # If the default stacked-on location is a path element then branches
 
220
        # we push there over the smart server are stacked and their
 
221
        # stacked_on_url is that exact path segment. Added to nail bug 385132.
 
222
        self.setup_smart_server_with_call_log()
 
223
        self.make_branch('stack-on', format='1.9')
 
224
        self.make_bzrdir('.').get_config().set_default_stack_on(
 
225
            '/stack-on')
 
226
        self.make_branch('from', format='1.9')
 
227
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
 
228
        b = branch.Branch.open(self.get_url('to'))
 
229
        self.assertEqual('/extra/stack-on', b.get_stacked_on_url())
 
230
 
 
231
    def test_push_smart_with_default_stacking_relative_path(self):
 
232
        # If the default stacked-on location is a relative path then branches
 
233
        # we push there over the smart server are stacked and their
 
234
        # stacked_on_url is a relative path. Added to nail bug 385132.
 
235
        self.setup_smart_server_with_call_log()
 
236
        self.make_branch('stack-on', format='1.9')
 
237
        self.make_bzrdir('.').get_config().set_default_stack_on('stack-on')
 
238
        self.make_branch('from', format='1.9')
 
239
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
 
240
        b = branch.Branch.open(self.get_url('to'))
 
241
        self.assertEqual('../stack-on', b.get_stacked_on_url())
 
242
 
218
243
    def create_simple_tree(self):
219
244
        tree = self.make_branch_and_tree('tree')
220
245
        self.build_tree(['tree/a'])
530
555
             % re.escape(destination_url)],
531
556
            ['push', '-d', 'tree', destination_url], retcode=3)
532
557
        self.assertEqual('', out)
 
558
 
 
559
 
 
560
class TestPushStrict(tests.TestCaseWithTransport):
 
561
 
 
562
    def make_local_branch_and_tree(self):
 
563
        tree = self.make_branch_and_tree('local')
 
564
        self.build_tree_contents([('local/file', 'initial')])
 
565
        tree.add('file')
 
566
        tree.commit('adding file', rev_id='from-1')
 
567
        return tree
 
568
 
 
569
    def make_local_branch_and_tree_with_changes(self):
 
570
        tree = self.make_local_branch_and_tree()
 
571
        # Make some changes
 
572
        self.build_tree_contents([('local/file', 'modified')])
 
573
        return tree
 
574
 
 
575
    def set_config_push_strict(self, tree, value):
 
576
        # set config var (any of bazaar.conf, locations.conf, branch.conf
 
577
        # should do)
 
578
        conf = tree.branch.get_config()
 
579
        conf.set_user_option('push_strict', value)
 
580
 
 
581
    def assertPushFails(self, location, *args):
 
582
        self.run_bzr_error(['Working tree ".*/local/"'
 
583
                            ' has uncommitted changes.$',],
 
584
                           ['push', '../' + location] + list(args),
 
585
                           working_dir='local', retcode=3)
 
586
 
 
587
    def assertPushSucceeds(self, location, *args):
 
588
        self.run_bzr(['push', '../' + location] + list(args),
 
589
                     working_dir='local')
 
590
        tree_to = workingtree.WorkingTree.open(location)
 
591
        repo_to = tree_to.branch.repository
 
592
        self.assertTrue(repo_to.has_revision('from-1'))
 
593
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
 
594
 
 
595
    def test_push_default(self):
 
596
        tree = self.make_local_branch_and_tree_with_changes()
 
597
        self.assertPushSucceeds('to')
 
598
 
 
599
    def test_push_no_strict_with_changes(self):
 
600
        tree = self.make_local_branch_and_tree_with_changes()
 
601
        self.assertPushSucceeds('to', '--no-strict')
 
602
 
 
603
    def test_push_strict_with_changes(self):
 
604
        tree = self.make_local_branch_and_tree_with_changes()
 
605
        self.assertPushFails('to', '--strict')
 
606
 
 
607
    def test_push_strict_without_changes(self):
 
608
        tree = self.make_local_branch_and_tree()
 
609
        self.assertPushSucceeds('to', '--strict')
 
610
 
 
611
    def test_push_respect_config_var_strict(self):
 
612
        tree = self.make_local_branch_and_tree_with_changes()
 
613
        self.set_config_push_strict(tree, 'true')
 
614
        self.assertPushFails('to')
 
615
 
 
616
    def test_push_bogus_config_var_ignored(self):
 
617
        tree = self.make_local_branch_and_tree_with_changes()
 
618
        self.set_config_push_strict(tree, "I don't want you to be strict")
 
619
        self.assertPushSucceeds('to')
 
620
 
 
621
    def test_push_no_strict_command_line_override_config(self):
 
622
        tree = self.make_local_branch_and_tree_with_changes()
 
623
        self.set_config_push_strict(tree, 'yES')
 
624
        self.assertPushFails('to')
 
625
        self.assertPushSucceeds('to', '--no-strict')
 
626
 
 
627
    def test_push_strict_command_line_override_config(self):
 
628
        tree = self.make_local_branch_and_tree_with_changes()
 
629
        self.set_config_push_strict(tree, 'oFF')
 
630
        self.assertPushFails('to', '--strict')
 
631
        self.assertPushSucceeds('to')