/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2999.1.4 by Ian Clatworthy
more review tweaks including commit of blackbox tests
1
# Copyright (C) 2007 Canonical Ltd
2
# -*- coding: utf-8 -*-
3
#
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.
8
#
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.
13
#
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
17
18
19
"""Tests for the switch command of bzr."""
20
21
import os
22
23
from bzrlib.tests.blackbox import ExternalBase
24
25
26
class TestSwitch(ExternalBase):
27
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')
32
        os.chdir('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)
37
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')
45
        os.chdir('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)
3246.5.1 by Robert Collins
* ``bzr switch`` will attempt to find branches to switch to relative to the
51
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')
56
        tree1.commit('foo')
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)
3602.3.1 by Adrian Wilkins
Test that `bzr switch` finds the sibling of the bound branch of heavy checkout.
65
66
    def test_switch_finds_relative_bound_branch(self):
3602.3.4 by Adrian Wilkins
Improved comments and documentation
67
        """Using switch on a heavy checkout should find master sibling
68
69
        The behaviour of lighweight and heavy checkouts should be 
70
        consistentwhen using the convenient "switch to sibling" feature
71
        Both should switch to a sibling of the branch
72
        they are bound to, and not a sibling of themself"""
73
3602.3.1 by Adrian Wilkins
Test that `bzr switch` finds the sibling of the bound branch of heavy checkout.
74
        self.build_tree(['repo/',
75
                         'heavyco/'])
76
        tree1 = self.make_branch_and_tree('repo/brancha')
77
        tree1.commit('foo')
78
        tree2 = self.make_branch_and_tree('repo/branchb')
79
        tree2.pull(tree1.branch)
80
        branchb_id = tree2.commit('bar')
81
        checkout = tree1.branch.create_checkout('heavyco/a', lightweight=False)
82
        self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
83
        self.assertEqual(branchb_id, checkout.last_revision())
84
        self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())