/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
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
21
from io import BytesIO
0.406.3 by Jelmer Vernooij
Add extra tests.
22
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
23
import os
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
24
import time
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
25
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
26
from ...controldir import ControlDir
27
from ...errors import (
0.200.1275 by Jelmer Vernooij
recognize missing repositories
28
    BzrError,
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
29
    DivergedBranches,
0.200.1275 by Jelmer Vernooij
recognize missing repositories
30
    NotBranchError,
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
31
    NoSuchTag,
7103.1.2 by Jelmer Vernooij
Handle PermissionDenied.
32
    PermissionDenied,
0.200.1275 by Jelmer Vernooij
recognize missing repositories
33
    )
34
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
35
from ...tests import (
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
36
    TestCase,
37
    TestCaseWithTransport,
38
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
39
from ...tests.features import ExecutableFeature
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
40
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
41
from ..mapping import default_mapping
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
42
from ..remote import (
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
43
    split_git_url,
0.200.1275 by Jelmer Vernooij
recognize missing repositories
44
    parse_git_error,
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
45
    HeadUpdateFailed,
46
    RemoteGitError,
0.295.1 by Jelmer Vernooij
Split up branch formats.
47
    RemoteGitBranchFormat,
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
48
    )
49
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
50
from dulwich import porcelain
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
51
from dulwich.repo import Repo as GitRepo
52
53
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
54
class SplitUrlTests(TestCase):
55
56
    def test_simple(self):
6964.2.3 by Jelmer Vernooij
Review comments.
57
        self.assertEqual(("foo", None, None, "/bar"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
58
            split_git_url("git://foo/bar"))
59
60
    def test_port(self):
6964.2.3 by Jelmer Vernooij
Review comments.
61
        self.assertEqual(("foo", 343, None, "/bar"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
62
            split_git_url("git://foo:343/bar"))
63
64
    def test_username(self):
6964.2.3 by Jelmer Vernooij
Review comments.
65
        self.assertEqual(("foo", None, "la", "/bar"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
66
            split_git_url("git://la@foo/bar"))
67
68
    def test_nopath(self):
6964.2.3 by Jelmer Vernooij
Review comments.
69
        self.assertEqual(("foo", None, None, "/"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
70
            split_git_url("git://foo/"))
71
72
    def test_slashpath(self):
6964.2.3 by Jelmer Vernooij
Review comments.
73
        self.assertEqual(("foo", None, None, "//bar"),
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
74
            split_git_url("git://foo//bar"))
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
75
76
    def test_homedir(self):
6964.2.3 by Jelmer Vernooij
Review comments.
77
        self.assertEqual(("foo", None, None, "~bar"),
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
78
            split_git_url("git://foo/~bar"))
0.200.1275 by Jelmer Vernooij
recognize missing repositories
79
80
81
class ParseGitErrorTests(TestCase):
82
83
    def test_unknown(self):
84
        e = parse_git_error("url", "foo")
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
85
        self.assertIsInstance(e, RemoteGitError)
0.200.1275 by Jelmer Vernooij
recognize missing repositories
86
87
    def test_notbrancherror(self):
88
        e = parse_git_error("url", "\n Could not find Repository foo/bar")
89
        self.assertIsInstance(e, NotBranchError)
0.295.1 by Jelmer Vernooij
Split up branch formats.
90
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
91
    def test_notbrancherror_github(self):
92
        e = parse_git_error("url", "Repository not found.\n")
93
        self.assertIsInstance(e, NotBranchError)
94
95
    def test_head_update(self):
96
        e = parse_git_error("url", "HEAD failed to update\n")
97
        self.assertIsInstance(e, HeadUpdateFailed)
98
7103.1.2 by Jelmer Vernooij
Handle PermissionDenied.
99
    def test_permission_dnied(self):
100
        e = parse_git_error(
101
            "url",
102
            "access denied or repository not exported: /debian/altermime.git")
103
        self.assertIsInstance(e, PermissionDenied)
104
0.295.1 by Jelmer Vernooij
Split up branch formats.
105
106
class TestRemoteGitBranchFormat(TestCase):
107
108
    def setUp(self):
109
        super(TestRemoteGitBranchFormat, self).setUp()
110
        self.format = RemoteGitBranchFormat()
111
112
    def test_get_format_description(self):
6964.2.3 by Jelmer Vernooij
Review comments.
113
        self.assertEqual("Remote Git Branch", self.format.get_format_description())
0.295.1 by Jelmer Vernooij
Split up branch formats.
114
115
    def test_get_network_name(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
116
        self.assertEqual(b"git", self.format.network_name())
0.295.1 by Jelmer Vernooij
Split up branch formats.
117
118
    def test_supports_tags(self):
119
        self.assertTrue(self.format.supports_tags())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
120
121
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
122
class FetchFromRemoteTestBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
123
124
    _test_needs_features = [ExecutableFeature('git')]
125
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
126
    _to_format = None
127
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
128
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
129
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
130
        self.remote_real = GitRepo.init('remote', mkdir=True)
131
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
132
        self.permit_url(self.remote_url)
133
134
    def test_sprout_simple(self):
135
        self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
136
                message=b'message',
137
                committer=b'committer <committer@example.com>',
138
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
139
140
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
141
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
142
        local = remote.sprout('local')
143
        self.assertEqual(
144
                default_mapping.revision_id_foreign_to_bzr(self.remote_real.head()),
145
                local.open_branch().last_revision())
146
147
    def test_sprout_with_tags(self):
148
        c1 = self.remote_real.do_commit(
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
149
                message=b'message',
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
150
                committer=b'committer <committer@example.com>',
151
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
152
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
153
                message=b'another commit',
154
                committer=b'committer <committer@example.com>',
155
                author=b'author <author@example.com>',
156
                ref=b'refs/tags/another')
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
157
        self.remote_real.refs[b'refs/tags/blah'] = self.remote_real.head()
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
158
159
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
160
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
161
        local = remote.sprout('local')
162
        local_branch = local.open_branch()
163
        self.assertEqual(
164
                default_mapping.revision_id_foreign_to_bzr(c1),
165
                local_branch.last_revision())
166
        self.assertEqual(
167
                {'blah': local_branch.last_revision(),
168
                 'another': default_mapping.revision_id_foreign_to_bzr(c2)},
169
                local_branch.tags.get_tag_dict())
170
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
171
    def test_sprout_with_annotated_tag(self):
172
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
173
                message=b'message',
174
                committer=b'committer <committer@example.com>',
175
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
176
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
177
                message=b'another commit',
178
                committer=b'committer <committer@example.com>',
179
                author=b'author <author@example.com>',
180
                ref=b'refs/heads/another')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
181
        porcelain.tag_create(
182
                self.remote_real,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
183
                tag=b"blah",
184
                author=b'author <author@example.com>',
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
185
                objectish=c2,
186
                tag_time=int(time.time()),
187
                tag_timezone=0,
188
                annotated=True,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
189
                message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
190
191
        remote = ControlDir.open(self.remote_url)
192
        self.make_controldir('local', format=self._to_format)
193
        local = remote.sprout('local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
194
        local_branch = local.open_branch()
195
        self.assertEqual(
196
                default_mapping.revision_id_foreign_to_bzr(c1),
197
                local_branch.last_revision())
198
        self.assertEqual(
199
                {'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
200
                local_branch.tags.get_tag_dict())
201
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
202
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
203
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase,TestCaseWithTransport):
204
205
    _to_format = '2a'
206
207
208
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase,TestCaseWithTransport):
209
210
    _to_format = 'git'
211
212
213
class PushToRemoteBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
214
215
    _test_needs_features = [ExecutableFeature('git')]
216
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
217
    _from_format = None
218
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
219
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
220
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
221
        self.remote_real = GitRepo.init('remote', mkdir=True)
222
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
223
        self.permit_url(self.remote_url)
224
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
225
    def test_push_branch_new(self):
226
        remote = ControlDir.open(self.remote_url)
227
        wt = self.make_branch_and_tree('local', format=self._from_format)
228
        self.build_tree(['local/blah'])
229
        wt.add(['blah'])
230
        revid = wt.commit('blah')
231
232
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
233
            result = remote.push_branch(wt.branch, name='newbranch')
234
        else:
235
            result = remote.push_branch(wt.branch, lossy=True, name='newbranch')
236
237
        self.assertEqual(0, result.old_revno)
238
        if self._from_format == 'git':
239
            self.assertEqual(1, result.new_revno)
240
        else:
241
            self.assertIs(None, result.new_revno)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
242
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
243
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
244
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
245
        self.assertEqual(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
246
                {b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
247
                },
248
                self.remote_real.get_refs())
249
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
250
    def test_push(self):
251
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
252
                message=b'message',
253
                committer=b'committer <committer@example.com>',
254
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
255
256
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
257
        self.make_controldir('local', format=self._from_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
258
        local = remote.sprout('local')
259
        self.build_tree(['local/blah'])
260
        wt = local.open_workingtree()
261
        wt.add(['blah'])
262
        revid = wt.commit('blah')
263
        wt.branch.tags.set_tag('sometag', revid)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
264
        wt.branch.get_config_stack().set('branch.fetch_tags', True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
265
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
266
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
267
            result = wt.branch.push(remote.create_branch('newbranch'))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
268
        else:
0.406.2 by Jelmer Vernooij
Add tests.
269
            result = wt.branch.push(remote.create_branch('newbranch'), lossy=True)
270
271
        self.assertEqual(0, result.old_revno)
272
        self.assertEqual(2, result.new_revno)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
273
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
274
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
275
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
276
        self.assertEqual(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
277
                {b'refs/heads/master': self.remote_real.head(),
278
                 b'HEAD': self.remote_real.head(),
279
                 b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
280
                 b'refs/tags/sometag': self.remote_real.refs[b'refs/heads/newbranch'],
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
281
                },
282
                self.remote_real.get_refs())
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
283
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
284
    def test_push_diverged(self):
285
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
286
                message=b'message',
287
                committer=b'committer <committer@example.com>',
288
                author=b'author <author@example.com>',
289
                ref=b'refs/heads/newbranch')
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
290
291
        remote = ControlDir.open(self.remote_url)
292
        wt = self.make_branch_and_tree('local', format=self._from_format)
293
        self.build_tree(['local/blah'])
294
        wt.add(['blah'])
295
        revid = wt.commit('blah')
296
297
        newbranch = remote.open_branch('newbranch')
298
        if self._from_format == 'git':
299
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch)
300
        else:
301
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch, lossy=True)
302
303
        self.assertEqual(
7018.3.2 by Jelmer Vernooij
Fix some git tests.
304
                {b'refs/heads/newbranch': c1 },
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
305
                self.remote_real.get_refs())
306
307
        if self._from_format == 'git':
308
            wt.branch.push(newbranch, overwrite=True)
309
        else:
310
            wt.branch.push(newbranch, lossy=True, overwrite=True)
311
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
312
        self.assertNotEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
313
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
314
315
class PushToRemoteFromBzrTests(PushToRemoteBase,TestCaseWithTransport):
316
317
    _from_format = '2a'
318
319
320
class PushToRemoteFromGitTests(PushToRemoteBase,TestCaseWithTransport):
321
322
    _from_format = 'git'
323
324
325
class RemoteControlDirTests(TestCaseWithTransport):
326
327
    _test_needs_features = [ExecutableFeature('git')]
328
329
    def setUp(self):
330
        TestCaseWithTransport.setUp(self)
331
        self.remote_real = GitRepo.init('remote', mkdir=True)
332
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
333
        self.permit_url(self.remote_url)
334
335
    def test_remove_branch(self):
336
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
337
                message=b'message',
338
                committer=b'committer <committer@example.com>',
339
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
340
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
341
                message=b'another commit',
342
                committer=b'committer <committer@example.com>',
343
                author=b'author <author@example.com>',
344
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
345
346
        remote = ControlDir.open(self.remote_url)
347
        remote.destroy_branch(name='blah')
348
        self.assertEqual(
349
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
350
                {b'refs/heads/master': self.remote_real.head(),
351
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
352
                })
353
354
    def test_list_branches(self):
355
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
356
                message=b'message',
357
                committer=b'committer <committer@example.com>',
358
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
359
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
360
                message=b'another commit',
361
                committer=b'committer <committer@example.com>',
362
                author=b'author <author@example.com>',
363
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
364
365
        remote = ControlDir.open(self.remote_url)
366
        self.assertEqual(
6997.1.1 by Jelmer Vernooij
Fix tests on Python3.5.
367
                set(['master', 'blah', 'master']),
368
                set([b.name for b in remote.list_branches()]))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
369
370
    def test_get_branches(self):
371
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
372
                message=b'message',
373
                committer=b'committer <committer@example.com>',
374
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
375
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
376
                message=b'another commit',
377
                committer=b'committer <committer@example.com>',
378
                author=b'author <author@example.com>',
379
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
380
381
        remote = ControlDir.open(self.remote_url)
382
        self.assertEqual(
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
383
                {'': 'master', 'blah': 'blah', 'master': 'master'},
384
                {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.
385
386
    def test_remove_tag(self):
387
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
388
                message=b'message',
389
                committer=b'committer <committer@example.com>',
390
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
391
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
392
                message=b'another commit',
393
                committer=b'committer <committer@example.com>',
394
                author=b'author <author@example.com>',
395
                ref=b'refs/tags/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
396
397
        remote = ControlDir.open(self.remote_url)
398
        remote_branch = remote.open_branch()
399
        remote_branch.tags.delete_tag('blah')
400
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
401
        self.assertEqual(
402
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
403
                {b'refs/heads/master': self.remote_real.head(),
404
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
405
                })
406
407
    def test_set_tag(self):
408
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
409
                message=b'message',
410
                committer=b'committer <committer@example.com>',
411
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
412
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
413
                message=b'another commit',
414
                committer=b'committer <committer@example.com>',
415
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
416
417
        remote = ControlDir.open(self.remote_url)
418
        remote.open_branch().tags.set_tag(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
419
            b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
420
        self.assertEqual(
421
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
422
                {b'refs/heads/master': self.remote_real.head(),
423
                 b'refs/tags/blah': c1,
424
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
425
                })
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
426
427
    def test_annotated_tag(self):
428
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
429
                message=b'message',
430
                committer=b'committer <committer@example.com>',
431
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
432
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
433
                message=b'another commit',
434
                committer=b'committer <committer@example.com>',
435
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
436
437
        porcelain.tag_create(
438
                self.remote_real,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
439
                tag=b"blah",
440
                author=b'author <author@example.com>',
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
441
                objectish=c2,
442
                tag_time=int(time.time()),
443
                tag_timezone=0,
444
                annotated=True,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
445
                message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
446
447
        remote = ControlDir.open(self.remote_url)
448
        remote_branch = remote.open_branch()
449
        self.assertEqual({
6973.13.2 by Jelmer Vernooij
Fix some more tests.
450
            'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
451
            remote_branch.tags.get_tag_dict())
452
453
    def tetst_get_branch_reference(self):
454
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
455
                message=b'message',
456
                committer=b'committer <committer@example.com>',
457
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
458
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
459
                message=b'another commit',
460
                committer=b'committer <committer@example.com>',
461
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
462
463
        remote = ControlDir.open(self.remote_url)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
464
        self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
465
        self.assertEqual(None, remote.get_branch_reference('master'))