~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-20 13:57:27 UTC
  • mfrom: (4633.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090820135727-pz56lf0l0tj6rbrn
(luks) Support for `bzr branch --switch`

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import os
21
21
 
22
 
from bzrlib import (branch, bzrdir, errors, repository)
 
22
from bzrlib import (
 
23
    branch,
 
24
    bzrdir,
 
25
    errors,
 
26
    repository,
 
27
    revision as _mod_revision,
 
28
    )
23
29
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
24
30
from bzrlib.tests.blackbox import ExternalBase
25
31
from bzrlib.tests import (
52
58
        self.assertFalse(b._transport.has('branch-name'))
53
59
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
54
60
 
 
61
    def test_branch_switch_no_branch(self):
 
62
        # No branch in the current directory:
 
63
        #  => new branch will be created, but switch fails
 
64
        self.example_branch('a')
 
65
        self.make_repository('current')
 
66
        self.run_bzr_error(['No WorkingTree exists for'],
 
67
            'branch --switch ../a ../b', working_dir='current')
 
68
        a = branch.Branch.open('a')
 
69
        b = branch.Branch.open('b')
 
70
        self.assertEqual(a.last_revision(), b.last_revision())
 
71
 
 
72
    def test_branch_switch_no_wt(self):
 
73
        # No working tree in the current directory:
 
74
        #  => new branch will be created, but switch fails and the current
 
75
        #     branch is unmodified
 
76
        self.example_branch('a')
 
77
        self.make_branch('current')
 
78
        self.run_bzr_error(['No WorkingTree exists for'],
 
79
            'branch --switch ../a ../b', working_dir='current')
 
80
        a = branch.Branch.open('a')
 
81
        b = branch.Branch.open('b')
 
82
        self.assertEqual(a.last_revision(), b.last_revision())
 
83
        work = branch.Branch.open('current')
 
84
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
 
85
 
 
86
    def test_branch_switch_no_checkout(self):
 
87
        # Standalone branch in the current directory:
 
88
        #  => new branch will be created, but switch fails and the current
 
89
        #     branch is unmodified
 
90
        self.example_branch('a')
 
91
        self.make_branch_and_tree('current')
 
92
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
 
93
            'branch --switch ../a ../b', working_dir='current')
 
94
        a = branch.Branch.open('a')
 
95
        b = branch.Branch.open('b')
 
96
        self.assertEqual(a.last_revision(), b.last_revision())
 
97
        work = branch.Branch.open('current')
 
98
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
 
99
 
 
100
    def test_branch_switch_checkout(self):
 
101
        # Checkout in the current directory:
 
102
        #  => new branch will be created and checkout bound to the new branch
 
103
        self.example_branch('a')
 
104
        self.run_bzr('checkout a current')
 
105
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
 
106
        a = branch.Branch.open('a')
 
107
        b = branch.Branch.open('b')
 
108
        self.assertEqual(a.last_revision(), b.last_revision())
 
109
        work = WorkingTree.open('current')
 
110
        self.assertEndsWith(work.branch.get_bound_location(), '/b/')
 
111
        self.assertContainsRe(err, "Switched to branch: .*/b/")
 
112
 
 
113
    def test_branch_switch_lightweight_checkout(self):
 
114
        # Lightweight checkout in the current directory:
 
115
        #  => new branch will be created and lightweight checkout pointed to
 
116
        #     the new branch
 
117
        self.example_branch('a')
 
118
        self.run_bzr('checkout --lightweight a current')
 
119
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
 
120
        a = branch.Branch.open('a')
 
121
        b = branch.Branch.open('b')
 
122
        self.assertEqual(a.last_revision(), b.last_revision())
 
123
        work = WorkingTree.open('current')
 
124
        self.assertEndsWith(work.branch.base, '/b/')
 
125
        self.assertContainsRe(err, "Switched to branch: .*/b/")
 
126
 
55
127
    def test_branch_only_copies_history(self):
56
128
        # Knit branches should only push the history for the current revision.
57
129
        format = bzrdir.BzrDirMetaFormat1()