/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_branch.py

Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
 
60
60
    def make_branch(self, relpath):
61
61
        repo = self.make_repository(relpath)
62
 
        return self.branch_format.initialize(repo.bzrdir)
 
62
        # fixme RBC 20060210 this isnt necessarily a fixable thing,
 
63
        # Skipped is the wrong exception to raise.
 
64
        try:
 
65
            return self.branch_format.initialize(repo.bzrdir)
 
66
        except errors.UninitializableFormat:
 
67
            raise TestSkipped('Uninitializable branch format')
63
68
 
64
69
    def make_repository(self, relpath):
65
70
        try:
93
98
        from bzrlib.fetch import Fetcher
94
99
        get_transport(self.get_url()).mkdir('b1')
95
100
        get_transport(self.get_url()).mkdir('b2')
96
 
        b1 = self.make_branch('b1')
 
101
        wt = self.make_branch_and_tree('b1')
 
102
        b1 = wt.branch
97
103
        b2 = self.make_branch('b2')
98
 
        wt = WorkingTree.create(b1, 'b1')
99
104
        file('b1/foo', 'w').write('hello')
100
105
        wt.add(['foo'], ['foo-id'])
101
106
        wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
113
118
    def get_unbalanced_tree_pair(self):
114
119
        """Return two branches, a and b, with one file in a."""
115
120
        get_transport(self.get_url()).mkdir('a')
116
 
        br_a = self.make_branch('a')
117
 
        tree_a = WorkingTree.create(br_a, 'a')
 
121
        tree_a = self.make_branch_and_tree('a')
118
122
        file('a/b', 'wb').write('b')
119
123
        tree_a.add('b')
120
124
        tree_a.commit("silly commit", rev_id='A')
121
125
 
122
126
        get_transport(self.get_url()).mkdir('b')
123
 
        br_b = self.make_branch('b')
124
 
        tree_b = WorkingTree.create(br_b, 'b')
 
127
        tree_b = self.make_branch_and_tree('b')
125
128
        return tree_a, tree_b
126
129
 
127
130
    def get_balanced_branch_pair(self):
128
131
        """Returns br_a, br_b as with one commit in a, and b has a's stores."""
129
132
        tree_a, tree_b = self.get_unbalanced_tree_pair()
130
 
        tree_a.branch.repository.push_stores(tree_b.branch.repository)
 
133
        tree_b.branch.repository.fetch(tree_a.branch.repository)
131
134
        return tree_a, tree_b
132
135
 
133
136
    def test_clone_branch(self):
136
139
        tree_b.commit("silly commit")
137
140
        os.mkdir('c')
138
141
        # this fails to test that the history from a was not used.
139
 
        br_c = tree_a.branch.clone('c', basis_branch=tree_b.branch)
 
142
        dir_c = tree_a.bzrdir.clone('c', basis=tree_b.bzrdir)
140
143
        self.assertEqual(tree_a.branch.revision_history(),
141
 
                         br_c.revision_history())
 
144
                         dir_c.open_branch().revision_history())
142
145
 
143
146
    def test_clone_partial(self):
144
147
        """Copy only part of the history of a branch."""
145
 
        get_transport(self.get_url()).mkdir('a')
146
 
        br_a = self.make_branch('a')
147
 
        wt = WorkingTree.create(br_a, "a")
148
 
        self.build_tree(['a/one'])
149
 
        wt.add(['one'])
150
 
        wt.commit('commit one', rev_id='u@d-1')
151
 
        self.build_tree(['a/two'])
152
 
        wt.add(['two'])
153
 
        wt.commit('commit two', rev_id='u@d-2')
154
 
        br_b = br_a.clone('b', revision='u@d-1')
155
 
        self.assertEqual(br_b.last_revision(), 'u@d-1')
156
 
        self.assertTrue(os.path.exists('b/one'))
157
 
        self.assertFalse(os.path.exists('b/two'))
 
148
        # TODO: RBC 20060208 test with a revision not on revision-history.
 
149
        #       what should that behaviour be ? Emailed the list.
 
150
        wt_a = self.make_branch_and_tree('a')
 
151
        self.build_tree(['a/one'])
 
152
        wt_a.add(['one'])
 
153
        wt_a.commit('commit one', rev_id='1')
 
154
        self.build_tree(['a/two'])
 
155
        wt_a.add(['two'])
 
156
        wt_a.commit('commit two', rev_id='2')
 
157
        repo_b = self.make_repository('b')
 
158
        wt_a.bzrdir.open_repository().copy_content_into(repo_b)
 
159
        br_b = wt_a.bzrdir.open_branch().clone(repo_b.bzrdir, revision_id='1')
 
160
        self.assertEqual(br_b.last_revision(), '1')
 
161
 
 
162
    def test_sprout_partial(self):
 
163
        # test sprouting with a prefix of the revision-history.
 
164
        # also needs not-on-revision-history behaviour defined.
 
