/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4044.1.1 by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push.
1
# Copyright (C) 2009 Canonical Ltd
2
#
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.
7
#
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.
12
#
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
16
17
"""Tests for branch.create_clone behaviour."""
18
4050.1.1 by Robert Collins
Fix race condition with branch hooks during cloning when the new branch is stacked.
19
from bzrlib.branch import Branch
4044.1.1 by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push.
20
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
4050.1.1 by Robert Collins
Fix race condition with branch hooks during cloning when the new branch is stacked.
21
from bzrlib import remote
4044.1.1 by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push.
22
23
24
class TestCreateClone(TestCaseWithBranch):
25
26
    def test_create_clone_on_transport_no_revision_id(self):
27
        tree = self.make_branch_and_tree('source')
28
        tree.commit('a commit')
29
        source = tree.branch
30
        target_transport = self.get_transport('target')
31
        result = tree.branch.create_clone_on_transport(target_transport)
32
        self.assertEqual(source.last_revision(), result.last_revision())
33
34
    def test_create_clone_on_transport_revision_id(self):
35
        tree = self.make_branch_and_tree('source')
36
        old_revid = tree.commit('a commit')
37
        source_tip = tree.commit('a second commit')
38
        source = tree.branch
39
        target_transport = self.get_transport('target')
40
        result = tree.branch.create_clone_on_transport(target_transport,
41
            revision_id=old_revid)
42
        self.assertEqual(old_revid, result.last_revision())
43
        result.lock_read()
44
        self.addCleanup(result.unlock)
45
        self.assertFalse(result.repository.has_revision(source_tip))
46
47
    def test_create_clone_on_transport_stacked(self):
48
        tree = self.make_branch_and_tree('source')
49
        tree.commit('a commit')
50
        trunk = tree.branch.create_clone_on_transport(
51
            self.get_transport('trunk'))
52
        revid = tree.commit('a second commit')
53
        source = tree.branch
54
        target_transport = self.get_transport('target')
55
        result = tree.branch.create_clone_on_transport(target_transport,
56
            stacked_on=trunk.base)
57
        self.assertEqual(revid, result.last_revision())
58
        self.assertEqual(trunk.base, result.get_stacked_on_url())
4050.1.1 by Robert Collins
Fix race condition with branch hooks during cloning when the new branch is stacked.
59
60
    def assertBranchHookBranchIsStacked(self, pre_change_params):
61
        # Just calling will either succeed or fail.
62
        pre_change_params.branch.get_stacked_on_url()
63
        self.hook_calls.append(pre_change_params)
64
65
    def test_create_clone_on_transport_stacked_hooks_get_stacked_branch(self):
66
        tree = self.make_branch_and_tree('source')
67
        tree.commit('a commit')
68
        trunk = tree.branch.create_clone_on_transport(
69
            self.get_transport('trunk'))
70
        revid = tree.commit('a second commit')
71
        source = tree.branch
72
        target_transport = self.get_transport('target')
73
        self.hook_calls = []
74
        Branch.hooks.install_named_hook("pre_change_branch_tip",
75
            self.assertBranchHookBranchIsStacked, None)
76
        result = tree.branch.create_clone_on_transport(target_transport,
77
            stacked_on=trunk.base)
78
        self.assertEqual(revid, result.last_revision())
79
        self.assertEqual(trunk.base, result.get_stacked_on_url())
80
        # Smart servers invoke hooks on both sides
81
        if isinstance(result, remote.RemoteBranch):
82
            expected_calls = 2
83
        else:
84
            expected_calls = 1
85
        self.assertEqual(expected_calls, len(self.hook_calls))