/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
19
import os
2524.1.1 by Aaron Bentley
Revert broken changes
20
from bzrlib import (
21
    remote,
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
22
    revision as _mod_revision,
2524.1.1 by Aaron Bentley
Revert broken changes
23
    tests,
24
    )
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
25
from bzrlib.tests import KnownFailure, SymlinkFeature, UnicodeFilenameFeature
2524.1.1 by Aaron Bentley
Revert broken changes
26
from bzrlib.tests.branch_implementations import TestCaseWithBranch
27
28
29
class TestSprout(TestCaseWithBranch):
30
31
    def test_sprout_branch_nickname(self):
32
        # test the nick name is reset always
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
33
        raise tests.TestSkipped('XXX branch sprouting is not yet tested.')
2524.1.1 by Aaron Bentley
Revert broken changes
34
35
    def test_sprout_branch_parent(self):
36
        source = self.make_branch('source')
37
        target = source.bzrdir.sprout(self.get_url('target')).open_branch()
38
        self.assertEqual(source.bzrdir.root_transport.base, target.get_parent())
39
40
    def test_sprout_preserves_kind(self):
41
        branch1 = self.make_branch('branch1')
42
        target_repo = self.make_repository('branch2')
43
        target_repo.fetch(branch1.repository)
44
        branch2 = branch1.sprout(target_repo.bzrdir)
45
        if isinstance(branch1, remote.RemoteBranch):
46
            branch1._ensure_real()
47
            target_class = branch1._real_branch.__class__
48
        else:
49
            target_class = branch1.__class__
50
        self.assertIsInstance(branch2, target_class)
51
52
    def test_sprout_partial(self):
53
        # test sprouting with a prefix of the revision-history.
54
        # also needs not-on-revision-history behaviour defined.
55
        wt_a = self.make_branch_and_tree('a')
56
        self.build_tree(['a/one'])
57
        wt_a.add(['one'])
58
        wt_a.commit('commit one', rev_id='1')
59
        self.build_tree(['a/two'])
60
        wt_a.add(['two'])
61
        wt_a.commit('commit two', rev_id='2')
62
        repo_b = self.make_repository('b')
63
        repo_a = wt_a.branch.repository
64
        repo_a.copy_content_into(repo_b)
65
        br_b = wt_a.branch.sprout(repo_b.bzrdir, revision_id='1')
66
        self.assertEqual('1', br_b.last_revision())
67
68
    def test_sprout_partial_not_in_revision_history(self):
69
        """We should be able to sprout from any revision in ancestry."""
70
        wt = self.make_branch_and_tree('source')
71
        self.build_tree(['source/a'])
72
        wt.add('a')
73
        wt.commit('rev1', rev_id='rev1')
74
        wt.commit('rev2-alt', rev_id='rev2-alt')
75
        wt.set_parent_ids(['rev1'])
76
        wt.branch.set_last_revision_info(1, 'rev1')
77
        wt.commit('rev2', rev_id='rev2')
78
        wt.set_parent_ids(['rev2', 'rev2-alt'])
79
        wt.commit('rev3', rev_id='rev3')
80
81
        repo = self.make_repository('target')
82
        repo.fetch(wt.branch.repository)
83
        branch2 = wt.branch.sprout(repo.bzrdir, revision_id='rev2-alt')
84
        self.assertEqual((2, 'rev2-alt'), branch2.last_revision_info())
85
        self.assertEqual(['rev1', 'rev2-alt'], branch2.revision_history())
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
86
87
    def test_sprout_from_any_repo_revision(self):
88
        """We should be able to sprout from any revision."""
89
        wt = self.make_branch_and_tree('source')
90
        self.build_tree(['source/a'])
91
        wt.add('a')
92
        wt.commit('rev1a', rev_id='rev1a')
93
        # simulated uncommit
94
        wt.branch.set_last_revision_info(0, _mod_revision.NULL_REVISION)
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
95
        wt.set_last_revision(_mod_revision.NULL_REVISION)
2796.1.4 by Aaron Bentley
Fix up various test cases
96
        wt.revert()
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
97
        wt.commit('rev1b', rev_id='rev1b')
98
        wt2 = wt.bzrdir.sprout('target',
99
            revision_id='rev1a').open_workingtree()
100
        self.assertEqual('rev1a', wt2.last_revision())
101
        self.failUnlessExists('target/a')
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
102
3763.9.7 by Daniel Clemente
Tested Unicode target rather than always trying to create it in UTF-8. Test renamed
103
    def test_sprout_with_unicode_symlink(self):
3763.9.8 by Daniel Clemente
Broken lines, and prepended # before bug numbers
104
        # this tests bug #272444
3763.9.11 by Daniel Clemente
More detailed comment and in broken line
105
        # Since the trigger function seems to be set_parent_trees, there exists
106
        # also a similar test, with name test_unicode_symlink, in class
107
        # TestSetParents at file workingtree_implementations/test_parents.py
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
108
        self.requireFeature(SymlinkFeature)
109
        self.requireFeature(UnicodeFilenameFeature)
110
111
        tree = self.make_branch_and_tree('tree1')
112
3763.9.9 by Daniel Clemente
Used a greek omega instead of an accented 'o' to avoid combining characters
113
        # The link points to a file whose name is an omega
114
        # U+03A9 GREEK CAPITAL LETTER OMEGA
115
        # UTF-8: ce a9  UTF-16BE: 03a9  Decimal: Ω
116
        os.symlink(u'\u03a9','tree1/link_name')
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
117
        tree.add(['link_name'],['link-id'])
118
119
        try:
3763.9.12 by Daniel Clemente
Made the tests pass on Python 2.4 and 2.7a0
120
            # python 2.7a0 failed on commit:
121
            revision = tree.commit('added a link to a Unicode target')
122
            # python 2.5 failed on sprout:
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
123
            tree.bzrdir.sprout('target')
124
        except UnicodeEncodeError, e:
3763.9.8 by Daniel Clemente
Broken lines, and prepended # before bug numbers
125
            raise KnownFailure('there is no support for'
126
                               ' symlinks to non-ASCII targets (bug #272444)')
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
127