165
        wt_a = self.make_branch_and_tree('a')
 
166
        self.build_tree(['a/one'])
 
167
        wt_a.add(['one'])
 
168
        wt_a.commit('commit one', rev_id='1')
 
169
        self.build_tree(['a/two'])
 
170
        wt_a.add(['two'])
 
171
        wt_a.commit('commit two', rev_id='2')
 
172
        repo_b = self.make_repository('b')
 
173
        wt_a.bzrdir.open_repository().copy_content_into(repo_b)
 
174
        br_b = wt_a.bzrdir.open_branch().sprout(repo_b.bzrdir, revision_id='1')
 
175
        self.assertEqual(br_b.last_revision(), '1')
 
176
 
 
177
    def test_clone_branch_nickname(self):
 
178
        # test the nick name is preserved always
 
179
        raise TestSkipped('XXX branch cloning is not yet tested..')
 
180
 
 
181
    def test_clone_branch_parent(self):
 
182
        # test the parent is preserved always
 
183
        raise TestSkipped('XXX branch cloning is not yet tested..')
 
184
        
 
185
    def test_sprout_branch_nickname(self):
 
186
        # test the nick name is reset always
 
187
        raise TestSkipped('XXX branch sprouting is not yet tested..')
 
188
 
 
189
    def test_sprout_branch_parent(self):
 
190
        source = self.make_branch('source')
 
191
        target = source.bzrdir.sprout(self.get_url('target')).open_branch()
 
192
        self.assertEqual(source.bzrdir.root_transport.base, target.get_parent())
158
193
        
159
194
    def test_record_initial_ghost_merge(self):
160
195
        """A pending merge with no revision present is still a merge."""
161
 
        branch = self.get_branch()
162
 
        wt = WorkingTree.create(branch, ".")
 
196
        wt = self.make_branch_and_tree('.')
 
197
        branch = wt.branch
163
198
        wt.add_pending_merge('non:existent@rev--ision--0--2')
164
199
        wt.commit('pretend to merge nonexistent-revision', rev_id='first')
165
200
        rev = branch.repository.get_revision(branch.last_revision())
180
215
        
181
216
    def test_pending_merges(self):
182
217
        """Tracking pending-merged revisions."""
183
 
        b = self.get_branch()
184
 
        wt = WorkingTree.create(b, '.')
 
218
        wt = self.make_branch_and_tree('.')
 
219
        b = wt.branch
185
220
        self.assertEquals(wt.pending_merges(), [])
186
221
        wt.add_pending_merge('foo@azkhazan-123123-abcabc')
187
222
        self.assertEquals(wt.pending_merges(), ['foo@azkhazan-123123-abcabc'])
202
237
        self.assertEquals(wt.pending_merges(), [])
203
238
 
204
239
    def test_sign_existing_revision(self):
205
 
        branch = self.get_branch()
206
 
        wt = WorkingTree.create(branch, ".")
 
240
        wt = self.make_branch_and_tree('.')
 
241
        branch = wt.branch
207
242
        wt.commit("base", allow_pointless=True, rev_id='A')
208
243
        from bzrlib.testament import Testament
209
244
        strategy = bzrlib.gpg.LoopbackGPGStrategy(None)
229
264
        #FIXME: clone should work to urls,
230
265
        # wt.clone should work to disks.
231
266
        self.build_tree(['target/'])
232
 
        b2 = wt.branch.clone('target')
 
267
        d2 = wt.bzrdir.clone('target')
233
268
        self.assertEqual(wt.branch.repository.revision_store.get('A', 
234
269
                            'sig').read(),
235
 
                         b2.repository.revision_store.get('A', 
 
270
                         d2.open_repository().revision_store.get('A', 
236
271
                            'sig').read())
237
272
 
238
273
    def test_upgrade_preserves_signatures(self):
244
279
        old_signature = wt.branch.repository.revision_store.get('A',
245
280
            'sig').read()
246
281
        upgrade(wt.basedir)
247
 
        wt = WorkingTree(wt.basedir)
 
282
        wt = WorkingTree.open(wt.basedir)
248
283
        new_signature = wt.branch.repository.revision_store.get('A',
249
284
            'sig').read()
250
285
        self.assertEqual(old_signature, new_signature)
277
312
    def test_commit_nicks(self):
278
313
        """Nicknames are committed to the revision"""
279
314
        get_transport(self.get_url()).mkdir('bzr.dev')
280
 
        branch = self.make_branch('bzr.dev')
 
315
        wt = self.make_branch_and_tree('bzr.dev')
 
316
        branch = wt.branch
281
317
        branch.nick = "My happy branch"
282
 
        WorkingTree.create(branch, 'bzr.dev').commit('My commit respect da nick.')
 
318
        wt.commit('My commit respect da nick.')
283
319
        committed = branch.repository.get_revision(branch.last_revision())
284
320
        self.assertEqual(committed.properties["branch-nick"], 
285
321
                         "My happy branch")