~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_switch.py

  • Committer: Ian Clatworthy
  • Date: 2007-11-16 01:19:16 UTC
  • mto: (3015.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3016.
  • Revision ID: ian.clatworthy@internode.on.net-20071116011916-cqzuyhp8vwsmyhyo
migrate switch command into the core - was in BzrTools

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Tests for bzrlib.switch."""
 
18
 
 
19
 
 
20
import os
 
21
 
 
22
from bzrlib import branch, errors, switch, tests
 
23
 
 
24
 
 
25
class TestSwitch(tests.TestCaseWithTransport):
 
26
 
 
27
    def test_switch_moved(self):
 
28
        tree = self.make_branch_and_tree('branch-1')
 
29
        self.build_tree(['branch-1/file-1'])
 
30
        tree.add('file-1')
 
31
        tree.commit('rev1')
 
32
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
33
        self.build_tree(['branch-1/file-2'])
 
34
        tree.add('file-2')
 
35
        tree.remove('file-1')
 
36
        tree.commit('rev2')
 
37
        os.rename('branch-1', 'branch-2')
 
38
        to_branch = branch.Branch.open('branch-2')
 
39
        self.build_tree(['checkout/file-3'])
 
40
        checkout.add('file-3')
 
41
        switch.switch(checkout.bzrdir, to_branch)
 
42
        self.failIfExists('checkout/file-1')
 
43
        self.failUnlessExists('checkout/file-2')
 
44
        self.failUnlessExists('checkout/file-3')
 
45
 
 
46
    def test_switch_old(self):
 
47
        tree = self.make_branch_and_tree('branch-1')
 
48
        self.build_tree(['branch-1/file-1'])
 
49
        tree.add('file-1')
 
50
        tree.commit('rev1')
 
51
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
 
52
        self.build_tree(['branch-1/file-2'])
 
53
        tree.add('file-2')
 
54
        tree.remove('file-1')
 
55
        tree.commit('rev2')
 
56
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
57
        self.build_tree(['checkout/file-3'])
 
58
        checkout.add('file-3')
 
59
        self.failIfExists('checkout/file-1')
 
60
        self.failUnlessExists('checkout/file-2')
 
61
        switch.switch(checkout.bzrdir, to_branch)
 
62
        self.failUnlessExists('checkout/file-1')
 
63
        self.failIfExists('checkout/file-2')
 
64
        self.failUnlessExists('checkout/file-3')
 
65
 
 
66
    def test_switch_heavy_checkout(self):
 
67
        tree = self.make_branch_and_tree('branch-1')
 
68
        self.build_tree(['branch-1/file-1'])
 
69
        tree.add('file-1')
 
70
        tree.commit('rev1')
 
71
        tree.branch.create_checkout('checkout-1', lightweight=False)
 
72
        branch2 = self.make_branch('branch-2')
 
73
        err = self.assertRaises(errors.BzrCommandError,
 
74
                                switch.switch, tree.bzrdir, branch2)
 
75
        self.assertContainsRe(str(err),
 
76
            "The switch command can only be used on a lightweight checkout")