~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-09 20:23:07 UTC
  • mfrom: (4265.1.4 bbc-merge)
  • Revision ID: pqm@pqm.ubuntu.com-20090409202307-n0depb16qepoe21o
(jam) Change _fetch_uses_deltas = False for CHK repos until we can
        write a better fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
27
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
31
28
from bzrlib.workingtree import WorkingTree
96
93
        self.build_tree(['source/file1'])
97
94
        source.add('file1')
98
95
        source.commit('added file')
99
 
        out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
 
96
        self.run_bzr(['branch', 'source', 'target', '--hardlink'])
100
97
        source_stat = os.stat('source/file1')
101
98
        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)")
 
99
        self.assertEqual(source_stat, target_stat)
111
100
 
112
101
    def test_branch_standalone(self):
113
102
        shared_repo = self.make_repository('repo', shared=True)
124
113
        self.failIfExists('target/hello')
125
114
        self.failIfExists('target/goodbye')
126
115
 
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
 
 
148
116
 
149
117
class TestBranchStacked(ExternalBase):
150
118
    """Tests for branch --stacked"""
151
119
 
 
120
    def check_shallow_branch(self, branch_revid, stacked_on):
 
121
        """Assert that the branch 'newbranch' has been published correctly.
 
122
 
 
123
        :param stacked_on: url of a branch this one is stacked upon.
 
124
        :param branch_revid: a revision id that should be the only
 
125
            revision present in the stacked branch, and it should not be in
 
126
            the reference branch.
 
127
        """
 
128
        new_branch = branch.Branch.open('newbranch')
 
129
        # The branch refers to the mainline
 
130
        self.assertEqual(stacked_on, new_branch.get_stacked_on_url())
 
131
        # and the branch's work was pushed
 
132
        self.assertTrue(new_branch.repository.has_revision(branch_revid))
 
133
        # The newly committed revision shoud be present in the stacked branch,
 
134
        # but not in the stacked-on branch.  Because stacking is set up by the
 
135
        # branch object, if we open the stacked branch's repository directly,
 
136
        # bypassing the branch, we see only what's in the stacked repository.
 
137
        stacked_repo = bzrdir.BzrDir.open('newbranch').open_repository()
 
138
        stacked_repo_revisions = set(stacked_repo.all_revision_ids())
 
139
        if len(stacked_repo_revisions) != 1:
 
140
            self.fail("wrong revisions in stacked repository: %r"
 
141
                % (stacked_repo_revisions,))
 
142
 
152
143
    def assertRevisionInRepository(self, repo_path, revid):
153
144
        """Check that a revision is in a repository, disregarding stacking."""
154
145
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
175
166
            format='1.9')
176
167
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
177
168
        # with some work on it
178
 
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
179
 
        work_tree.commit('moar work plz')
180
 
        work_tree.branch.push(branch_tree.branch)
 
169
        branch_tree.commit('moar work plz')
181
170
        # branching our local branch gives us a new stacked branch pointing at
182
171
        # mainline.
183
172
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
184
173
        self.assertEqual('', out)
185
 
        self.assertEqual('Branched 2 revision(s).\n',
 
174
        self.assertEqual('Branched 1 revision(s).\n',
186
175
            err)
187
176
        # it should have preserved the branch format, and so it should be
188
177
        # capable of supporting stacking, but not actually have a stacked_on
201
190
            format='1.9')
202
191
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
203
192
        # with some work on it
204
 
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
205
 
        branch_revid = work_tree.commit('moar work plz')
206
 
        work_tree.branch.push(branch_tree.branch)
 
193
        branch_revid = branch_tree.commit('moar work plz')
207
194
        # you can chain branches on from there
208
195
        out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
209
196
        self.assertEqual('', out)
212
199
        self.assertEqual(branch_tree.branch.base,
213
200
            branch.Branch.open('branch2').get_stacked_on_url())
214
201
        branch2_tree = WorkingTree.open('branch2')
215
 
        branch2_revid = work_tree.commit('work on second stacked branch')
216
 
        work_tree.branch.push(branch2_tree.branch)
 
202
        branch2_revid = branch2_tree.commit('work on second stacked branch')
217
203
        self.assertRevisionInRepository('branch2', branch2_revid)
218
204
        self.assertRevisionsInBranchRepository(
219
205
            [trunk_revid, branch_revid, branch2_revid],
232
218
        self.assertEqual('Created new stacked branch referring to %s.\n' %
233
219
            trunk_tree.branch.base, err)
234
220
        self.assertRevisionNotInRepository('newbranch', original_revid)
235
 
        new_branch = branch.Branch.open('newbranch')
236
 
        self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
 
221
        new_tree = WorkingTree.open('newbranch')
 
222
        new_revid = new_tree.commit('new work')
 
223
        self.check_shallow_branch(new_revid, trunk_tree.branch.base)
237
224
 
238
225
    def test_branch_stacked_from_smart_server(self):
239
226
        # We can branch stacking on a smart server
250
237
            ['branch', '--stacked', 'trunk', 'shallow'])
251
238
        # We should notify the user that we upgraded their format
252
239
        self.assertEqualDiff(
253
 
            'Source repository format does not support stacking, using format:\n'
 
240
            'Source format does not support stacking, using format: \'1.6\'\n'
254
241
            '  Packs 5 (adds stacking support, requires bzr 1.6)\n'
255
 
            'Source branch format does not support stacking, using format:\n'
256
 
            '  Branch format 7\n'
 
242
            '\n'
257
243
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
258
244
            err)
259
245
 
263
249
            ['branch', '--stacked', 'trunk', 'shallow'])
264
250
        # We should notify the user that we upgraded their format
265
251
        self.assertEqualDiff(
266
 
            'Source repository format does not support stacking, using format:\n'
 
252
            'Source format does not support stacking, using format:'
 
253
            ' \'1.6.1-rich-root\'\n'
267
254
            '  Packs 5 rich-root (adds stacking support, requires bzr 1.6.1)\n'
268
 
            'Source branch format does not support stacking, using format:\n'
269
 
            '  Branch format 7\n'
 
255
            '\n'
270
256
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
271
257
            err)
272
258
 
286
272
        # being too low. If rpc_count increases, more network roundtrips have
287
273
        # become necessary for this use case. Please do not adjust this number
288
274
        # upwards without agreement from bzr's network support maintainers.
289
 
        self.assertLength(38, self.hpss_calls)
 
275
        self.assertLength(53, self.hpss_calls)
290
276
 
291
277
    def test_branch_from_trivial_branch_streaming_acceptance(self):
292
278
        self.setup_smart_server_with_call_log()
310
296
            t.commit(message='commit %d' % count)
311
297
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
312
298
            ).open_workingtree()
313
 
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
314
 
        local_tree.commit('feature change')
315
 
        local_tree.branch.push(tree2.branch)
 
299
        tree2.commit('feature change')
316
300
        self.reset_smart_call_log()
317
301
        out, err = self.run_bzr(['branch', self.get_url('feature'),
318
302
            'local-target'])