14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
"""Tests for the switch command of bzr."""
133
133
self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
134
134
self.assertEqual(branchb_id, checkout.last_revision())
135
135
self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
137
def prepare_lightweight_switch(self):
138
branch = self.make_branch('branch')
139
branch.create_checkout('tree', lightweight=True)
140
os.rename('branch', 'branch1')
142
def test_switch_lightweight_after_branch_moved(self):
143
self.prepare_lightweight_switch()
144
self.run_bzr('switch --force ../branch1', working_dir='tree')
145
branch_location = WorkingTree.open('tree').branch.base
146
self.assertEndsWith(branch_location, 'branch1/')
148
def test_switch_lightweight_after_branch_moved_relative(self):
149
self.prepare_lightweight_switch()
150
self.run_bzr('switch --force branch1', working_dir='tree')
151
branch_location = WorkingTree.open('tree').branch.base
152
self.assertEndsWith(branch_location, 'branch1/')
154
def test_create_branch_no_branch(self):
155
self.prepare_lightweight_switch()
156
self.run_bzr_error(['cannot create branch without source branch'],
157
'switch --create-branch ../branch2', working_dir='tree')
159
def test_create_branch(self):
160
branch = self.make_branch('branch')
161
tree = branch.create_checkout('tree', lightweight=True)
162
tree.commit('one', rev_id='rev-1')
163
self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
164
tree = WorkingTree.open('tree')
165
self.assertEndsWith(tree.branch.base, '/branch2/')
167
def test_create_branch_local(self):
168
branch = self.make_branch('branch')
169
tree = branch.create_checkout('tree', lightweight=True)
170
tree.commit('one', rev_id='rev-1')
171
self.run_bzr('switch --create-branch branch2', working_dir='tree')
172
tree = WorkingTree.open('tree')
173
# The new branch should have been created at the same level as
174
# 'branch', because we did not have a '/' segment
175
self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
177
def test_create_branch_short_name(self):
178
branch = self.make_branch('branch')
179
tree = branch.create_checkout('tree', lightweight=True)
180
tree.commit('one', rev_id='rev-1')
181
self.run_bzr('switch -b branch2', working_dir='tree')
182
tree = WorkingTree.open('tree')
183
# The new branch should have been created at the same level as
184
# 'branch', because we did not have a '/' segment
185
self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)