/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 breezy/git/tests/test_remote.py

  • Committer: Jelmer Vernooij
  • Date: 2019-10-28 01:38:39 UTC
  • mto: This revision was merged to the branch mainline in revision 7412.
  • Revision ID: jelmer@jelmer.uk-20191028013839-q63zzm4yr0id9b3o
Allow unknown extras in git commits when just inspecting revisions, rather than importing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
 
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Test the smart client."""
 
18
 
 
19
from __future__ import absolute_import
 
20
 
 
21
from io import BytesIO
 
22
 
 
23
import os
 
24
import time
 
25
 
 
26
from ...controldir import ControlDir
 
27
from ...errors import (
 
28
    DivergedBranches,
 
29
    NotBranchError,
 
30
    NoSuchTag,
 
31
    PermissionDenied,
 
32
    )
 
33
 
 
34
from ...tests import (
 
35
    TestCase,
 
36
    TestCaseWithTransport,
 
37
    )
 
38
from ...tests.features import ExecutableFeature
 
39
 
 
40
from ..mapping import default_mapping
 
41
from ..remote import (
 
42
    split_git_url,
 
43
    parse_git_error,
 
44
    HeadUpdateFailed,
 
45
    RemoteGitError,
 
46
    RemoteGitBranchFormat,
 
47
    _git_url_and_path_from_transport,
 
48
    )
 
49
 
 
50
from dulwich import porcelain
 
51
from dulwich.repo import Repo as GitRepo
 
52
 
 
53
 
 
54
class SplitUrlTests(TestCase):
 
55
 
 
56
    def test_simple(self):
 
57
        self.assertEqual(("foo", None, None, "/bar"),
 
58
                         split_git_url("git://foo/bar"))
 
59
 
 
60
    def test_port(self):
 
61
        self.assertEqual(("foo", 343, None, "/bar"),
 
62
                         split_git_url("git://foo:343/bar"))
 
63
 
 
64
    def test_username(self):
 
65
        self.assertEqual(("foo", None, "la", "/bar"),
 
66
                         split_git_url("git://la@foo/bar"))
 
67
 
 
68
    def test_nopath(self):
 
69
        self.assertEqual(("foo", None, None, "/"),
 
70
                         split_git_url("git://foo/"))
 
71
 
 
72
    def test_slashpath(self):
 
73
        self.assertEqual(("foo", None, None, "//bar"),
 
74
                         split_git_url("git://foo//bar"))
 
75
 
 
76
    def test_homedir(self):
 
77
        self.assertEqual(("foo", None, None, "~bar"),
 
78
                         split_git_url("git://foo/~bar"))
 
79
 
 
80
 
 
81
class ParseGitErrorTests(TestCase):
 
82
 
 
83
    def test_unknown(self):
 
84
        e = parse_git_error("url", "foo")
 
85
        self.assertIsInstance(e, RemoteGitError)
 
86
 
 
87
    def test_notbrancherror(self):
 
88
        e = parse_git_error("url", "\n Could not find Repository foo/bar")
 
89
        self.assertIsInstance(e, NotBranchError)
 
90
 
 
91
    def test_notbrancherror_launchpad(self):
 
92
        e = parse_git_error("url", "Repository 'foo/bar' not found.")
 
93
        self.assertIsInstance(e, NotBranchError)
 
94
 
 
95
    def test_notbrancherror_github(self):
 
96
        e = parse_git_error("url", "Repository not found.\n")
 
97
        self.assertIsInstance(e, NotBranchError)
 
98
 
 
99
    def test_notbrancherror_normal(self):
 
100
        e = parse_git_error(
 
101
            "url", "fatal: '/srv/git/lintian-brush' does not appear to be a git repository")
 
102
        self.assertIsInstance(e, NotBranchError)
 
103
 
 
104
    def test_head_update(self):
 
105
        e = parse_git_error("url", "HEAD failed to update\n")
 
106
        self.assertIsInstance(e, HeadUpdateFailed)
 
107
 
 
108
    def test_permission_dnied(self):
 
109
        e = parse_git_error(
 
110
            "url",
 
111
            "access denied or repository not exported: /debian/altermime.git")
 
112
        self.assertIsInstance(e, PermissionDenied)
 
113
 
 
114
    def test_permission_denied_gitlab(self):
 
115
        e = parse_git_error(
 
116
            "url",
 
117
            'GitLab: You are not allowed to push code to this project.\n')
 
118
        self.assertIsInstance(e, PermissionDenied)
 
119
 
 
120
    def test_permission_denied_github(self):
 
121
        e = parse_git_error(
 
122
            "url",
 
123
            'Permission to porridge/gaduhistory.git denied to jelmer.')
 
124
        self.assertIsInstance(e, PermissionDenied)
 
125
        self.assertEqual(e.path, 'porridge/gaduhistory.git')
 
126
        self.assertEqual(e.extra, ': denied to jelmer')
 
127
 
 
128
    def test_invalid_repo_name(self):
 
129
        e = parse_git_error(
 
130
            "url",
 
131
            """Gregwar/fatcat/tree/debian is not a valid repository name
 
