~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

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,
235
236
        revid = b.revision_history()[0]
236
237
        self.log('first revision_id is {%s}' % revid)
237
238
 
238
 
        inv = b.repository.get_revision_inventory(revid)
 
239
        inv = b.repository.get_inventory(revid)
239
240
        self.log('contents of inventory: %r' % inv.entries())
240
241
 
241
242
        self.check_inventory_shape(inv,
422
423
        made_control = self.bzrdir_format.initialize('new')
423
424
        source.branch.repository.clone(made_control)
424
425
        source.branch.clone(made_control)
425
 
        made_tree = self.workingtree_format.initialize(made_control, revision_id='a')
 
426
        made_tree = self.workingtree_format.initialize(made_control,
 
427
            revision_id='a')
426
428
        self.assertEqual(['a'], made_tree.get_parent_ids())
427
429
 
428
430
    def test_update_sets_last_revision(self):
446
448
        # current format
447
449
        self.build_tree(['checkout/', 'tree/file'])
448
450
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
449
 
        branch.BranchReferenceFormat().initialize(checkout, main_branch)
 
451
        branch.BranchReferenceFormat().initialize(checkout,
 
452
            target_branch=main_branch)
450
453
        old_tree = self.workingtree_format.initialize(checkout)
451
454
        # now commit to 'tree'
452
455
        wt.add('file')
513
516
        # current format
514
517
        self.build_tree(['checkout/', 'tree/file'])
515
518
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
516
 
        branch.BranchReferenceFormat().initialize(checkout, main_branch)
 
519
        branch.BranchReferenceFormat().initialize(checkout,
 
520
            target_branch=main_branch)
517
521
        old_tree = self.workingtree_format.initialize(checkout)
518
522
        # now commit to 'tree'
519
523
        wt.add('file')
949
953
            os.link = real_os_link
950
954
 
951
955
 
 
956
class TestWorkingTreeUpdate(TestCaseWithWorkingTree):
 
957
 
 
958
    def make_diverged_master_branch(self):
 
959
        """
 
960
        B: wt.branch.last_revision()
 
961
        M: wt.branch.get_master_branch().last_revision()
 
962
        W: wt.last_revision()
 
963
 
 
964
 
 
965
            1
 
966
            |\
 
967
          B-2 3
 
968
            | |
 
969
            4 5-M
 
970
            |
 
971
            W
 
972
         """
 
973
        builder = branchbuilder.BranchBuilder(
 
974
            self.get_transport(),
 
975
            format=self.workingtree_format._matchingbzrdir)
 
976
        builder.start_series()
 
977
        # mainline
 
978
        builder.build_snapshot(
 
979
            '1', None,
 
980
            [('add', ('', 'root-id', 'directory', '')),
 
981
             ('add', ('file1', 'file1-id', 'file', 'file1 content\n'))])
 
982
        # branch
 
983
        builder.build_snapshot('2', ['1'], [])
 
984
        builder.build_snapshot(
 
985
            '4', ['2'],
 
986
            [('add', ('file4', 'file4-id', 'file', 'file4 content\n'))])
 
987
        # master
 
988
        builder.build_snapshot('3', ['1'], [])
 
989
        builder.build_snapshot(
 
990
            '5', ['3'],
 
991
            [('add', ('file5', 'file5-id', 'file', 'file5 content\n'))])
 
992
        builder.finish_series()
 
993
        return builder, builder._branch.last_revision()
 
994
 
 
995
    def make_checkout_and_master(self, builder, wt_path, master_path, wt_revid,
 
996
                                 master_revid=None, branch_revid=None):
 
997
        """Build a lightweight checkout and its master branch."""
 
998
        if master_revid is None:
 
999
            master_revid = wt_revid
 
1000
        if branch_revid is None:
 
1001
            branch_revid = master_revid
 
1002
        final_branch = builder.get_branch()
 
1003
        # The master branch
 
1004
        master = final_branch.bzrdir.sprout(master_path,
 
1005
                                            master_revid).open_branch()
 
1006
        # The checkout
 
1007
        wt = self.make_branch_and_tree(wt_path)
 
1008
        wt.pull(final_branch, stop_revision=wt_revid)
 
1009
        wt.branch.pull(final_branch, stop_revision=branch_revid, overwrite=True)
 
1010
        try:
 
1011
            wt.branch.bind(master)
 
1012
        except errors.UpgradeRequired:
 
1013
            raise TestNotApplicable(
 
1014
                "Can't bind %s" % wt.branch._format.__class__)
 
1015
        return wt, master
 
1016
 
 
1017
    def test_update_remove_commit(self):
 
1018
        """Update should remove revisions when the branch has removed
 
1019
        some commits.
 
1020
 
 
1021
        We want to revert 4, so that strating with the
 
1022
        make_diverged_master_branch() graph the final result should be
 
1023
        equivalent to:
 
1024
 
 
1025
           1
 
1026
           |\
 
1027
           3 2
 
1028
           | |\
 
1029
        MB-5 | 4
 
1030
           |/
 
1031
           W
 
1032
 
 
1033
        And the changes in 4 have been removed from the WT.
 
1034
        """
 
1035
        builder, tip = self.make_diverged_master_branch()
 
1036
        wt, master = self.make_checkout_and_master(
 
1037
            builder, 'checkout', 'master', '4',
 
1038
            master_revid=tip, branch_revid='2')
 
1039
        # First update the branch
 
1040
        old_tip = wt.branch.update()
 
1041
        self.assertEqual('2', old_tip)
 
1042
        # No conflicts should occur
 
1043
        self.assertEqual(0, wt.update(old_tip=old_tip))
 
1044
        # We are in sync with the master
 
1045
        self.assertEqual(tip, wt.branch.last_revision())
 
1046
        # We have the right parents ready to be committed
 
1047
        self.assertEqual(['5', '2'], wt.get_parent_ids())
 
1048
 
 
1049
    def test_update_revision(self):
 
1050
        builder, tip = self.make_diverged_master_branch()
 
1051
        wt, master = self.make_checkout_and_master(
 
1052
            builder, 'checkout', 'master', '4',
 
1053
            master_revid=tip, branch_revid='2')
 
1054
        self.assertEqual(0, wt.update(revision='1'))
 
1055
        self.assertEqual('1', wt.last_revision())
 
1056
        self.assertEqual(tip, wt.branch.last_revision())
 
1057
        self.failUnlessExists('checkout/file1')
 
1058
        self.failIfExists('checkout/file4')
 
1059
        self.failIfExists('checkout/file5')
 
1060
 
 
1061
 
952
1062
class TestIllegalPaths(TestCaseWithWorkingTree):
953
1063
 
954
1064
    def test_bad_fs_path(self):