~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-02-13 07:46:08 UTC
  • mfrom: (2279.1.3 push_readonly)
  • Revision ID: pqm@pqm.ubuntu.com-20070213074608-337e1db89805f74d
(John Arbash Meinel) Fix pushing branches within the same repository by using a read lock on the source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
        self.assertRaises(errors.BoundBranchConnectionFailure,
91
91
                other.branch.push, checkout.branch)
92
92
 
 
93
    def test_push_uses_read_lock(self):
 
94
        """Push should only need a read lock on the source side."""
 
95
        source = self.make_branch_and_tree('source')
 
96
        target = self.make_branch('target')
 
97
 
 
98
        self.build_tree(['source/a'])
 
99
        source.add(['a'])
 
100
        source.commit('a')
 
101
 
 
102
        source.branch.lock_read()
 
103
        try:
 
104
            target.lock_write()
 
105
            try:
 
106
                source.branch.push(target, stop_revision=source.last_revision())
 
107
            finally:
 
108
                target.unlock()
 
109
        finally:
 
110
            source.branch.unlock()
 
111
 
 
112
    def test_push_within_repository(self):
 
113
        """Push from one branch to another inside the same repository."""
 
114
        try:
 
115
            repo = self.make_repository('repo', shared=True)
 
116
        except (errors.IncompatibleFormat, errors.UninitializableFormat):
 
117
            # This Branch format cannot create shared repositories
 
118
            return
 
119
        # This is a little bit trickier because make_branch_and_tree will not
 
120
        # re-use a shared repository.
 
121
        a_bzrdir = self.make_bzrdir('repo/tree')
 
122
        try:
 
123
            a_branch = self.branch_format.initialize(a_bzrdir)
 
124
        except (errors.UninitializableFormat):
 
125
            # Cannot create these branches
 
126
            return
 
127
        tree = a_branch.bzrdir.create_workingtree()
 
128
        self.build_tree(['repo/tree/a'])
 
129
        tree.add(['a'])
 
130
        tree.commit('a')
 
131
 
 
132
        to_bzrdir = self.make_bzrdir('repo/branch')
 
133
        to_branch = self.branch_format.initialize(to_bzrdir)
 
134
        tree.branch.push(to_branch)
 
135
 
 
136
        self.assertEqual(tree.branch.last_revision(),
 
137
                         to_branch.last_revision())
 
138
 
93
139
 
94
140
class TestPushHook(TestCaseWithBranch):
95
141