132
Email support@github.com for help
 
133
""")
 
134
        self.assertIsInstance(e, NotBranchError)
 
135
 
 
136
 
 
137
class TestRemoteGitBranchFormat(TestCase):
 
138
 
 
139
    def setUp(self):
 
140
        super(TestRemoteGitBranchFormat, self).setUp()
 
141
        self.format = RemoteGitBranchFormat()
 
142
 
 
143
    def test_get_format_description(self):
 
144
        self.assertEqual("Remote Git Branch",
 
145
                         self.format.get_format_description())
 
146
 
 
147
    def test_get_network_name(self):
 
148
        self.assertEqual(b"git", self.format.network_name())
 
149
 
 
150
    def test_supports_tags(self):
 
151
        self.assertTrue(self.format.supports_tags())
 
152
 
 
153
 
 
154
class TestRemoteGitBranch(TestCaseWithTransport):
 
155
 
 
156
    _test_needs_features = [ExecutableFeature('git')]
 
157
 
 
158
    def setUp(self):
 
159
        TestCaseWithTransport.setUp(self)
 
160
        self.remote_real = GitRepo.init('remote', mkdir=True)
 
161
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
 
162
        self.permit_url(self.remote_url)
 
163
 
 
164
    def test_set_last_revision_info(self):
 
165
        c1 = self.remote_real.do_commit(
 
166
            message=b'message 1',
 
167
            committer=b'committer <committer@example.com>',
 
168
            author=b'author <author@example.com>',
 
169
            ref=b'refs/heads/newbranch')
 
170
        c2 = self.remote_real.do_commit(
 
171
            message=b'message 2',
 
172
            committer=b'committer <committer@example.com>',
 
173
            author=b'author <author@example.com>',
 
174
            ref=b'refs/heads/newbranch')
 
175
 
 
176
        remote = ControlDir.open(self.remote_url)
 
177
        newbranch = remote.open_branch('newbranch')
 
178
        self.assertEqual(newbranch.lookup_foreign_revision_id(c2),
 
179
                         newbranch.last_revision())
 
180
        newbranch.set_last_revision_info(
 
181
            1, newbranch.lookup_foreign_revision_id(c1))
 
182
        self.assertEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
 
183
        self.assertEqual(newbranch.last_revision(),
 
184
                         newbranch.lookup_foreign_revision_id(c1))
 
185
 
 
186
 
 
187
class FetchFromRemoteTestBase(object):
 
188
 
 
189
    _test_needs_features = [ExecutableFeature('git')]
 
190
 
 
191
    _to_format = None
 
192
 
 
193
    def setUp(self):
 
194
        TestCaseWithTransport.setUp(self)
 
195
        self.remote_real = GitRepo.init('remote', mkdir=True)
 
196
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
 
197
        self.permit_url(self.remote_url)
 
198
 
 
199
    def test_sprout_simple(self):
 
200
        self.remote_real.do_commit(
 
201
            message=b'message',
 
202
            committer=b'committer <committer@example.com>',
 
203
            author=b'author <author@example.com>')
 
204
 
 
205
        remote = ControlDir.open(self.remote_url)
 
206
        self.make_controldir('local', format=self._to_format)
 
207
        local = remote.sprout('local')
 
208
        self.assertEqual(
 
209
            default_mapping.revision_id_foreign_to_bzr(
 
210
                self.remote_real.head()),
 
211
            local.open_branch().last_revision())
 
212
 
 
213
    def test_sprout_with_tags(self):
 
214
        c1 = self.remote_real.do_commit(
 
215
            message=b'message',
 
216
            committer=b'committer <committer@example.com>',
 
217
            author=b'author <author@example.com>')
 
218
        c2 = self.remote_real.do_commit(
 
219
            message=b'another commit',
 
220
            committer=b'committer <committer@example.com>',
 
221
            author=b'author <author@example.com>',
 
222
            ref=b'refs/tags/another')
 
223
        self.remote_real.refs[b'refs/tags/blah'] = self.remote_real.head()
 
224
 
 
225
        remote = ControlDir.open(self.remote_url)
 
226
        self.make_controldir('local', format=self._to_format)
 
227
        local = remote.sprout('local')
 
228
        local_branch = local.open_branch()
 
229
        self.assertEqual(
 
230
            default_mapping.revision_id_foreign_to_bzr(c1),
 
231
            local_branch.last_revision())
 
232
        self.assertEqual(
 
233
            {'blah': local_branch.last_revision(),
 
234
             'another': default_mapping.revision_id_foreign_to_bzr(c2)},
 
235
            local_branch.tags.get_tag_dict())
 
236
 
 
237
    def test_sprout_with_annotated_tag(self):
 
238
        c1 = self.remote_real.do_commit(
 
239
            message=b'message',
 
240
            committer=b'committer <committer@example.com>',
 
241
            author=b'author <author@example.com>')
 
242
        c2 = self.remote_real.do_commit(
 
243
            message=b'another commit',
 
244
            committer=b'committer <committer@example.com>',
 
245
            author=b'author <author@example.com>',
 
246
            ref=b'refs/heads/another')
 
247
        porcelain.tag_create(
 
248
            self.remote_real,
 
249
            tag=b"blah",
 
250
            author=b'author <author@example.com>',
 
251
            objectish=c2,
 
252
            tag_time=int(time.time()),
 
253
            tag_timezone=0,
 
254
            annotated=True,
 
255
            message=b"Annotated tag")
 
256
 
 
257
        remote = ControlDir.open(self.remote_url)
 
258
        self.make_controldir('local', format=self._to_format)
 
259
        local = remote.sprout(
 
260
            'local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
 
261
        local_branch = local.open_branch()
 
262
        self.assertEqual(
 
263
            default_mapping.revision_id_foreign_to_bzr(c1),
 
264
            local_branch.last_revision())
 
265
        self.assertEqual(
 
266
            {'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
 
267
            local_branch.tags.get_tag_dict())
 
268
 
 
269
    def test_sprout_with_annotated_tag_unreferenced(self):
 
270
        c1 = self.remote_real.do_commit(
 
271
            message=b'message',
 
272
            committer=b'committer <committer@example.com>',
 
273
            author=b'author <author@example.com>')
 
274
        c2 = self.remote_real.do_commit(
 
275
            message=b'another commit',
 
276
            committer=b'committer <committer@example.com>',
 
277
            author=b'author <author@example.com>')
 
278
        porcelain.tag_create(
 
279
            self.remote_real,
 
280
            tag=b"blah",
 
281
            author=b'author <author@example.com>',
 
282
            objectish=c1,
 
283
            tag_time=int(time.time()),
 
284
            tag_timezone=0,
 
285
            annotated=True,
 
286
            message=b"Annotated tag")
 
287
 
 
288
        remote = ControlDir.open(self.remote_url)
 
289
        self.make_controldir('local', format=self._to_format)
 
290
        local = remote.sprout(
 
291
            'local',
 
292
            revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
 
293
        local_branch = local.open_branch()
 
294
        self.assertEqual(
 
295
            default_mapping.revision_id_foreign_to_bzr(c1),
 
296
            local_branch.last_revision())
 
297
        self.assertEqual(
 
298
            {'blah': default_mapping.revision_id_foreign_to_bzr(c1)},
 
299
            local_branch.tags.get_tag_dict())
 
300
 
 
301
 
 
302
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase, TestCaseWithTransport):
 
303
 
 
304
    _to_format = '2a'
 
305
 
 
306
 
 
307
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase, TestCaseWithTransport):
 
308
 
 
309
    _to_format = 'git'
 
310
 
 
311
 
 
312
class PushToRemoteBase(object):
 
313
 
 
314
    _test_needs_features = [ExecutableFeature('git')]
 
315
 
 
316
    _from_format = None
 
317
 
 
318
    def setUp(self):
 
319
        TestCaseWithTransport.setUp(self)
 
320
        self.remote_real = GitRepo.init('remote', mkdir=True)
 
321
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
 
322
        self.permit_url(self.remote_url)
 
323
 
 
324
    def test_push_branch_new(self):
 
325
        remote = ControlDir.open(self.remote_url)
 
326
        wt = self.make_branch_and_tree('local', format=self._from_format)
 
327
        self.build_tree(['local/blah'])
 
328
        wt.add(['blah'])
 
329
        revid = wt.commit('blah')
 
330
 
 
331
        if self._from_format == 'git':
 
332
            result = remote.push_branch(wt.branch, name='newbranch')
 
333
        else:
 
334
            result = remote.push_branch(
 
335
                wt.branch, lossy=True, name='newbranch')
 
336
 
 
337
        self.assertEqual(0, result.old_revno)
 
338
        if self._from_format == 'git':
 
339
            self.assertEqual(1, result.new_revno)
 
340
        else:
 
341
            self.assertIs(None, result.new_revno)
 
342
 
 
343
        result.report(BytesIO())
 
344
 
 
345
        self.assertEqual(
 
346
            {b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
 
347
             },
 
348
            self.remote_real.get_refs())
 
349
 
 
350
    def test_push_branch_new_with_tags(self):
 
351
        remote = ControlDir.open(self.remote_url)
 
352
        builder = self.make_branch_builder('local', format=self._from_format)
 
353
        builder.start_series()
 
354
        rev_1 = builder.build_snapshot(None, [
 
355
            ('add', ('', None, 'directory', '')),
 
356
            ('add', ('filename', None, 'file', b'content'))])
 
357
        rev_2 = builder.build_snapshot(
 
358
            [rev_1], [('modify', ('filename', b'new-content\n'))])
 
359
        rev_3 = builder.build_snapshot(
 
360
            [rev_1], [('modify', ('filename', b'new-new-content\n'))])
 
361
        builder.finish_series()
 
362
        branch = builder.get_branch()
 
363
        try:
 
364
            branch.tags.set_tag('atag', rev_2)
 
365
        except TagsNotSupported:
 
366
            raise TestNotApplicable('source format does not support tags')
 
367
 
 
368
        branch.get_config_stack().set('branch.fetch_tags', True)
 
369
        if self._from_format == 'git':
 
370
            result = remote.push_branch(branch, name='newbranch')
 
371
        else:
 
372
            result = remote.push_branch(
 
373
                branch, lossy=True, name='newbranch')
 
374
 
 
375
        self.assertEqual(0, result.old_revno)
 
376
        if self._from_format == 'git':
 
377
            self.assertEqual(2, result.new_revno)
 
378
        else:
 
379
            self.assertIs(None, result.new_revno)
 
380
 
 
381
        result.report(BytesIO())
 
382
 
 
383
        self.assertEqual(
 
384
            {b'refs/heads/newbranch', b'refs/tags/atag'},
 
385
            set(self.remote_real.get_refs().keys()))
 
386
 
 
387
    def test_push(self):
 
388
        c1 = self.remote_real.do_commit(
 
389
            message=b'message',
 
390
            committer=b'committer <committer@example.com>',
 
391
            author=b'author <author@example.com>')
 
392
 
 
393
        remote = ControlDir.open(self.remote_url)
 
394
        self.make_controldir('local', format=self._from_format)
 
395
        local = remote.sprout('local')
 
396
        self.build_tree(['local/blah'])
 
397
        wt = local.open_workingtree()
 
398
        wt.add(['blah'])
 
399
        revid = wt.commit('blah')
 
400
        wt.branch.tags.set_tag('sometag', revid)
 
401
        wt.branch.get_config_stack().set('branch.fetch_tags', True)
 
402
 
 
403
        if self._from_format == 'git':
 
404
            result = wt.branch.push(remote.create_branch('newbranch'))
 
405
        else:
 
406
            result = wt.branch.push(
 
407
                remote.create_branch('newbranch'), lossy=True)
 
408
 
 
409
        self.assertEqual(0, result.old_revno)
 
410
        self.assertEqual(2, result.new_revno)
 
411
 
 
412
        result.report(BytesIO())
 
413
 
 
414
        self.assertEqual(
 
415
            {b'refs/heads/master': self.remote_real.head(),
 
416
             b'HEAD': self.remote_real.head(),
 
417
             b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
 
418
             b'refs/tags/sometag': self.remote_real.refs[b'refs/heads/newbranch'],
 
419
             },
 
420
            self.remote_real.get_refs())
 
421
 
 
422
    def test_push_diverged(self):
 
423
        c1 = self.remote_real.do_commit(
 
424
            message=b'message',
 
425
            committer=b'committer <committer@example.com>',
 
426
            author=b'author <author@example.com>',
 
427
            ref=b'refs/heads/newbranch')
 
428
 
 
429
        remote = ControlDir.open(self.remote_url)
 
430
        wt = self.make_branch_and_tree('local', format=self._from_format)
 
431
        self.build_tree(['local/blah'])
 
432
        wt.add(['blah'])
 
433
        revid = wt.commit('blah')
 
434
 
 
435
        newbranch = remote.open_branch('newbranch')
 
436
        if self._from_format == 'git':
 
437
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch)
 
438
        else:
 
439
            self.assertRaises(DivergedBranches, wt.branch.push,
 
440
                              newbranch, lossy=True)
 
441
 
 
442
        self.assertEqual(
 
443
            {b'refs/heads/newbranch': c1},
 
444
            self.remote_real.get_refs())
 
445
 
 
446
        if self._from_format == 'git':
 
447
            wt.branch.push(newbranch, overwrite=True)
 
448
        else:
 
449
            wt.branch.push(newbranch, lossy=True, overwrite=True)
 
450
 
 
451
        self.assertNotEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
 
452
 
 
453
 
 
454
class PushToRemoteFromBzrTests(PushToRemoteBase, TestCaseWithTransport):
 
455
 
 
456
    _from_format = '2a'
 
457
 
 
458
 
 
459
class PushToRemoteFromGitTests(PushToRemoteBase, TestCaseWithTransport):
 
460
 
 
461
    _from_format = 'git'
 
462
 
 
463
 
 
464
class RemoteControlDirTests(TestCaseWithTransport):
 
465
 
 
466
    _test_needs_features = [ExecutableFeature('git')]
 
467
 
 
468
    def setUp(self):
 
469
        TestCaseWithTransport.setUp(self)
 
470
        self.remote_real = GitRepo.init('remote', mkdir=True)
 
471
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
 
472
        self.permit_url(self.remote_url)
 
473
 
 
474
    def test_remove_branch(self):
 
475
        c1 = self.remote_real.do_commit(
 
476
            message=b'message',
 
477
            committer=b'committer <committer@example.com>',
 
478
            author=b'author <author@example.com>')
 
479
        c2 = self.remote_real.do_commit(
 
480
            message=b'another commit',
 
481
            committer=b'committer <committer@example.com>',
 
482
            author=b'author <author@example.com>',
 
483
            ref=b'refs/heads/blah')
 
484
 
 
485
        remote = ControlDir.open(self.remote_url)
 
486
        remote.destroy_branch(name='blah')
 
487
        self.assertEqual(
 
488
            self.remote_real.get_refs(),
 
489
            {b'refs/heads/master': self.remote_real.head(),
 
490
             b'HEAD': self.remote_real.head(),
 
491
             })
 
492
 
 
493
    def test_list_branches(self):
 
494
        c1 = self.remote_real.do_commit(
 
495
            message=b'message',
 
496
            committer=b'committer <committer@example.com>',
 
497
            author=b'author <author@example.com>')
 
498
        c2 = self.remote_real.do_commit(
 
499
            message=b'another commit',
 
500
            committer=b'committer <committer@example.com>',
 
501
            author=b'author <author@example.com>',
 
502
            ref=b'refs/heads/blah')
 
503
 
 
504
        remote = ControlDir.open(self.remote_url)
 
505
        self.assertEqual(
 
506
            set(['master', 'blah', 'master']),
 
507
            set([b.name for b in remote.list_branches()]))
 
508
 
 
509
    def test_get_branches(self):
 
510
        c1 = self.remote_real.do_commit(
 
511
            message=b'message',
 
512
            committer=b'committer <committer@example.com>',
 
513
            author=b'author <author@example.com>')
 
514
        c2 = self.remote_real.do_commit(
 
515
            message=b'another commit',
 
516
            committer=b'committer <committer@example.com>',
 
517
            author=b'author <author@example.com>',
 
518
            ref=b'refs/heads/blah')
 
519
 
 
520
        remote = ControlDir.open(self.remote_url)
 
521
        self.assertEqual(
 
522
            {'': 'master', 'blah': 'blah', 'master': 'master'},
 
523
            {n: b.name for (n, b) in remote.get_branches().items()})
 
524
 
 
525
    def test_remove_tag(self):
 
526
        c1 = self.remote_real.do_commit(
 
527
            message=b'message',
 
528
            committer=b'committer <committer@example.com>',
 
529
            author=b'author <author@example.com>')
 
530
        c2 = self.remote_real.do_commit(
 
531
            message=b'another commit',
 
532
            committer=b'committer <committer@example.com>',
 
533
            author=b'author <author@example.com>',
 
534
            ref=b'refs/tags/blah')
 
535
 
 
536
        remote = ControlDir.open(self.remote_url)
 
537
        remote_branch = remote.open_branch()
 
538
        remote_branch.tags.delete_tag('blah')
 
539
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
 
540
        self.assertEqual(
 
541
            self.remote_real.get_refs(),
 
542
            {b'refs/heads/master': self.remote_real.head(),
 
543
             b'HEAD': self.remote_real.head(),
 
544
             })
 
545
 
 
546
    def test_set_tag(self):
 
547
        c1 = self.remote_real.do_commit(
 
548
            message=b'message',
 
549
            committer=b'committer <committer@example.com>',
 
550
            author=b'author <author@example.com>')
 
551
        c2 = self.remote_real.do_commit(
 
552
            message=b'another commit',
 
553
            committer=b'committer <committer@example.com>',
 
554
            author=b'author <author@example.com>')
 
555
 
 
556
        remote = ControlDir.open(self.remote_url)
 
557
        remote.open_branch().tags.set_tag(
 
558
            b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
 
559
        self.assertEqual(
 
560
            self.remote_real.get_refs(),
 
561
            {b'refs/heads/master': self.remote_real.head(),
 
562
             b'refs/tags/blah': c1,
 
563
             b'HEAD': self.remote_real.head(),
 
564
             })
 
565
 
 
566
    def test_annotated_tag(self):
 
567
        c1 = self.remote_real.do_commit(
 
568
            message=b'message',
 
569
            committer=b'committer <committer@example.com>',
 
570
            author=b'author <author@example.com>')
 
571
        c2 = self.remote_real.do_commit(
 
572
            message=b'another commit',
 
573
            committer=b'committer <committer@example.com>',
 
574
            author=b'author <author@example.com>')
 
575
 
 
576
        porcelain.tag_create(
 
577
            self.remote_real,
 
578
            tag=b"blah",
 
579
            author=b'author <author@example.com>',
 
580
            objectish=c2,
 
581
            tag_time=int(time.time()),
 
582
            tag_timezone=0,
 
583
            annotated=True,
 
584
            message=b"Annotated tag")
 
585
 
 
586
        remote = ControlDir.open(self.remote_url)
 
587
        remote_branch = remote.open_branch()
 
588
        self.assertEqual({
 
589
            'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
 
590
            remote_branch.tags.get_tag_dict())
 
591
 
 
592
    def test_get_branch_reference(self):
 
593
        c1 = self.remote_real.do_commit(
 
594
            message=b'message',
 
595
            committer=b'committer <committer@example.com>',
 
596
            author=b'author <author@example.com>')
 
597
        c2 = self.remote_real.do_commit(
 
598
            message=b'another commit',
 
599
            committer=b'committer <committer@example.com>',
 
600
            author=b'author <author@example.com>')
 
601
 
 
602
        remote = ControlDir.open(self.remote_url)
 
603
        self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))
 
604
        self.assertEqual(None, remote.get_branch_reference('master'))
 
605
 
 
606
    def test_get_branch_nick(self):
 
607
        c1 = self.remote_real.do_commit(
 
608
            message=b'message',
 
609
            committer=b'committer <committer@example.com>',
 
610
            author=b'author <author@example.com>')
 
611
        remote = ControlDir.open(self.remote_url)
 
612
        self.assertEqual('master', remote.open_branch().nick)
 
613
 
 
614
 
 
615
class GitUrlAndPathFromTransportTests(TestCase):
 
616
 
 
617
    def test_file(self):
 
618
        split_url = _git_url_and_path_from_transport('file:///home/blah')
 
619
        self.assertEqual(split_url.scheme, 'file')
 
620
        self.assertEqual(split_url.path, '/home/blah')
 
621
 
 
622
    def test_file_segment_params(self):
 
623
        split_url = _git_url_and_path_from_transport('file:///home/blah,branch=master')
 
624
        self.assertEqual(split_url.scheme, 'file')
 
625
        self.assertEqual(split_url.path, '/home/blah')
 
626
 
 
627
    def test_git_smart(self):
 
628
        split_url = _git_url_and_path_from_transport(
 
629
            'git://github.com/dulwich/dulwich,branch=master')
 
630
        self.assertEqual(split_url.scheme, 'git')
 
631
        self.assertEqual(split_url.path, '/dulwich/dulwich')
 
632
 
 
633
    def test_https(self):
 
634
        split_url = _git_url_and_path_from_transport(
 
635
            'https://github.com/dulwich/dulwich')
 
636
        self.assertEqual(split_url.scheme, 'https')
 
637
        self.assertEqual(split_url.path, '/dulwich/dulwich')
 
638
 
 
639
    def test_https_segment_params(self):
 
640
        split_url = _git_url_and_path_from_transport(
 
641
            'https://github.com/dulwich/dulwich,branch=master')
 
642
        self.assertEqual(split_url.scheme, 'https')
 
643
        self.assertEqual(split_url.path, '/dulwich/dulwich')