~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_branch.py

Initial commit for russian version of documents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Black-box tests for bzr branch."""
22
22
from bzrlib import (branch, bzrdir, errors, repository)
23
23
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
24
24
from bzrlib.tests.blackbox import ExternalBase
25
 
from bzrlib.tests import (
26
 
    KnownFailure,
27
 
    HardlinkFeature,
28
 
    )
 
25
from bzrlib.tests import HardlinkFeature
29
26
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
30
 
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
31
27
from bzrlib.workingtree import WorkingTree
32
28
 
33
29
 
96
92
        self.build_tree(['source/file1'])
97
93
        source.add('file1')
98
94
        source.commit('added file')
99
 
        out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
 
95
        self.run_bzr(['branch', 'source', 'target', '--hardlink'])
100
96
        source_stat = os.stat('source/file1')
101
97
        target_stat = os.stat('target/file1')
102
 
        same_file = (source_stat == target_stat)
103
 
        if same_file:
104
 
            pass
105
 
        else:
106
 
            # https://bugs.edge.launchpad.net/bzr/+bug/408193
107
 
            self.assertContainsRe(err, "hardlinking working copy files is "
108
 
                "not currently supported")
109
 
            raise KnownFailure("--hardlink doesn't work in formats "
110
 
                "that support content filtering (#408193)")
111
 
 
112
 
    def test_branch_standalone(self):
113
 
        shared_repo = self.make_repository('repo', shared=True)
114
 
        self.example_branch('source')
115
 
        self.run_bzr('branch --standalone source repo/target')
116
 
        b = branch.Branch.open('repo/target')
117
 
        expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
118
 
        self.assertEqual(strip_trailing_slash(b.repository.base),
119
 
            strip_trailing_slash(local_path_to_url(expected_repo_path)))
120
 
 
121
 
    def test_branch_no_tree(self):
122
 
        self.example_branch('source')
123
 
        self.run_bzr('branch --no-tree source target')
124
 
        self.failIfExists('target/hello')
125
 
        self.failIfExists('target/goodbye')
126
 
 
127
 
    def test_branch_into_existing_dir(self):
128
 
        self.example_branch('a')
129
 
        # existing dir with similar files but no .bzr dir
130
 
        self.build_tree_contents([('b/',)])
131
 
        self.build_tree_contents([('b/hello', 'bar')])  # different content
132
 
        self.build_tree_contents([('b/goodbye', 'baz')])# same content
133
 
        # fails without --use-existing-dir
134
 
        out,err = self.run_bzr('branch a b', retcode=3)
135
 
        self.assertEqual('', out)
136
 
        self.assertEqual('bzr: ERROR: Target directory "b" already exists.\n',
137
 
            err)
138
 
        # force operation
139
 
        self.run_bzr('branch a b --use-existing-dir')
140
 
        # check conflicts
141
 
        self.failUnlessExists('b/hello.moved')
142
 
        self.failIfExists('b/godbye.moved')
143
 
        # we can't branch into branch
144
 
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
145
 
        self.assertEqual('', out)
146
 
        self.assertEqual('bzr: ERROR: Already a branch: "b".\n', err)
147
 
 
 
98
        self.assertEqual(source_stat, target_stat)
148
99
 
149
100
class TestBranchStacked(ExternalBase):
150
101
    """Tests for branch --stacked"""
151
102
 
152
103
    def check_shallow_branch(self, branch_revid, stacked_on):
153
104
        """Assert that the branch 'newbranch' has been published correctly.
154
 
 
 
105
        
155
106
        :param stacked_on: url of a branch this one is stacked upon.
156
 
        :param branch_revid: a revision id that should be the only
 
107
        :param branch_revid: a revision id that should be the only 
157
108
            revision present in the stacked branch, and it should not be in
158
109
            the reference branch.
