1
# Copyright (C) 2007-2011 Canonical Ltd
1
# Copyright (C) 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
53
47
lightweight=self.lightweight)
54
48
self.build_tree(['checkout/file-3'])
55
49
checkout.add('file-3')
56
self.assertPathDoesNotExist('checkout/file-1')
57
self.assertPathExists('checkout/file-2')
50
self.failIfExists('checkout/file-1')
51
self.failUnlessExists('checkout/file-2')
58
52
switch.switch(checkout.bzrdir, to_branch)
59
self.assertPathExists('checkout/file-1')
60
self.assertPathDoesNotExist('checkout/file-2')
61
self.assertPathExists('checkout/file-3')
53
self.failUnlessExists('checkout/file-1')
54
self.failIfExists('checkout/file-2')
55
self.failUnlessExists('checkout/file-3')
63
57
def test_switch_after_branch_moved(self):
64
58
"""Test switch after the branch is moved."""
84
78
'Unable to connect to current master branch .*'
85
79
'To switch anyway, use --force.')
86
80
switch.switch(checkout.bzrdir, to_branch, force=True)
87
self.assertPathDoesNotExist('checkout/file-1')
88
self.assertPathExists('checkout/file-2')
89
self.assertPathExists('checkout/file-3')
81
self.failIfExists('checkout/file-1')
82
self.failUnlessExists('checkout/file-2')
83
self.failUnlessExists('checkout/file-3')
91
85
def test_switch_when_pending_merges(self):
92
86
"""Test graceful failure if pending merges are outstanding."""
118
112
tree.commit(rev_id='rev2', message='rev2')
119
113
# Check it out and switch to revision 1
120
114
checkout = tree.branch.create_checkout('checkout',
121
lightweight=self.lightweight)
115
lightweight=self.lightweight)
122
116
switch.switch(checkout.bzrdir, tree.branch, revision_id="rev1")
123
self.assertPathExists('checkout/file-1')
124
self.assertPathDoesNotExist('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)
117
self.failUnlessExists('checkout/file-1')
118
self.failIfExists('checkout/file-2')
157
121
class TestSwitchHeavyweight(TestSwitch):
179
143
self.assertContainsRe(str(err),
180
144
'Cannot switch as local commits found in the checkout.')
181
145
# Check all is ok when force is given
182
self.assertPathDoesNotExist('checkout/file-1')
183
self.assertPathExists('checkout/file-2')
146
self.failIfExists('checkout/file-1')
147
self.failUnlessExists('checkout/file-2')
184
148
switch.switch(checkout.bzrdir, to_branch, force=True)
185
self.assertPathExists('checkout/file-1')
186
self.assertPathDoesNotExist('checkout/file-2')
187
self.assertPathDoesNotExist('checkout/file-3')
188
self.assertPathExists('checkout/file-4')
149
self.failUnlessExists('checkout/file-1')
150
self.failIfExists('checkout/file-2')
151
self.failIfExists('checkout/file-3')
152
self.failUnlessExists('checkout/file-4')
189
153
# Check that the checkout is a true mirror of the bound branch
190
154
self.assertEqual(to_branch.last_revision_info(),
191
155
checkout.branch.last_revision_info())