/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
205
    def test_push(self):
206
        c1 = self.remote_real.do_commit(
207
                message='message',
208
                committer='committer <committer@example.com>',
209
                author='author <author@example.com>')
210
211
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
212
        self.make_controldir('local', format=self._from_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
213
        local = remote.sprout('local')
214
        self.build_tree(['local/blah'])
215
        wt = local.open_workingtree()
216
        wt.add(['blah'])
217
        revid = wt.commit('blah')
218
        wt.branch.tags.set_tag('sometag', revid)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
219
        wt.branch.get_config_stack().set('branch.fetch_tags', True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
220
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
221
        if self._from_format == 'git':
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
222
            wt.branch.push(remote.create_branch('newbranch'))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
223
        else:
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
224
            wt.branch.push(remote.create_branch('newbranch'), lossy=True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
225
226
        self.assertEqual(
227
                {'refs/heads/master': self.remote_real.head(),
228
                 'HEAD': self.remote_real.head(),
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
229
                 'refs/heads/newbranch': self.remote_real.refs['refs/heads/newbranch'],
230
                 'refs/tags/sometag': self.remote_real.refs['refs/heads/newbranch'],
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
231
                },
232
                self.remote_real.get_refs())
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
233
234
235
class PushToRemoteFromBzrTests(PushToRemoteBase,TestCaseWithTransport):
236
237
    _from_format = '2a'
238
239
240
class PushToRemoteFromGitTests(PushToRemoteBase,TestCaseWithTransport):
241
242
    _from_format = 'git'
243
244
245
class RemoteControlDirTests(TestCaseWithTransport):
246
247
    _test_needs_features = [ExecutableFeature('git')]
248
249
    def setUp(self):
250
        TestCaseWithTransport.setUp(self)
251
        self.remote_real = GitRepo.init('remote', mkdir=True)
252
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
253
        self.permit_url(self.remote_url)
254
255
    def test_remove_branch(self):
256
        c1 = self.remote_real.do_commit(
257
                message='message',
258
                committer='committer <committer@example.com>',
259
                author='author <author@example.com>')
260
        c2 = self.remote_real.do_commit(
261
                message='another commit',
262
                committer='committer <committer@example.com>',
263
                author='author <author@example.com>',
264
                ref='refs/heads/blah')
265
266
        remote = ControlDir.open(self.remote_url)
267
        remote.destroy_branch(name='blah')
268
        self.assertEqual(
269
                self.remote_real.get_refs(),
270
                {'refs/heads/master': self.remote_real.head(),
271
                 'HEAD': self.remote_real.head(),
272
                })
273
274
    def test_list_branches(self):
275
        c1 = self.remote_real.do_commit(
276
                message='message',
277
                committer='committer <committer@example.com>',
278
                author='author <author@example.com>')
279
        c2 = self.remote_real.do_commit(
280
                message='another commit',
281
                committer='committer <committer@example.com>',
282
                author='author <author@example.com>',
283
                ref='refs/heads/blah')
284
285
        remote = ControlDir.open(self.remote_url)
286
        self.assertEqual(
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
287
                ['master', 'blah', 'master'],
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
288
                [b.name for b in remote.list_branches()])
289
290
    def test_get_branches(self):
291
        c1 = self.remote_real.do_commit(
292
                message='message',
293
                committer='committer <committer@example.com>',
294
                author='author <author@example.com>')
295
        c2 = self.remote_real.do_commit(
296
                message='another commit',
297
                committer='committer <committer@example.com>',
298
                author='author <author@example.com>',
299
                ref='refs/heads/blah')
300
301
        remote = ControlDir.open(self.remote_url)
302
        self.assertEqual(
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
303
                {'': 'master', 'blah': 'blah', 'master': 'master'},
304
                {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.
305
306
    def test_remove_tag(self):
307
        c1 = self.remote_real.do_commit(
308
                message='message',
309
                committer='committer <committer@example.com>',
310
                author='author <author@example.com>')
311
        c2 = self.remote_real.do_commit(
312
                message='another commit',
313
                committer='committer <committer@example.com>',
314
                author='author <author@example.com>',
315
                ref='refs/tags/blah')
316
317
        remote = ControlDir.open(self.remote_url)
318
        remote_branch = remote.open_branch()
319
        remote_branch.tags.delete_tag('blah')
320
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
321
        self.assertEqual(
322
                self.remote_real.get_refs(),
323
                {'refs/heads/master': self.remote_real.head(),
324
                 'HEAD': self.remote_real.head(),
325
                })
326
327
    def test_set_tag(self):
328
        c1 = self.remote_real.do_commit(
329
                message='message',
330
                committer='committer <committer@example.com>',
331
                author='author <author@example.com>')
332
        c2 = self.remote_real.do_commit(
333
                message='another commit',
334
                committer='committer <committer@example.com>',
335
                author='author <author@example.com>')
336
337
        remote = ControlDir.open(self.remote_url)
338
        remote.open_branch().tags.set_tag(
339
            'blah', default_mapping.revision_id_foreign_to_bzr(c1))
340
        self.assertEqual(
341
                self.remote_real.get_refs(),
342
                {'refs/heads/master': self.remote_real.head(),
343
                 'refs/tags/blah': c1,
344
                 'HEAD': self.remote_real.head(),
345
                })
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
346
347
    def test_annotated_tag(self):
348
        c1 = self.remote_real.do_commit(
349
                message='message',
350
                committer='committer <committer@example.com>',
351
                author='author <author@example.com>')
352
        c2 = self.remote_real.do_commit(
353
                message='another commit',
354
                committer='committer <committer@example.com>',
355
                author='author <author@example.com>')
356
357
        porcelain.tag_create(
358
                self.remote_real,
359
                tag="blah",
360
                author='author <author@example.com>',
361
                objectish=c2,
362
                tag_time=int(time.time()),
363
                tag_timezone=0,
364
                annotated=True,
365
                message="Annotated tag")
366
367
        remote = ControlDir.open(self.remote_url)
368
        remote_branch = remote.open_branch()
369
        self.assertEqual({
370
            'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
371
            remote_branch.tags.get_tag_dict())
372
373
    def tetst_get_branch_reference(self):
374
        c1 = self.remote_real.do_commit(
375
                message='message',
376
                committer='committer <committer@example.com>',
377
                author='author <author@example.com>')
378
        c2 = self.remote_real.do_commit(
379
                message='another commit',
380
                committer='committer <committer@example.com>',
381
                author='author <author@example.com>')
382
383
        remote = ControlDir.open(self.remote_url)
384
        self.assertEqual('refs/heads/master', remote.get_branch_reference(''))
385
        self.assertEqual(None, remote.get_branch_reference('master'))