/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: 2020-01-19 15:14:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7455.
  • Revision ID: jelmer@jelmer.uk-20200119151416-f2x9y9rtvwxndr2l
Don't show submodules that are not checked out as deltas.

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