100
100
super(TestSwitchHeavyweight, self).setUp()
101
101
self.lightweight = False
103
def test_switch_with_local_commits(self):
104
"""Test switch complains about local commits unless --force given."""
105
tree = self._setup_tree()
106
to_branch = tree.bzrdir.sprout('branch-2').open_branch()
107
self.build_tree(['branch-1/file-2'])
109
tree.remove('file-1')
111
checkout = tree.branch.create_checkout('checkout')
112
self.build_tree(['checkout/file-3'])
113
checkout.add('file-3')
114
checkout.commit(message='local only commit', local=True)
115
self.build_tree(['checkout/file-4'])
116
# Check the error reporting is as expected
117
err = self.assertRaises(errors.BzrCommandError,
118
switch.switch, checkout.bzrdir, to_branch)
119
self.assertContainsRe(str(err),
120
'Cannot switch as local commits found in the checkout.')
121
# Check all is ok when force is given
122
self.failIfExists('checkout/file-1')
123
self.failUnlessExists('checkout/file-2')
124
switch.switch(checkout.bzrdir, to_branch, force=True)
125
self.failUnlessExists('checkout/file-1')
126
self.failIfExists('checkout/file-2')
127
self.failIfExists('checkout/file-3')
128
self.failUnlessExists('checkout/file-4')
129
# Check that the checkout is a true mirror of the bound branch
130
missing_in_checkout = checkout.branch.missing_revisions(to_branch)
131
self.assertEqual([], missing_in_checkout)
132
missing_in_remote = to_branch.missing_revisions(checkout.branch)
133
self.assertEqual([], missing_in_remote)