~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: 2009-06-10 12:38:51 UTC
  • mto: (4452.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4453.
  • Revision ID: v.ladeuil+lp@free.fr-20090610123851-ftix8vy3p054jlwn
Fix bug #284038 by adding a --strict option to push.

* tests/branch_implementations/test_push.py:
(EmptyPushSmartEffortTests.test_empty_branch_command): Fix
semi-unrelated get_url() misuse.

* tests/blackbox/test_push.py:
(TestPushRedirect.test_push_gracefully_handles_too_many_redirects):
Test push command behavior with respect to uncommitted changes and
--strict option.

* builtins.py:
(cmd_push): Add a '--strict' option to check uncommitted changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
530
530
             % re.escape(destination_url)],
531
531
            ['push', '-d', 'tree', destination_url], retcode=3)
532
532
        self.assertEqual('', out)
 
533
 
 
534
 
 
535
class TestPushStrict(tests.TestCaseWithTransport):
 
536
 
 
537
    def make_local_branch_and_tree(self):
 
538
        tree = self.make_branch_and_tree('local')
 
539
        self.build_tree_contents([('local/file', 'initial')])
 
540
        tree.add('file')
 
541
        tree.commit('adding file', rev_id='from-1')
 
542
        return tree
 
543
 
 
544
    def assertTreePushed(self, relpath):
 
545
        tree_to = workingtree.WorkingTree.open(relpath)
 
546
        repo_to = tree_to.branch.repository
 
547
        self.assertTrue(repo_to.has_revision('from-1'))
 
548
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
 
549
 
 
550
    def test_push_default(self):
 
551
        tree = self.make_local_branch_and_tree()
 
552
        # Make some changes
 
553
        self.build_tree_contents([('local/file', 'modified')])
 
554
        # Push with some uncommitted changes works
 
555
        self.run_bzr(['push', '../to'], working_dir='local')
 
556
        self.assertTreePushed('to')
 
557
 
 
558
    def test_push_strict_with_changes(self):
 
559
        tree = self.make_local_branch_and_tree()
 
560
        # Make some changes
 
561
        self.build_tree_contents([('local/file', 'modified')])
 
562
        # Push with some uncommitted changes fails
 
563
        self.run_bzr_error(['Working tree ".*/local/"'
 
564
                            ' has uncommitted changes.$',],
 
565
                           ['push', '--strict', '../to'],
 
566
                           working_dir='local', retcode=3)
 
567
 
 
568
    def test_push_strict_without_changes(self):
 
569
        tree = self.make_local_branch_and_tree()
 
570
        self.run_bzr(['push', '--strict', '../to'], working_dir='local')
 
571
        self.assertTreePushed('to')
 
572
 
 
573
    def test_push_respect_config_var(self):
 
574
        tree = self.make_local_branch_and_tree()
 
575
        # Make some changes
 
576
        self.build_tree_contents([('local/file', 'modified')])
 
577
        # set config var (any of bazaar.conf, locations.conf, branch.conf
 
578
        # should do)
 
579
        conf = tree.branch.get_config()
 
580
        conf.set_user_option('push_strict', 'true')
 
581
        # Push --strict (inherited from config) with some uncommitted changes
 
582
        # fails
 
583
        self.run_bzr_error(['Working tree ".*/local/"'
 
584
                            ' has uncommitted changes.$',],
 
585
                           ['push', '../to'],
 
586
                           working_dir='local', retcode=3)
 
587
 
 
588
    def test_push_command_line_override_config(self):
 
589
        tree = self.make_local_branch_and_tree()
 
590
        # Make some changes
 
591
        self.build_tree_contents([('local/file', 'modified')])
 
592
        # set config var (any of bazaar.conf, locations.conf, branch.conf
 
593
        # should do)
 
594
        conf = tree.branch.get_config()
 
595
        conf.set_user_option('push_strict', 'true')
 
596
        self.run_bzr(['push', '--no-strict', '../to'], working_dir='local')
 
597
        self.assertTreePushed('to')