/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
16
17
"""Test the smart client."""
18
0.358.3 by Jelmer Vernooij
Enable absolute import.
19
from __future__ import absolute_import
20
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
21
import os
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
22
import time
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
23
24
from ....controldir import ControlDir
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
25
from ....errors import (
0.200.1275 by Jelmer Vernooij
recognize missing repositories
26
    BzrError,
27
    NotBranchError,
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
28
    NoSuchTag,
0.200.1275 by Jelmer Vernooij
recognize missing repositories
29
    )
30
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
31
from ....tests import (
32
    TestCase,
33
    TestCaseWithTransport,
34
    )
35
from ....tests.features import ExecutableFeature
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
36
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
37
from ..mapping import default_mapping
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
38
from ..remote import (
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
39
    split_git_url,
0.200.1275 by Jelmer Vernooij
recognize missing repositories
40
    parse_git_error,
0.295.1 by Jelmer Vernooij
Split up branch formats.
41
    RemoteGitBranchFormat,
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
42
    )
43
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
44
from dulwich import porcelain
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
45
from dulwich.repo import Repo as GitRepo
46
47
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
48
class SplitUrlTests(TestCase):
49
50
    def test_simple(self):
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
51
        self.assertEquals(("foo", None, None, "/bar"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
52
            split_git_url("git://foo/bar"))
53
54
    def test_port(self):
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
55
        self.assertEquals(("foo", 343, None, "/bar"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
56
            split_git_url("git://foo:343/bar"))
57
58
    def test_username(self):
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
59
        self.assertEquals(("foo", None, "la", "/bar"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
60
            split_git_url("git://la@foo/bar"))
61
62
    def test_nopath(self):
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
63
        self.assertEquals(("foo", None, None, "/"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
64
            split_git_url("git://foo/"))
65
66
    def test_slashpath(self):
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
67
        self.assertEquals(("foo", None, None, "//bar"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
68
            split_git_url("git://foo//bar"))
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
69
70
    def test_homedir(self):
71
        self.assertEquals(("foo", None, None, "~bar"),
72
            split_git_url("git://foo/~bar"))
0.200.1275 by Jelmer Vernooij
recognize missing repositories
73
74
75
class ParseGitErrorTests(TestCase):
76
77
    def test_unknown(self):
78
        e = parse_git_error("url", "foo")
79
        self.assertIsInstance(e, BzrError)
80
81
    def test_notbrancherror(self):
82
        e = parse_git_error("url", "\n Could not find Repository foo/bar")
83
        self.assertIsInstance(e, NotBranchError)
0.295.1 by Jelmer Vernooij
Split up branch formats.
84
85
86
class TestRemoteGitBranchFormat(TestCase):
87
88
    def setUp(self):
89
        super(TestRemoteGitBranchFormat, self).setUp()
90
        self.format = RemoteGitBranchFormat()
91
92
    def test_get_format_description(self):
93
        self.assertEquals("Remote Git Branch", self.format.get_format_description())
94
95
    def test_get_network_name(self):
96
        self.assertEquals("git", self.format.network_name())
97
98
    def test_supports_tags(self):
99
        self.assertTrue(self.format.supports_tags())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
100
101
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
102
class FetchFromRemoteTestBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
103
104
    _test_needs_features = [ExecutableFeature('git')]
105
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
106
    _to_format = None
107
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
108
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
109
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
110
        self.remote_real = GitRepo.init('remote', mkdir=True)
111
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
112
        self.permit_url(self.remote_url)
113
114
    def test_sprout_simple(self):
115
        self.remote_real.do_commit(
116
                message='message',
117
                committer='committer <committer@example.com>',
118
                author='author <author@example.com>')
119
120
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
121
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
122
        local = remote.sprout('local')
123
        self.assertEqual(
124
                default_mapping.revision_id_foreign_to_bzr(self.remote_real.head()),
125
                local.open_branch().last_revision())
126
127
    def test_sprout_with_tags(self):
128
        c1 = self.remote_real.do_commit(
129
                message='message',
130
                committer='committer <committer@example.com>',
131
                author='author <author@example.com>')
132
        c2 = self.remote_real.do_commit(
133
                message='another commit',
134
                committer='committer <committer@example.com>',
135
                author='author <author@example.com>',
136
                ref='refs/tags/another')
137
        self.remote_real.refs['refs/tags/blah'] = self.remote_real.head()
138
139
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
140
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
141
        local = remote.sprout('local')
142
        local_branch = local.open_branch()
143
        self.assertEqual(
144
                default_mapping.revision_id_foreign_to_bzr(c1),
145
                local_branch.last_revision())
146
        self.assertEqual(
147
                {'blah': local_branch.last_revision(),
148
                 'another': default_mapping.revision_id_foreign_to_bzr(c2)},
149
                local_branch.tags.get_tag_dict())
150
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
151
    def test_sprout_with_annotated_tag(self):
152
        c1 = self.remote_real.do_commit(
153
                message='message',
154
                committer='committer <committer@example.com>',
155
                author='author <author@example.com>')
156
        c2 = self.remote_real.do_commit(
157
                message='another commit',
158
                committer='committer <committer@example.com>',
159
                author='author <author@example.com>',
160
                ref='refs/heads/another')
161
        porcelain.tag_create(
162
                self.remote_real,
163
                tag="blah",
164
                author='author <author@example.com>',
165
                objectish=c2,
166
                tag_time=int(time.time()),
167
                tag_timezone=0,
168
                annotated=True,
169
                message="Annotated tag")
170
171
        remote = ControlDir.open(self.remote_url)
172
        self.make_controldir('local', format=self._to_format)
173
        local = remote.sprout('local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
174
        local_branch = local.open_branch()
175
        self.assertEqual(
176
                default_mapping.revision_id_foreign_to_bzr(c1),
177
                local_branch.last_revision())
178
        self.assertEqual(
179
                {'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
180
                local_branch.tags.get_tag_dict())
181
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
182
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
183
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase,TestCaseWithTransport):
184
185
    _to_format = '2a'
186
187
188
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase,TestCaseWithTransport):
189
190
    _to_format = 'git'
191
192
193
class PushToRemoteBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
194
195
    _test_needs_features = [ExecutableFeature('git')]
196
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
197
    _from_format = None
198
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
199
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
200
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
201
        self.remote_real = GitRepo.init('remote', mkdir=True)
202
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
203
        self.permit_url(self.remote_url)
204
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
205
    def test_push_branch_new(self):
206
        remote = ControlDir.open(self.remote_url)
207
        wt = self.make_branch_and_tree('local', format=self._from_format)
208
        self.build_tree(['local/blah'])
209
        wt.add(['blah'])
210
        revid = wt.commit('blah')
211
212
        if self._from_format == 'git':
213
            remote.push_branch(wt.branch, name='newbranch')
214
        else:
215
            remote.push_branch(wt.branch, lossy=True, name='newbranch')
216
217
        self.assertEqual(
218
                {'refs/heads/newbranch': self.remote_real.refs['refs/heads/newbranch'],
219
                },
220
                self.remote_real.get_refs())
221
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
222
    def test_push(self):
223
        c1 = self.remote_real.do_commit(
224
                message='message',
225
                committer='committer <committer@example.com>',
226
                author='author <author@example.com>')
227
228
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
229
        self.make_controldir('local', format=self._from_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
230
        local = remote.sprout('local')
231
        self.build_tree(['local/blah'])
232
        wt = local.open_workingtree()
233
        wt.add(['blah'])
234
        revid = wt.commit('blah')
235
        wt.branch.tags.set_tag('sometag', revid)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
236
        wt.branch.get_config_stack().set('branch.fetch_tags', True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
237
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
238
        if self._from_format == 'git':
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
239
            wt.branch.push(remote.create_branch('newbranch'))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
240
        else:
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
241
            wt.branch.push(remote.create_branch('newbranch'), lossy=True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
242
243
        self.assertEqual(
244
                {'refs/heads/master': self.remote_real.head(),
245
                 'HEAD': self.remote_real.head(),
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
246
                 'refs/heads/newbranch': self.remote_real.refs['refs/heads/newbranch'],
247
                 'refs/tags/sometag': self.remote_real.refs['refs/heads/newbranch'],
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
248
                },
249
                self.remote_real.get_refs())
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
250
251
252
class PushToRemoteFromBzrTests(PushToRemoteBase,TestCaseWithTransport):
253
254
    _from_format = '2a'
255
256
257
class PushToRemoteFromGitTests(PushToRemoteBase,TestCaseWithTransport):
258
259
    _from_format = 'git'
260
261
262
class RemoteControlDirTests(TestCaseWithTransport):
263
264
    _test_needs_features = [ExecutableFeature('git')]
265
266
    def setUp(self):
267
        TestCaseWithTransport.setUp(self)
268
        self.remote_real = GitRepo.init('remote', mkdir=True)
269
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
270
        self.permit_url(self.remote_url)
271
272
    def test_remove_branch(self):
273
        c1 = self.remote_real.do_commit(
274
                message='message',
275
                committer='committer <committer@example.com>',
276
                author='author <author@example.com>')
277
        c2 = self.remote_real.do_commit(
278
                message='another commit',
279
                committer='committer <committer@example.com>',
280
                author='author <author@example.com>',
281
                ref='refs/heads/blah')
282
283
        remote = ControlDir.open(self.remote_url)
284
        remote.destroy_branch(name='blah')
285
        self.assertEqual(
286
                self.remote_real.get_refs(),
287
                {'refs/heads/master': self.remote_real.head(),
288
                 'HEAD': self.remote_real.head(),
289
                })
290
291
    def test_list_branches(self):
292
        c1 = self.remote_real.do_commit(
293
                message='message',
294
                committer='committer <committer@example.com>',
295
                author='author <author@example.com>')
296
        c2 = self.remote_real.do_commit(
297
                message='another commit',
298
                committer='committer <committer@example.com>',
299
                author='author <author@example.com>',
300
                ref='refs/heads/blah')
301
302
        remote = ControlDir.open(self.remote_url)
303
        self.assertEqual(
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
304
                ['master', 'blah', 'master'],
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
305
                [b.name for b in remote.list_branches()])
306
307
    def test_get_branches(self):
308
        c1 = self.remote_real.do_commit(
309
                message='message',
310
                committer='committer <committer@example.com>',
311
                author='author <author@example.com>')
312
        c2 = self.remote_real.do_commit(
313
                message='another commit',
314
                committer='committer <committer@example.com>',
315
                author='author <author@example.com>',
316
                ref='refs/heads/blah')
317
318
        remote = ControlDir.open(self.remote_url)
319
        self.assertEqual(
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
320
                {'': 'master', 'blah': 'blah', 'master': 'master'},
321
                {n: b.name for (n, b) in remote.get_branches().items()})
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
322
323
    def test_remove_tag(self):
324
        c1 = self.remote_real.do_commit(
325
                message='message',
326
                committer='committer <committer@example.com>',
327
                author='author <author@example.com>')
328
        c2 = self.remote_real.do_commit(
329
                message='another commit',
330
                committer='committer <committer@example.com>',
331
                author='author <author@example.com>',
332
                ref='refs/tags/blah')
333
334
        remote = ControlDir.open(self.remote_url)
335
        remote_branch = remote.open_branch()
336
        remote_branch.tags.delete_tag('blah')
337
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
338
        self.assertEqual(
339
                self.remote_real.get_refs(),
340
                {'refs/heads/master': self.remote_real.head(),
341
                 'HEAD': self.remote_real.head(),
342
                })
343
344
    def test_set_tag(self):
345
        c1 = self.remote_real.do_commit(
346
                message='message',
347
                committer='committer <committer@example.com>',
348
                author='author <author@example.com>')
349
        c2 = self.remote_real.do_commit(
350
                message='another commit',
351
                committer='committer <committer@example.com>',
352
                author='author <author@example.com>')
353
354
        remote = ControlDir.open(self.remote_url)
355
        remote.open_branch().tags.set_tag(
356
            'blah', default_mapping.revision_id_foreign_to_bzr(c1))
357
        self.assertEqual(
358
                self.remote_real.get_refs(),
359
                {'refs/heads/master': self.remote_real.head(),
360
                 'refs/tags/blah': c1,
361
                 'HEAD': self.remote_real.head(),
362
                })
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
363
364
    def test_annotated_tag(self):
365
        c1 = self.remote_real.do_commit(
366
                message='message',
367
                committer='committer <committer@example.com>',
368
                author='author <author@example.com>')
369
        c2 = self.remote_real.do_commit(
370
                message='another commit',
371
                committer='committer <committer@example.com>',
372
                author='author <author@example.com>')
373
374
        porcelain.tag_create(
375
                self.remote_real,
376
                tag="blah",
377
                author='author <author@example.com>',
378
                objectish=c2,
379
                tag_time=int(time.time()),
380
                tag_timezone=0,
381
                annotated=True,
382
                message="Annotated tag")
383
384
        remote = ControlDir.open(self.remote_url)
385
        remote_branch = remote.open_branch()
386
        self.assertEqual({
387
            'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
388
            remote_branch.tags.get_tag_dict())
389
390
    def tetst_get_branch_reference(self):
391
        c1 = self.remote_real.do_commit(
392
                message='message',
393
                committer='committer <committer@example.com>',
394
                author='author <author@example.com>')
395
        c2 = self.remote_real.do_commit(
396
                message='another commit',
397
                committer='committer <committer@example.com>',
398
                author='author <author@example.com>')
399
400
        remote = ControlDir.open(self.remote_url)
401
        self.assertEqual('refs/heads/master', remote.get_branch_reference(''))
402
        self.assertEqual(None, remote.get_branch_reference('master'))