/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_stacking.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-15 14:14:22 UTC
  • mfrom: (3242.3.41 stacking-policy)
  • Revision ID: pqm@pqm.ubuntu.com-20080715141422-gwfo1jmu1tm8lcf0
Implement policies for stacking (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    errors,
22
22
    )
23
23
from bzrlib.revision import NULL_REVISION
24
 
from bzrlib.tests import TestNotApplicable
 
24
from bzrlib.tests import TestNotApplicable, KnownFailure
25
25
from bzrlib.tests.branch_implementations import TestCaseWithBranch
26
26
 
27
27
 
49
49
        branch.set_stacked_on(None)
50
50
        self.assertRaises(errors.NotStacked, branch.get_stacked_on)
51
51
 
 
52
    def test_get_set_stacked_on_relative(self):
 
53
        # Branches can be stacked on other branches using relative paths.
 
54
        branch = self.make_branch('branch')
 
55
        target = self.make_branch('target')
 
56
        old_format_errors = (
 
57
            errors.UnstackableBranchFormat,
 
58
            errors.UnstackableRepositoryFormat,
 
59
            )
 
60
        try:
 
61
            branch.set_stacked_on('../target')
 
62
        except old_format_errors:
 
63
            # if the set failed, so must the get
 
64
            self.assertRaises(old_format_errors, branch.get_stacked_on)
 
65
            return
 
66
        self.assertEqual('../target', branch.get_stacked_on())
 
67
 
52
68
    def assertRevisionInRepository(self, repo_path, revid):
53
69
        """Check that a revision is in a repository, disregarding stacking."""
54
70
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
96
112
        self.assertRevisionNotInRepository('newbranch', trunk_revid)
97
113
        new_tree = new_dir.open_workingtree()
98
114
        new_tree.commit('something local')
 
115
 
 
116
    def prepare_for_clone(self):
 
117
        tree = self.make_branch_and_tree('stacked-on')
 
118
        tree.commit('Added foo')
 
119
        stacked_bzrdir = tree.branch.bzrdir.sprout(
 
120
            'stacked', tree.branch.last_revision(), stacked=True)
 
121
        return stacked_bzrdir
 
122
 
 
123
    def test_clone_from_stacked_branch_preserve_stacking(self):
 
124
        # We can clone from the bzrdir of a stacked branch. If
 
125
        # preserve_stacking is True, the cloned branch is stacked on the
 
126
        # same branch as the original.
 
127
        try:
 
128
            stacked_bzrdir = self.prepare_for_clone()
 
129
        except (errors.UnstackableBranchFormat,
 
130
                errors.UnstackableRepositoryFormat):
 
131
            # not a testable combination.
 
132
            return
 
133
        cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
 
134
        try:
 
135
            self.assertEqual(
 
136
                stacked_bzrdir.open_branch().get_stacked_on(),
 
137
                cloned_bzrdir.open_branch().get_stacked_on())
 
138
        except (errors.UnstackableBranchFormat,
 
139
                errors.UnstackableRepositoryFormat):
 
140
            pass
 
141
 
 
142
    def test_clone_from_stacked_branch_no_preserve_stacking(self):
 
143
        try:
 
144
            stacked_bzrdir = self.prepare_for_clone()
 
145
        except (errors.UnstackableBranchFormat,
 
146
                errors.UnstackableRepositoryFormat):
 
147
            # not a testable combination.
 
148
            return
 
149
        try:
 
150
            cloned_unstacked_bzrdir = stacked_bzrdir.clone('cloned-unstacked',
 
151
                preserve_stacking=False)
 
152
        except errors.NoSuchRevision:
 
153
            raise KnownFailure(
 
154
                'Pack-to-pack fetch does not handle stacking properly.'
 
155
                ' (#248506)')
 
156
        else:
 
157
            self.fail('Expected a failure due to broken fetching.')
 
158
        unstacked_branch = cloned_unstacked_bzrdir.open_branch()
 
159
        self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat),
 
160
                          unstacked_branch.get_stacked_on)
 
161
 
 
162
    def test_no_op_preserve_stacking(self):
 
163
        """With no stacking, preserve_stacking should be a no-op."""
 
164
        branch = self.make_branch('source')
 
165
        cloned_bzrdir = branch.bzrdir.clone('cloned', preserve_stacking=True)
 
166
        self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat),
 
167
                          cloned_bzrdir.open_branch().get_stacked_on)
 
168
 
 
169
    def test_sprout_stacking_policy_handling(self):
 
170
        """Obey policy where possible, ignore otherwise."""
 
171
        stack_on = self.make_branch('stack-on')
 
172
        parent_bzrdir = self.make_bzrdir('.', format='default')
 
173
        parent_bzrdir.get_config().set_default_stack_on('stack-on')
 
174
        source = self.make_branch('source')
 
175
        target = source.bzrdir.sprout('target').open_branch()
 
176
        try:
 
177
            self.assertEqual('../stack-on', target.get_stacked_on())
 
178
        except errors.UnstackableBranchFormat:
 
179
            pass
 
180
 
 
181
    def test_clone_stacking_policy_handling(self):
 
182
        """Obey policy where possible, ignore otherwise."""
 
183
        stack_on = self.make_branch('stack-on')
 
184
        parent_bzrdir = self.make_bzrdir('.', format='default')
 
185
        parent_bzrdir.get_config().set_default_stack_on('stack-on')
 
186
        source = self.make_branch('source')
 
187
        target = source.bzrdir.clone('target').open_branch()
 
188
        try:
 
189
            self.assertEqual('../stack-on', target.get_stacked_on())
 
190
        except errors.UnstackableBranchFormat:
 
191
            pass