~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2010-01-13 16:23:07 UTC
  • mto: (4634.119.7 2.0)
  • mto: This revision was merged to the branch mainline in revision 4959.
  • Revision ID: john@arbash-meinel.com-20100113162307-0bs82td16gzih827
Update the MANIFEST.in file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import os
21
21
 
22
 
from bzrlib import (branch, bzrdir, errors, repository)
 
22
from bzrlib import (
 
23
    branch,
 
24
    bzrdir,
 
25
    errors,
 
26
    repository,
 
27
    revision as _mod_revision,
 
28
    )
23
29
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
24
30
from bzrlib.tests.blackbox import ExternalBase
25
31
from bzrlib.tests import (
52
58
        self.assertFalse(b._transport.has('branch-name'))
53
59
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
54
60
 
 
61
    def test_branch_switch_no_branch(self):
 
62
        # No branch in the current directory:
 
63
        #  => new branch will be created, but switch fails
 
64
        self.example_branch('a')
 
65
        self.make_repository('current')
 
66
        self.run_bzr_error(['No WorkingTree exists for'],
 
67
            'branch --switch ../a ../b', working_dir='current')
 
68
        a = branch.Branch.open('a')
 
69
        b = branch.Branch.open('b')
 
70
        self.assertEqual(a.last_revision(), b.last_revision())
 
71
 
 
72
    def test_branch_switch_no_wt(self):
 
73
        # No working tree in the current directory:
 
74
        #  => new branch will be created, but switch fails and the current
 
75
        #     branch is unmodified
 
76
        self.example_branch('a')
 
77
        self.make_branch('current')
 
78
        self.run_bzr_error(['No WorkingTree exists for'],
 
79
            'branch --switch ../a ../b', working_dir='current')
 
80
        a = branch.Branch.open('a')
 
81
        b = branch.Branch.open('b')
 
82
        self.assertEqual(a.last_revision(), b.last_revision())
 
83
        work = branch.Branch.open('current')
 
84
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
 
85
 
 
86
    def test_branch_switch_no_checkout(self):
 
87
        # Standalone branch in the current directory:
 
88
        #  => new branch will be created, but switch fails and the current
 
89
        #     branch is unmodified
 
90
        self.example_branch('a')
 
91
        self.make_branch_and_tree('current')
 
92
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
 
93
            'branch --switch ../a ../b', working_dir='current')
 
94
        a = branch.Branch.open('a')
 
95
        b = branch.Branch.open('b')
 
96
        self.assertEqual(a.last_revision(), b.last_revision())
 
97
        work = branch.Branch.open('current')
 
98
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
 
99
 
 
100
    def test_branch_switch_checkout(self):
 
101
        # Checkout in the current directory:
 
102
        #  => new branch will be created and checkout bound to the new branch
 
103
        self.example_branch('a')
 
104
        self.run_bzr('checkout a current')
 
105
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
 
106
        a = branch.Branch.open('a')
 
107
        b = branch.Branch.open('b')
 
108
        self.assertEqual(a.last_revision(), b.last_revision())
 
109
        work = WorkingTree.open('current')
 
110
        self.assertEndsWith(work.branch.get_bound_location(), '/b/')
 
111
        self.assertContainsRe(err, "Switched to branch: .*/b/")
 
112
 
 
113
    def test_branch_switch_lightweight_checkout(self):
 
114
        # Lightweight checkout in the current directory:
 
115
        #  => new branch will be created and lightweight checkout pointed to
 
116
        #     the new branch
 
117
        self.example_branch('a')
 
118
        self.run_bzr('checkout --lightweight a current')
 
119
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
 
120
        a = branch.Branch.open('a')
 
121
        b = branch.Branch.open('b')
 
122
        self.assertEqual(a.last_revision(), b.last_revision())
 
123
        work = WorkingTree.open('current')
 
124
        self.assertEndsWith(work.branch.base, '/b/')
 
125
        self.assertContainsRe(err, "Switched to branch: .*/b/")
 
126
 
55
127
    def test_branch_only_copies_history(self):
56
128
        # Knit branches should only push the history for the current revision.
57
129
        format = bzrdir.BzrDirMetaFormat1()
149
221
class TestBranchStacked(ExternalBase):
150
222
    """Tests for branch --stacked"""
151
223
 
