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