159
110
        """
191
142
        """Branching a stacked branch is not stacked by default"""
192
143
        # We have a mainline
193
144
        trunk_tree = self.make_branch_and_tree('target',
194
 
            format='1.9')
 
145
            format='development')
195
146
        trunk_tree.commit('mainline')
196
147
        # and a branch from it which is stacked
197
148
        branch_tree = self.make_branch_and_tree('branch',
198
 
            format='1.9')
 
149
            format='development')
199
150
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
200
151
        # with some work on it
201
152
        branch_tree.commit('moar work plz')
215
166
        """Asking to stack on a stacked branch does work"""
216
167
        # We have a mainline
217
168
        trunk_tree = self.make_branch_and_tree('target',
218
 
            format='1.9')
 
169
            format='development')
219
170
        trunk_revid = trunk_tree.commit('mainline')
220
171
        # and a branch from it which is stacked
221
172
        branch_tree = self.make_branch_and_tree('branch',
222
 
            format='1.9')
 
173
            format='development')
223
174
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
224
175
        # with some work on it
225
176
        branch_revid = branch_tree.commit('moar work plz')
240
191
    def test_branch_stacked(self):
241
192
        # We have a mainline
242
193
        trunk_tree = self.make_branch_and_tree('mainline',
243
 
            format='1.9')
 
194
            format='development')
244
195
        original_revid = trunk_tree.commit('mainline')
245
196
        self.assertRevisionInRepository('mainline', original_revid)
246
197
        # and a branch from it which is stacked
258
209
        # We can branch stacking on a smart server
259
210
        from bzrlib.smart.server import SmartTCPServer_for_testing
260
211
        self.transport_server = SmartTCPServer_for_testing
261
 
        trunk = self.make_branch('mainline', format='1.9')
 
212
        trunk = self.make_branch('mainline', format='development')
262
213
        out, err = self.run_bzr(
263
214
            ['branch', '--stacked', self.get_url('mainline'), 'shallow'])
264
215
 
267
218
        trunk = self.make_branch('trunk', format='pack-0.92')
268
219
        out, err = self.run_bzr(
269
220
            ['branch', '--stacked', 'trunk', 'shallow'])
270
 
        # We should notify the user that we upgraded their format
271
 
        self.assertEqualDiff(
272
 
            'Source repository format does not support stacking, using format:\n'
273
 
            '  Packs 5 (adds stacking support, requires bzr 1.6)\n'
274
 
            'Source branch format does not support stacking, using format:\n'
275
 
            '  Branch format 7\n'
276
 
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
277
 
            err)
278
 
 
279
 
    def test_branch_stacked_from_rich_root_non_stackable(self):
280
 
        trunk = self.make_branch('trunk', format='rich-root-pack')
281
 
        out, err = self.run_bzr(
282
 
            ['branch', '--stacked', 'trunk', 'shallow'])
283
 
        # We should notify the user that we upgraded their format
284
 
        self.assertEqualDiff(
285
 
            'Source repository format does not support stacking, using format:\n'
286
 
            '  Packs 5 rich-root (adds stacking support, requires bzr 1.6.1)\n'
287
 
            'Source branch format does not support stacking, using format:\n'
288
 
            '  Branch format 7\n'
289
 
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
290
 
            err)
291
 
 
292
 
 
293
 
class TestSmartServerBranching(ExternalBase):
294
 
 
295
 
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
296
 
        self.setup_smart_server_with_call_log()
297
 
        t = self.make_branch_and_tree('from')
298
 
        for count in range(9):
299
 
            t.commit(message='commit %d' % count)
300
 
        self.reset_smart_call_log()
301
 
        out, err = self.run_bzr(['branch', self.get_url('from'),
302
 
            self.get_url('target')])
303
 
        # This figure represent the amount of work to perform this use case. It
304
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
305
 
        # being too low. If rpc_count increases, more network roundtrips have
306
 
        # become necessary for this use case. Please do not adjust this number
307
 
        # upwards without agreement from bzr's network support maintainers.
308
 
        self.assertLength(38, self.hpss_calls)
309
 
 
310
 
    def test_branch_from_trivial_branch_streaming_acceptance(self):
311
 
        self.setup_smart_server_with_call_log()
312
 
        t = self.make_branch_and_tree('from')
313
 
        for count in range(9):
314
 
            t.commit(message='commit %d' % count)
315
 
        self.reset_smart_call_log()
316
 
        out, err = self.run_bzr(['branch', self.get_url('from'),
317
 
            'local-target'])
318
 
        # This figure represent the amount of work to perform this use case. It
319
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
320
 
        # being too low. If rpc_count increases, more network roundtrips have
321
 
        # become necessary for this use case. Please do not adjust this number
322
 
        # upwards without agreement from bzr's network support maintainers.
323
 
        self.assertLength(10, self.hpss_calls)
324
 
 
325
 
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
326
 
        self.setup_smart_server_with_call_log()
327
 
        t = self.make_branch_and_tree('trunk')
328
 
        for count in range(8):
329
 
            t.commit(message='commit %d' % count)
330
 
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
331
 
            ).open_workingtree()
332
 
        tree2.commit('feature change')
333
 
        self.reset_smart_call_log()
334
 
        out, err = self.run_bzr(['branch', self.get_url('feature'),
335
 
            'local-target'])
336
 
        # This figure represent the amount of work to perform this use case. It
337
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
338
 
        # being too low. If rpc_count increases, more network roundtrips have
339
 
        # become necessary for this use case. Please do not adjust this number
340
 
        # upwards without agreement from bzr's network support maintainers.
341
 
        self.assertLength(15, self.hpss_calls)
342
221
 
343
222
 
344
223
class TestRemoteBranch(TestCaseWithSFTPServer):