13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Tests for bzrlib.switch."""
22
from bzrlib import branch, errors, switch, tests
31
25
class TestSwitch(tests.TestCaseWithTransport):
76
70
os.rename('branch-1', 'branch-2')
77
71
to_branch = branch.Branch.open('branch-2')
78
72
# Check fails without --force
79
err = self.assertRaises(
80
(errors.BzrCommandError, errors.NotBranchError),
73
err = self.assertRaises((errors.NotBranchError,
74
errors.BoundBranchConnectionFailure),
81
75
switch.switch, checkout.bzrdir, to_branch)
82
if isinstance(err, errors.BzrCommandError):
83
self.assertContainsRe(str(err),
84
'Unable to connect to current master branch .*'
85
'To switch anyway, use --force.')
86
76
switch.switch(checkout.bzrdir, to_branch, force=True)
87
77
self.failIfExists('checkout/file-1')
88
78
self.failUnlessExists('checkout/file-2')
106
96
self.assertContainsRe(str(err),
107
97
"Pending merges must be committed or reverted before using switch")
109
def test_switch_with_revision(self):
110
"""Test switch when a revision is given."""
111
# Create a tree with 2 revisions
112
tree = self.make_branch_and_tree('branch-1')
113
self.build_tree(['branch-1/file-1'])
115
tree.commit(rev_id='rev1', message='rev1')
116
self.build_tree(['branch-1/file-2'])
118
tree.commit(rev_id='rev2', message='rev2')
119
# Check it out and switch to revision 1
120
checkout = tree.branch.create_checkout('checkout',
121
lightweight=self.lightweight)
122
switch.switch(checkout.bzrdir, tree.branch, revision_id="rev1")
123
self.failUnlessExists('checkout/file-1')
124
self.failIfExists('checkout/file-2')
126
def test_switch_changing_root_id(self):
127
tree = self._setup_tree()
128
tree2 = self.make_branch_and_tree('tree-2')
129
tree2.set_root_id('custom-root-id')
130
self.build_tree(['tree-2/file-2'])
131
tree2.add(['file-2'])
132
tree2.commit('rev1b')
133
checkout = tree.branch.create_checkout('checkout',
134
lightweight=self.lightweight)
135
switch.switch(checkout.bzrdir, tree2.branch)
136
self.assertEqual('custom-root-id', tree2.get_root_id())
138
def test_switch_configurable_file_merger(self):
139
class DummyMerger(_mod_merge.ConfigurableFileMerger):
142
_mod_merge.Merger.hooks.install_named_hook(
143
'merge_file_content', DummyMerger,
145
foo = self.make_branch('foo')
146
checkout = foo.create_checkout('checkout', lightweight=True)
147
self.build_tree_contents([('checkout/file', 'a')])
150
bar = foo.bzrdir.sprout('bar').open_workingtree()
151
self.build_tree_contents([('bar/file', 'b')])
153
self.build_tree_contents([('checkout/file', 'c')])
154
switch.switch(checkout.bzrdir, bar.branch)
157
100
class TestSwitchHeavyweight(TestSwitch):