~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_switch.py

  • Committer: Ian Clatworthy
  • Date: 2007-11-22 04:31:28 UTC
  • mto: (3015.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3016.
  • Revision ID: ian.clatworthy@internode.on.net-20071122043128-bjlhladklqlmfo4d
fix pending merge detection and test

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
class TestSwitch(tests.TestCaseWithTransport):
26
26
 
27
 
    def test_switch_moved(self):
 
27
    def _setup_tree(self):
28
28
        tree = self.make_branch_and_tree('branch-1')
29
29
        self.build_tree(['branch-1/file-1'])
30
30
        tree.add('file-1')
31
31
        tree.commit('rev1')
32
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
33
 
        self.build_tree(['branch-1/file-2'])
34
 
        tree.add('file-2')
35
 
        tree.remove('file-1')
36
 
        tree.commit('rev2')
37
 
        os.rename('branch-1', 'branch-2')
38
 
        to_branch = branch.Branch.open('branch-2')
39
 
        self.build_tree(['checkout/file-3'])
40
 
        checkout.add('file-3')
41
 
        switch.switch(checkout.bzrdir, to_branch)
42
 
        self.failIfExists('checkout/file-1')
43
 
        self.failUnlessExists('checkout/file-2')
44
 
        self.failUnlessExists('checkout/file-3')
 
32
        return tree
45
33
 
46
 
    def test_switch_old(self):
47
 
        tree = self.make_branch_and_tree('branch-1')
48
 
        self.build_tree(['branch-1/file-1'])
49
 
        tree.add('file-1')
50
 
        tree.commit('rev1')
 
34
    def test_switch_updates(self):
 
35
        """Test switch updates tree and keeps uncommitted changes."""
 
36
        tree = self._setup_tree()
51
37
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
52
38
        self.build_tree(['branch-1/file-2'])
53
39
        tree.add('file-2')
63
49
        self.failIfExists('checkout/file-2')
64
50
        self.failUnlessExists('checkout/file-3')
65
51
 
66
 
    def test_switch_heavy_checkout(self):
67
 
        tree = self.make_branch_and_tree('branch-1')
68
 
        self.build_tree(['branch-1/file-1'])
69
 
        tree.add('file-1')
70
 
        tree.commit('rev1')
71
 
        tree.branch.create_checkout('checkout-1', lightweight=False)
 
52
    def test_switch_after_branch_moved(self):
 
53
        """Test switch after the branch is moved."""
 
54
        tree = self._setup_tree()
 
55
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
56
        self.build_tree(['branch-1/file-2'])
 
57
        tree.add('file-2')
 
58
        tree.remove('file-1')
 
59
        tree.commit('rev2')
 
60
        os.rename('branch-1', 'branch-2')
 
61
        to_branch = branch.Branch.open('branch-2')
 
62
        self.build_tree(['checkout/file-3'])
 
63
        checkout.add('file-3')
 
64
        switch.switch(checkout.bzrdir, to_branch)
 
65
        self.failIfExists('checkout/file-1')
 
66
        self.failUnlessExists('checkout/file-2')
 
67
        self.failUnlessExists('checkout/file-3')
 
68
 
 
69
    def test_switch_on_heavy_checkout(self):
 
70
        """Test graceful failure on heavyweight checkouts."""
 
71
        tree = self._setup_tree()
 
72
        checkout = tree.branch.create_checkout('checkout-1', lightweight=False)
72
73
        branch2 = self.make_branch('branch-2')
73
74
        err = self.assertRaises(errors.BzrCommandError,
74
 
                                switch.switch, tree.bzrdir, branch2)
 
75
            switch.switch, checkout.bzrdir, branch2)
75
76
        self.assertContainsRe(str(err),
76
77
            "The switch command can only be used on a lightweight checkout")
 
78
 
 
79
    def test_switch_when_pending_merges(self):
 
80
        """Test graceful failure if pending merges are outstanding."""
 
81
        # Create 2 branches and a checkout
 
82
        tree = self._setup_tree()
 
83
        tree2 = tree.bzrdir.sprout('branch-2').open_workingtree()
 
84
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
85
        # Change tree2 and merge it into the checkout without committing
 
86
        self.build_tree(['branch-2/file-2'])
 
87
        tree2.add('file-2')
 
88
        tree2.commit('rev2')
 
89
        checkout.merge_from_branch(tree2.branch)
 
90
        # Check the error reporting is as expected
 
91
        err = self.assertRaises(errors.BzrCommandError,
 
92
            switch.switch, checkout.bzrdir, tree2.branch)
 
93
        self.assertContainsRe(str(err),
 
94
            "Pending merges must be committed or reverted before using switch")