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 contract of commit on branches."""
19
from bzrlib.branch import Branch
20
from bzrlib import errors
21
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
22
from bzrlib.revision import NULL_REVISION
23
from bzrlib.transport import get_transport
26
class TestCommit(TestCaseWithBranch):
28
def test_commit_nicks(self):
29
"""Nicknames are committed to the revision"""
30
get_transport(self.get_url()).mkdir('bzr.dev')
31
wt = self.make_branch_and_tree('bzr.dev')
33
branch.nick = "My happy branch"
34
wt.commit('My commit respect da nick.')
35
committed = branch.repository.get_revision(branch.last_revision())
36
self.assertEqual(committed.properties["branch-nick"],
40
class TestCommitHook(TestCaseWithBranch):
44
TestCaseWithBranch.setUp(self)
46
def capture_post_commit_hook(self, local, master, old_revno,
47
old_revid, new_revno, new_revid):
48
"""Capture post commit hook calls to self.hook_calls.
50
The call is logged, as is some state of the two branches.
53
local_locked = local.is_locked()
54
local_base = local.base
58
self.hook_calls.append(
59
('post_commit', local_base, master.base, old_revno, old_revid,
60
new_revno, new_revid, local_locked, master.is_locked()))
62
def test_post_commit_to_origin(self):
63
tree = self.make_branch_and_memory_tree('branch')
64
Branch.hooks.install_hook('post_commit',
65
self.capture_post_commit_hook)
68
revid = tree.commit('a revision')
69
# should have had one notification, from origin, and
70
# have the branch locked at notification time.
72
('post_commit', None, tree.branch.base, 0, NULL_REVISION, 1, revid,
78
def test_post_commit_bound(self):
79
master = self.make_branch('master')
80
tree = self.make_branch_and_memory_tree('local')
82
tree.branch.bind(master)
83
except errors.UpgradeRequired:
84
# cant bind this format, the test is irrelevant.
86
Branch.hooks.install_hook('post_commit',
87
self.capture_post_commit_hook)
90
revid = tree.commit('a revision')
91
# with a bound branch, local is set.
93
('post_commit', tree.branch.base, master.base, 0, NULL_REVISION,
99
def test_post_commit_not_to_origin(self):
100
tree = self.make_branch_and_memory_tree('branch')
103
revid = tree.commit('first revision')
104
Branch.hooks.install_hook('post_commit',
105
self.capture_post_commit_hook)
106
revid2 = tree.commit('second revision')
107
# having committed from up the branch, we should get the
108
# before and after revnos and revids correctly.
110
('post_commit', None, tree.branch.base, 1, revid, 2, revid2,