1
# Copyright (C) 2006 by 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 repository commit builder."""
19
from bzrlib.errors import UnsupportedOperation
20
from bzrlib.repository import CommitBuilder
21
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
24
class TestCommitBuilder(TestCaseWithRepository):
26
def test_get_commit_builder(self):
27
tree = self.make_branch_and_tree(".")
28
builder = tree.branch.get_commit_builder([])
29
self.assertIsInstance(builder, CommitBuilder)
31
def test_finish_inventory(self):
32
tree = self.make_branch_and_tree(".")
33
builder = tree.branch.get_commit_builder([])
34
builder.finish_inventory()
36
def test_commit_message(self):
37
tree = self.make_branch_and_tree(".")
38
builder = tree.branch.get_commit_builder([])
39
builder.finish_inventory()
40
rev_id = builder.commit('foo bar blah')
41
rev = tree.branch.repository.get_revision(rev_id)
42
self.assertEqual('foo bar blah', rev.message)
44
def test_commit_with_revision_id(self):
45
tree = self.make_branch_and_tree(".")
47
builder = tree.branch.get_commit_builder([], revision_id="foo")
48
except UnsupportedOperation:
49
# This format doesn't support supplied revision ids
51
builder.finish_inventory()
52
self.assertEqual("foo", builder.commit('foo bar'))
53
self.assertTrue(tree.branch.repository.has_revision("foo"))
54
# the revision id must be set on the inventory when saving it. This does not
55
# precisely test that - a repository that wants to can add it on deserialisation,
56
# but thats all the current contract guarantees anyway.
57
self.assertEqual('foo', tree.branch.repository.get_inventory('foo').revision_id)
59
def test_commit(self):
60
tree = self.make_branch_and_tree(".")
61
builder = tree.branch.get_commit_builder([])
62
builder.finish_inventory()
63
rev_id = builder.commit('foo bar')
64
self.assertNotEqual(None, rev_id)
65
self.assertTrue(tree.branch.repository.has_revision(rev_id))
66
# the revision id must be set on the inventory when saving it. This does not
67
# precisely test that - a repository that wants to can add it on deserialisation,
68
# but thats all the current contract guarantees anyway.
69
self.assertEqual(rev_id, tree.branch.repository.get_inventory(rev_id).revision_id)