~bzr-pqm/bzr/bzr.dev

2524.1.1 by Aaron Bentley
Revert broken changes
1
# Copyright (C) 2007 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.sprout()"""
18
19
from bzrlib import (
20
    remote,
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
21
    revision as _mod_revision,
2524.1.1 by Aaron Bentley
Revert broken changes
22
    tests,
23
    )
24
from bzrlib.tests.branch_implementations import TestCaseWithBranch
25
26
27
class TestSprout(TestCaseWithBranch):
28
29
    def test_sprout_branch_nickname(self):
30
        # test the nick name is reset always
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
31
        raise tests.TestSkipped('XXX branch sprouting is not yet tested.')
2524.1.1 by Aaron Bentley
Revert broken changes
32
33
    def test_sprout_branch_parent(self):
34
        source = self.make_branch('source')
35
        target = source.bzrdir.sprout(self.get_url('target')).open_branch()
36
        self.assertEqual(source.bzrdir.root_transport.base, target.get_parent())
37
38
    def test_sprout_preserves_kind(self):
39
        branch1 = self.make_branch('branch1')
40
        target_repo = self.make_repository('branch2')
41
        target_repo.fetch(branch1.repository)
42
        branch2 = branch1.sprout(target_repo.bzrdir)
43
        if isinstance(branch1, remote.RemoteBranch):
44
            branch1._ensure_real()
45
            target_class = branch1._real_branch.__class__
46
        else:
47
            target_class = branch1.__class__
48
        self.assertIsInstance(branch2, target_class)
49
50
    def test_sprout_partial(self):
51
        # test sprouting with a prefix of the revision-history.
52
        # also needs not-on-revision-history behaviour defined.
53
        wt_a = self.make_branch_and_tree('a')
54
        self.build_tree(['a/one'])
55
        wt_a.add(['one'])
56
        wt_a.commit('commit one', rev_id='1')
57
        self.build_tree(['a/two'])
58
        wt_a.add(['two'])
59
        wt_a.commit('commit two', rev_id='2')
60
        repo_b = self.make_repository('b')
61
        repo_a = wt_a.branch.repository
62
        repo_a.copy_content_into(repo_b)
63
        br_b = wt_a.branch.sprout(repo_b.bzrdir, revision_id='1')
64
        self.assertEqual('1', br_b.last_revision())
65
66
    def test_sprout_partial_not_in_revision_history(self):
67
        """We should be able to sprout from any revision in ancestry."""
68
        wt = self.make_branch_and_tree('source')
69
        self.build_tree(['source/a'])
70
        wt.add('a')
71
        wt.commit('rev1', rev_id='rev1')
72
        wt.commit('rev2-alt', rev_id='rev2-alt')
73
        wt.set_parent_ids(['rev1'])
74
        wt.branch.set_last_revision_info(1, 'rev1')
75
        wt.commit('rev2', rev_id='rev2')
76
        wt.set_parent_ids(['rev2', 'rev2-alt'])
77
        wt.commit('rev3', rev_id='rev3')
78
79
        repo = self.make_repository('target')
80
        repo.fetch(wt.branch.repository)
81
        branch2 = wt.branch.sprout(repo.bzrdir, revision_id='rev2-alt')
82
        self.assertEqual((2, 'rev2-alt'), branch2.last_revision_info())
83
        self.assertEqual(['rev1', 'rev2-alt'], branch2.revision_history())
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
84
85
    def test_sprout_from_any_repo_revision(self):
86
        """We should be able to sprout from any revision."""
87
        wt = self.make_branch_and_tree('source')
88
        self.build_tree(['source/a'])
89
        wt.add('a')
90
        wt.commit('rev1a', rev_id='rev1a')
91
        # simulated uncommit
92
        wt.branch.set_last_revision_info(0, _mod_revision.NULL_REVISION)
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
93
        wt.set_last_revision(_mod_revision.NULL_REVISION)
2796.1.4 by Aaron Bentley
Fix up various test cases
94
        wt.revert()
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
95
        wt.commit('rev1b', rev_id='rev1b')
96
        wt2 = wt.bzrdir.sprout('target',
97
            revision_id='rev1a').open_workingtree()
98
        self.assertEqual('rev1a', wt2.last_revision())
99
        self.failUnlessExists('target/a')