/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

Move working tree initialisation out from  Branch.initialize, deprecated Branch.initialize to Branch.create.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 
54
54
    def get_branch(self):
55
55
        if self.branch is None:
56
 
            self.branch = self.make_branch(self.get_url())
 
56
            self.branch = self.make_branch(None)
57
57
        return self.branch
58
58
 
59
59
    def make_branch(self, relpath):
60
60
        try:
61
 
            return self.branch_format.initialize(relpath)
 
61
            return self.branch_format.initialize(self.get_url(relpath))
62
62
        except UninitializableFormat:
63
63
            raise TestSkipped("Format %s is not initializable.")
64
64
 
76
76
    def test_fetch_revisions(self):
77
77
        """Test fetch-revision operation."""
78
78
        from bzrlib.fetch import Fetcher
79
 
        os.mkdir('b1')
80
 
        os.mkdir('b2')
 
79
        get_transport(self.get_url()).mkdir('b1')
 
80
        get_transport(self.get_url()).mkdir('b2')
81
81
        b1 = self.make_branch('b1')
82
82
        b2 = self.make_branch('b2')
 
83
        wt = WorkingTree.create(b1, 'b1')
83
84
        file('b1/foo', 'w').write('hello')
84
 
        wt = WorkingTree('b1', b1)
85
85
        wt.add(['foo'], ['foo-id'])
86
86
        wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
87
87
 
97
97
 
98
98
    def test_revision_tree(self):
99
99
        b1 = self.get_branch()
100
 
        wt = WorkingTree('.', b1)
 
100
        wt = WorkingTree.create(b1, '.')
101
101
        wt.commit('lala!', rev_id='revision-1', allow_pointless=True)
102
102
        tree = b1.revision_tree('revision-1')
103
103
        tree = b1.revision_tree(None)
105
105
        tree = b1.revision_tree(NULL_REVISION)
106
106
        self.assertEqual(len(tree.list_files()), 0)
107
107
 
108
 
    def get_unbalanced_branch_pair(self):
 
108
    def get_unbalanced_tree_pair(self):
109
109
        """Return two branches, a and b, with one file in a."""
110
 
        os.mkdir('a')
 
110
        get_transport(self.get_url()).mkdir('a')
111
111
        br_a = self.make_branch('a')
 
112
        tree_a = WorkingTree.create(br_a, 'a')
112
113
        file('a/b', 'wb').write('b')
113
 
        WorkingTree("a", br_a).add('b')
114
 
        commit(br_a, "silly commit", rev_id='A')
115
 
        os.mkdir('b')
 
114
        tree_a.add('b')
 
115
        tree_a.commit("silly commit", rev_id='A')
 
116
 
 
117
        get_transport(self.get_url()).mkdir('b')
116
118
        br_b = self.make_branch('b')
117
 
        return br_a, br_b
 
119
        tree_b = WorkingTree.create(br_b, 'b')
 
120
        return tree_a, tree_b
118
121
 
119
122
    def get_balanced_branch_pair(self):
120
123
        """Returns br_a, br_b as with one commit in a, and b has a's stores."""
121
 
        br_a, br_b = self.get_unbalanced_branch_pair()
122
 
        br_a.push_stores(br_b)
123
 
        return br_a, br_b
 
124
        tree_a, tree_b = self.get_unbalanced_tree_pair()
 
125
        tree_a.branch.push_stores(tree_b.branch)
 
126
        return tree_a, tree_b
124
127
 
125
128
    def test_push_stores(self):
126
129
        """Copy the stores from one branch to another"""
127
 
        br_a, br_b = self.get_unbalanced_branch_pair()
 
130
        tree_a, tree_b = self.get_unbalanced_tree_pair()
 
131
        br_a = tree_a.branch
 
132
        br_b = tree_b.branch
128
133
        # ensure the revision is missing.
129
134
        self.assertRaises(NoSuchRevision, br_b.get_revision, 
130
135
                          br_a.revision_history()[0])
135
140
        for file_id in tree:
136
141
            if tree.inventory[file_id].kind == "file":
137
142
                tree.get_file(file_id).read()
138
 
        return br_a, br_b
139
143
 
140
144
    def test_copy_branch(self):
141
145
        """Copy the stores from one branch to another"""
142
 
        br_a, br_b = self.get_balanced_branch_pair()
143
 
        commit(br_b, "silly commit")
 
146
        tree_a, tree_b = self.get_balanced_branch_pair()
 
147
        tree_b.commit("silly commit")
144
148
        os.mkdir('c')
145
 
        br_c = copy_branch(br_a, 'c', basis_branch=br_b)
146
 
        self.assertEqual(br_a.revision_history(), br_c.revision_history())
 
149
        br_c = copy_branch(tree_a.branch, 'c', basis_branch=tree_b.branch)
 
150
        self.assertEqual(tree_a.branch.revision_history(),
 
151
                         br_c.revision_history())
147
152
 
148
153
    def test_copy_partial(self):
149
154
        """Copy only part of the history of a branch."""