152
 
    def check_shallow_branch(self, branch_revid, stacked_on):
153
 
        """Assert that the branch 'newbranch' has been published correctly.
154
 
 
155
 
        :param stacked_on: url of a branch this one is stacked upon.
156
 
        :param branch_revid: a revision id that should be the only
157
 
            revision present in the stacked branch, and it should not be in
158
 
            the reference branch.
159
 
        """
160
 
        new_branch = branch.Branch.open('newbranch')
161
 
        # The branch refers to the mainline
162
 
        self.assertEqual(stacked_on, new_branch.get_stacked_on_url())
163
 
        # and the branch's work was pushed
164
 
        self.assertTrue(new_branch.repository.has_revision(branch_revid))
165
 
        # The newly committed revision shoud be present in the stacked branch,
166
 
        # but not in the stacked-on branch.  Because stacking is set up by the
167
 
        # branch object, if we open the stacked branch's repository directly,
168
 
        # bypassing the branch, we see only what's in the stacked repository.
169
 
        stacked_repo = bzrdir.BzrDir.open('newbranch').open_repository()
170
 
        stacked_repo_revisions = set(stacked_repo.all_revision_ids())
171
 
        if len(stacked_repo_revisions) != 1:
172
 
            self.fail("wrong revisions in stacked repository: %r"
173
 
                % (stacked_repo_revisions,))
174
 
 
175
224
    def assertRevisionInRepository(self, repo_path, revid):
176
225
        """Check that a revision is in a repository, disregarding stacking."""
177
226
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
198
247
            format='1.9')
199
248
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
200
249
        # with some work on it
201
 
        branch_tree.commit('moar work plz')
 
250
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
 
251
        work_tree.commit('moar work plz')
 
252
        work_tree.branch.push(branch_tree.branch)
202
253
        # branching our local branch gives us a new stacked branch pointing at
203
254
        # mainline.
204
255
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
205
256
        self.assertEqual('', out)
206
 
        self.assertEqual('Branched 1 revision(s).\n',
 
257
        self.assertEqual('Branched 2 revision(s).\n',
207
258
            err)
208
259
        # it should have preserved the branch format, and so it should be
209
260
        # capable of supporting stacking, but not actually have a stacked_on
222
273
            format='1.9')
223
274
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
224
275
        # with some work on it
225
 
        branch_revid = branch_tree.commit('moar work plz')
 
276
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
 
277
        branch_revid = work_tree.commit('moar work plz')
 
278
        work_tree.branch.push(branch_tree.branch)
226
279
        # you can chain branches on from there
227
280
        out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
228
281
        self.assertEqual('', out)
231
284
        self.assertEqual(branch_tree.branch.base,
232
285
            branch.Branch.open('branch2').get_stacked_on_url())
233
286
        branch2_tree = WorkingTree.open('branch2')
234
 
        branch2_revid = branch2_tree.commit('work on second stacked branch')
 
287
        branch2_revid = work_tree.commit('work on second stacked branch')
 
288
        work_tree.branch.push(branch2_tree.branch)
235
289
        self.assertRevisionInRepository('branch2', branch2_revid)
236
290
        self.assertRevisionsInBranchRepository(
237
291
            [trunk_revid, branch_revid, branch2_revid],
250
304
        self.assertEqual('Created new stacked branch referring to %s.\n' %
251
305
            trunk_tree.branch.base, err)
252
306
        self.assertRevisionNotInRepository('newbranch', original_revid)
253
 
        new_tree = WorkingTree.open('newbranch')
254
 
        new_revid = new_tree.commit('new work')
255
 
        self.check_shallow_branch(new_revid, trunk_tree.branch.base)
 
307
        new_branch = branch.Branch.open('newbranch')
 
308
        self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
256
309
 
257
310
    def test_branch_stacked_from_smart_server(self):
258
311
        # We can branch stacking on a smart server
329
382
            t.commit(message='commit %d' % count)
330
383
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
331
384
            ).open_workingtree()
332
 
        tree2.commit('feature change')
 
385
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
 
386
        local_tree.commit('feature change')
 
387
        local_tree.branch.push(tree2.branch)
333
388
        self.reset_smart_call_log()
334
389
        out, err = self.run_bzr(['branch', self.get_url('feature'),
335
390
            'local-target'])