1
# Copyright (C) 2007 Canonical Ltd
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.
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.
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
17
"""Tests for the BranchBuilder class."""
20
branch as _mod_branch,
21
revision as _mod_revision,
24
from bzrlib.branchbuilder import BranchBuilder
27
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
29
def test_create(self):
30
"""Test the constructor api."""
31
builder = BranchBuilder(self.get_transport().clone('foo'))
32
# we dont care if the branch has been built or not at this point.
34
def test_get_branch(self):
35
"""get_branch returns the created branch."""
36
builder = BranchBuilder(self.get_transport().clone('foo'))
37
branch = builder.get_branch()
38
self.assertIsInstance(branch, _mod_branch.Branch)
39
self.assertEqual(self.get_transport().clone('foo').base,
42
(0, _mod_revision.NULL_REVISION),
43
branch.last_revision_info())
45
def test_format(self):
46
"""Making a BranchBuilder with a format option sets the branch type."""
47
builder = BranchBuilder(self.get_transport(), format='dirstate-tags')
48
branch = builder.get_branch()
49
self.assertIsInstance(branch, _mod_branch.BzrBranch6)
51
def test_build_one_commit(self):
52
"""doing build_commit causes a commit to happen."""
53
builder = BranchBuilder(self.get_transport().clone('foo'))
54
rev_id = builder.build_commit()
55
branch = builder.get_branch()
56
self.assertEqual((1, rev_id), branch.last_revision_info())
59
branch.repository.get_revision(branch.last_revision()).message)
61
def test_build_two_commits(self):
62
"""The second commit has the right parents and message."""
63
builder = BranchBuilder(self.get_transport().clone('foo'))
64
rev_id1 = builder.build_commit()
65
rev_id2 = builder.build_commit()
66
branch = builder.get_branch()
67
self.assertEqual((2, rev_id2), branch.last_revision_info())
70
branch.repository.get_revision(branch.last_revision()).message)
73
branch.repository.get_revision(branch.last_revision()).parent_ids)