150
 
        self.build_tree(['a/', 'a/one'])
 
155
        get_transport(self.get_url()).mkdir('a')
151
156
        br_a = self.make_branch('a')
152
 
        wt = WorkingTree("a", br_a)
 
157
        wt = WorkingTree.create(br_a, "a")
 
158
        self.build_tree(['a/one'])
153
159
        wt.add(['one'])
154
160
        wt.commit('commit one', rev_id='u@d-1')
155
161
        self.build_tree(['a/two'])
163
169
    def test_record_initial_ghost_merge(self):
164
170
        """A pending merge with no revision present is still a merge."""
165
171
        branch = self.get_branch()
166
 
        wt = WorkingTree(".", branch)
 
172
        wt = WorkingTree.create(branch, ".")
167
173
        wt.add_pending_merge('non:existent@rev--ision--0--2')
168
174
        wt.commit('pretend to merge nonexistent-revision', rev_id='first')
169
175
        rev = branch.get_revision(branch.last_revision())
183
189
    def test_pending_merges(self):
184
190
        """Tracking pending-merged revisions."""
185
191
        b = self.get_branch()
186
 
        wt = WorkingTree(".", b)
 
192
        wt = WorkingTree.create(b, '.')
187
193
        self.assertEquals(wt.pending_merges(), [])
188
194
        wt.add_pending_merge('foo@azkhazan-123123-abcabc')
189
195
        self.assertEquals(wt.pending_merges(), ['foo@azkhazan-123123-abcabc'])
205
211
 
206
212
    def test_sign_existing_revision(self):
207
213
        branch = self.get_branch()
208
 
        WorkingTree(".", branch).commit("base", allow_pointless=True,
209
 
                                        rev_id='A')
 
214
        wt = WorkingTree.create(branch, ".")
 
215
        wt.commit("base", allow_pointless=True, rev_id='A')
210
216
        from bzrlib.testament import Testament
211
217
        branch.sign_revision('A', bzrlib.gpg.LoopbackGPGStrategy(None))
212
218
        self.assertEqual(Testament.from_revision(branch, 'A').as_short_text(),
226
232
 
227
233
    def test_nicks(self):
228
234
        """Branch nicknames"""
229
 
        os.mkdir('bzr.dev')
 
235
        t = get_transport(self.get_url())
 
236
        t.mkdir('bzr.dev')
230
237
        branch = self.make_branch('bzr.dev')
231
238
        self.assertEqual(branch.nick, 'bzr.dev')
232
 
        os.rename('bzr.dev', 'bzr.ab')
233
 
        branch = Branch.open('bzr.ab')
 
239
        t.move('bzr.dev', 'bzr.ab')
 
240
        branch = Branch.open(self.get_url('bzr.ab'))
234
241
        self.assertEqual(branch.nick, 'bzr.ab')
235
242
        branch.nick = "Aaron's branch"
236
243
        branch.nick = "Aaron's branch"
237
 
        self.failUnless(os.path.exists(branch.controlfilename("branch.conf")))
 
244
        self.failUnless(t.has(t.relpath(branch.controlfilename("branch.conf"))))
238
245
        self.assertEqual(branch.nick, "Aaron's branch")
239
 
        os.rename('bzr.ab', 'integration')
240
 
        branch = Branch.open('integration')
 
246
        t.move('bzr.ab', 'integration')
 
247
        branch = Branch.open(self.get_url('integration'))
241
248
        self.assertEqual(branch.nick, "Aaron's branch")
242
249
        branch.nick = u"\u1234"
243
250
        self.assertEqual(branch.nick, u"\u1234")
244
251
 
245
252
    def test_commit_nicks(self):
246
253
        """Nicknames are committed to the revision"""
247
 
        os.mkdir('bzr.dev')
248
 
        branch = self.get_branch()
 
254
        get_transport(self.get_url()).mkdir('bzr.dev')
 
255
        branch = self.make_branch('bzr.dev')
249
256
        branch.nick = "My happy branch"
250
 
        WorkingTree('.', branch).commit('My commit respect da nick.')
 
257
        WorkingTree.create(branch, 'bzr.dev').commit('My commit respect da nick.')
251
258
        committed = branch.get_revision(branch.last_revision())
252
259
        self.assertEqual(committed.properties["branch-nick"], 
253
260
                         "My happy branch")
255
262
    def test_no_ancestry_weave(self):
256
263
        # We no longer need to create the ancestry.weave file
257
264
        # since it is *never* used.
258
 
        branch = Branch.initialize(u'.')
 
265
        branch = Branch.create('.')
259
266
        self.failIfExists('.bzr/ancestry.weave')
260
267
 
261
268
 
269
276
 
270
277
    def setUp(self):
271
278
        super(ChrootedTests, self).setUp()
272
 
        if not isinstance(self.transport_server, MemoryServer):
 
279
        if not self.transport_server == MemoryServer:
273
280
            self.transport_readonly_server = HttpServer
274
281
 
275
282
    def test_open_containing(self):