~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-10 16:25:28 UTC
  • mfrom: (5020.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100210162528-00g29u0ex6vzv914
(gerard) Update performs two merges in a more logical order but stop
        on conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
from bzrlib import (
25
25
    branch,
 
26
    branchbuilder,
26
27
    bzrdir,
27
28
    errors,
28
29
    osutils,
949
950
            os.link = real_os_link
950
951
 
951
952
 
 
953
class TestWorkingTreeUpdate(TestCaseWithWorkingTree):
 
954
 
 
955
    def make_diverged_master_branch(self):
 
956
        """
 
957
        B: wt.branch.last_revision()
 
958
        M: wt.branch.get_master_branch().last_revision()
 
959
        W: wt.last_revision()
 
960
 
 
961
 
 
962
            1
 
963
            |\
 
964
          B-2 3
 
965
            | |
 
966
            4 5-M
 
967
            |
 
968
            W
 
969
         """
 
970
        builder = branchbuilder.BranchBuilder(
 
971
            self.get_transport(),
 
972
            format=self.workingtree_format._matchingbzrdir)
 
973
        builder.start_series()
 
974
        # mainline
 
975
        builder.build_snapshot(
 
976
            '1', None,
 
977
            [('add', ('', 'root-id', 'directory', '')),
 
978
             ('add', ('file1', 'file1-id', 'file', 'file1 content\n'))])
 
979
        # branch
 
980
        builder.build_snapshot('2', ['1'], [])
 
981
        builder.build_snapshot(
 
982
            '4', ['2'],
 
983
            [('add', ('file4', 'file4-id', 'file', 'file4 content\n'))])
 
984
        # master
 
985
        builder.build_snapshot('3', ['1'], [])
 
986
        builder.build_snapshot(
 
987
            '5', ['3'],
 
988
            [('add', ('file5', 'file5-id', 'file', 'file5 content\n'))])
 
989
        builder.finish_series()
 
990
        return builder, builder._branch.last_revision()
 
991
 
 
992
    def make_checkout_and_master(self, builder, wt_path, master_path, wt_revid,
 
993
                                 master_revid=None, branch_revid=None):
 
994
        """Build a lightweight checkout and its master branch."""
 
995
        if master_revid is None:
 
996
            master_revid = wt_revid
 
997
        if branch_revid is None:
 
998
            branch_revid = master_revid
 
999
        final_branch = builder.get_branch()
 
1000
        # The master branch
 
1001
        master = final_branch.bzrdir.sprout(master_path,
 
1002
                                            master_revid).open_branch()
 
1003
        # The checkout
 
1004
        wt = self.make_branch_and_tree(wt_path)
 
1005
        wt.pull(final_branch, stop_revision=wt_revid)
 
1006
        wt.branch.pull(final_branch, stop_revision=branch_revid, overwrite=True)
 
1007
        try:
 
1008
            wt.branch.bind(master)
 
1009
        except errors.UpgradeRequired:
 
1010
            raise TestNotApplicable(
 
1011
                "Can't bind %s" % wt.branch._format.__class__)
 
1012
        return wt, master
 
1013
 
 
1014
    def test_update_remove_commit(self):
 
1015
        """Update should remove revisions when the branch has removed
 
1016
        some commits.
 
1017
 
 
1018
        We want to revert 4, so that strating with the
 
1019
        make_diverged_master_branch() graph the final result should be
 
1020
        equivalent to:
 
1021
 
 
1022
           1
 
1023
           |\
 
1024
           3 2
 
1025
           | |\
 
1026
        MB-5 | 4
 
1027
           |/
 
1028
           W
 
1029
 
 
1030
        And the changes in 4 have been removed from the WT.
 
1031
        """
 
1032
        builder, tip = self.make_diverged_master_branch()
 
1033
        wt, master = self.make_checkout_and_master(
 
1034
            builder, 'checkout', 'master', '4',
 
1035
            master_revid=tip, branch_revid='2')
 
1036
        # First update the branch
 
1037
        old_tip = wt.branch.update()
 
1038
        self.assertEqual('2', old_tip)
 
1039
        # No conflicts should occur
 
1040
        self.assertEqual(0, wt.update(old_tip=old_tip))
 
1041
        # We are in sync with the master
 
1042
        self.assertEqual(tip, wt.branch.last_revision())
 
1043
        # We have the right parents ready to be committed
 
1044
        self.assertEqual(['5', '2'], wt.get_parent_ids())
 
1045
 
 
1046
    def test_update_revision(self):
 
1047
        builder, tip = self.make_diverged_master_branch()
 
1048
        wt, master = self.make_checkout_and_master(
 
1049
            builder, 'checkout', 'master', '4',
 
1050
            master_revid=tip, branch_revid='2')
 
1051
        self.assertEqual(0, wt.update(revision='1'))
 
1052
        self.assertEqual('1', wt.last_revision())
 
1053
        self.assertEqual(tip, wt.branch.last_revision())
 
1054
        self.failUnlessExists('checkout/file1')
 
1055
        self.failIfExists('checkout/file4')
 
1056
        self.failIfExists('checkout/file5')
 
1057
 
 
1058
 
952
1059
class TestIllegalPaths(TestCaseWithWorkingTree):
953
1060
 
954
1061
    def test_bad_fs_path(self):