22
from bzrlib import (branch, bzrdir, repository)
22
from bzrlib import (branch, bzrdir, errors, repository)
23
23
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
24
24
from bzrlib.tests.blackbox import ExternalBase
25
25
from bzrlib.tests import HardlinkFeature
130
130
repo = bzrdir.BzrDir.open(repo_path).open_repository()
131
131
self.assertFalse(repo.has_revision(revid))
133
def test_branch_stacked_branch_also_stacked_same_reference(self):
133
def assertRevisionsInBranchRepository(self, revid_list, branch_path):
134
repo = branch.Branch.open(branch_path).repository
135
self.assertEqual(set(revid_list),
136
repo.has_revisions(revid_list))
138
def test_branch_stacked_branch_not_stacked(self):
139
"""Branching a stacked branch is not stacked by default"""
134
140
# We have a mainline
135
141
trunk_tree = self.make_branch_and_tree('target',
136
142
format='development')
146
152
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
147
153
self.assertEqual('', out)
154
self.assertEqual('Branched 1 revision(s).\n',
156
self.assertRaises(errors.NotStacked,
157
bzrdir.BzrDir.open('newbranch').open_branch().get_stacked_on_url)
159
def test_branch_stacked_branch_stacked(self):
160
"""Asking to stack on a stacked branch does work"""
162
trunk_tree = self.make_branch_and_tree('target',
163
format='development')
164
trunk_revid = trunk_tree.commit('mainline')
165
# and a branch from it which is stacked
166
branch_tree = self.make_branch_and_tree('branch',
167
format='development')
168
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
169
# with some work on it
170
branch_revid = branch_tree.commit('moar work plz')
171
# you can chain branches on from there
172
out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
173
self.assertEqual('', out)
148
174
self.assertEqual('Created new stacked branch referring to %s.\n' %
149
trunk_tree.branch.base, err)
150
self.check_shallow_branch(branch_tree.last_revision(),
151
trunk_tree.branch.base)
175
branch_tree.branch.base, err)
176
self.assertEqual(branch_tree.branch.base,
177
branch.Branch.open('branch2').get_stacked_on_url())
178
branch2_tree = WorkingTree.open('branch2')
179
branch2_revid = branch2_tree.commit('work on second stacked branch')
180
self.assertRevisionInRepository('branch2', branch2_revid)
181
self.assertRevisionsInBranchRepository(
182
[trunk_revid, branch_revid, branch2_revid],
153
185
def test_branch_stacked(self):
154
186
# We have a mainline