1
# Copyright (C) 2007 Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
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
19
"""Tests for the switch command of bzr."""
23
from bzrlib.tests.blackbox import ExternalBase
26
class TestSwitch(ExternalBase):
28
def test_switch_up_to_date_light_checkout(self):
29
self.make_branch_and_tree('branch')
30
self.run_bzr('branch branch branch2')
31
self.run_bzr('checkout --lightweight branch checkout')
33
out, err = self.run_bzr('switch ../branch2')
34
self.assertContainsRe(err, 'Tree is up to date at revision 0.\n')
35
self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
36
self.assertEqual('', out)
38
def test_switch_out_of_date_light_checkout(self):
39
self.make_branch_and_tree('branch')
40
self.run_bzr('branch branch branch2')
41
self.build_tree(['branch2/file'])
42
self.run_bzr('add branch2/file')
43
self.run_bzr('commit -m add-file branch2')
44
self.run_bzr('checkout --lightweight branch checkout')
46
out, err = self.run_bzr('switch ../branch2')
47
#self.assertContainsRe(err, '\+N file')
48
self.assertContainsRe(err, 'Updated to revision 1.\n')
49
self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
50
self.assertEqual('', out)
52
def test_switch_finds_relative_branch(self):
53
"""Switch will find 'foo' relative to the branch that the checkout is of."""
54
self.build_tree(['repo/'])
55
tree1 = self.make_branch_and_tree('repo/brancha')
57
tree2 = self.make_branch_and_tree('repo/branchb')
58
tree2.pull(tree1.branch)
59
branchb_id = tree2.commit('bar')
60
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
61
self.run_bzr(['switch', 'branchb'], working_dir='checkout')
62
self.assertEqual(branchb_id, checkout.last_revision())
63
checkout = checkout.bzrdir.open_workingtree()
64
self.assertEqual(tree2.branch.base, checkout.branch.base)