52
58
self.assertFalse(b._transport.has('branch-name'))
53
59
b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
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())
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)
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)
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/")
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
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/")
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()