/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
7104.2.1 by Jelmer Vernooij
Handle another way of formatting Git "repository not found" errors.
91
    def test_notbrancherror_launchpad(self):
92
        e = parse_git_error("url", "Repository 'foo/bar' not found.")
93
        self.assertIsInstance(e, NotBranchError)
94
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
95
    def test_notbrancherror_github(self):
96
        e = parse_git_error("url", "Repository not found.\n")
97
        self.assertIsInstance(e, NotBranchError)
98
7131.7.3 by Jelmer Vernooij
Handle one more error.
99
    def test_notbrancherror_normal(self):
100
        e = parse_git_error("url", "fatal: '/srv/git/lintian-brush' does not appear to be a git repository")
101
        self.assertIsInstance(e, NotBranchError)
102
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
103
    def test_head_update(self):
104
        e = parse_git_error("url", "HEAD failed to update\n")
105
        self.assertIsInstance(e, HeadUpdateFailed)
106
7103.1.2 by Jelmer Vernooij
Handle PermissionDenied.
107
    def test_permission_dnied(self):
108
        e = parse_git_error(
109
            "url",
110
            "access denied or repository not exported: /debian/altermime.git")
111
        self.assertIsInstance(e, PermissionDenied)
112
7131.7.1 by Jelmer Vernooij
Handle permission denied by GitLab.
113
    def test_permission_denied_gitlab(self):
114
        e = parse_git_error(
115
            "url",
116
            'GitLab: You are not allowed to push code to this project.\n')
117
        self.assertIsInstance(e, PermissionDenied)
118
7131.7.2 by Jelmer Vernooij
Handle github PermissionDenied.
119
    def test_permission_denied_github(self):
120
        e = parse_git_error(
121
            "url",
122
            'Permission to porridge/gaduhistory.git denied to jelmer.')
123
        self.assertIsInstance(e, PermissionDenied)
124
        self.assertEqual(e.path, 'porridge/gaduhistory.git')
125
        self.assertEqual(e.extra, ': denied to jelmer')
126
0.295.1 by Jelmer Vernooij
Split up branch formats.
127
128
class TestRemoteGitBranchFormat(TestCase):
129
130
    def setUp(self):
131
        super(TestRemoteGitBranchFormat, self).setUp()
132
        self.format = RemoteGitBranchFormat()
133
134
    def test_get_format_description(self):
6964.2.3 by Jelmer Vernooij
Review comments.
135
        self.assertEqual("Remote Git Branch", self.format.get_format_description())
0.295.1 by Jelmer Vernooij
Split up branch formats.
136
137
    def test_get_network_name(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
138
        self.assertEqual(b"git", self.format.network_name())
0.295.1 by Jelmer Vernooij
Split up branch formats.
139
140
    def test_supports_tags(self):
141
        self.assertTrue(self.format.supports_tags())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
142
143
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
144
class FetchFromRemoteTestBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
145
146
    _test_needs_features = [ExecutableFeature('git')]
147
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
148
    _to_format = None
149
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
150
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
151
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
152
        self.remote_real = GitRepo.init('remote', mkdir=True)
153
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
154
        self.permit_url(self.remote_url)
155
156
    def test_sprout_simple(self):
157
        self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
158
                message=b'message',
159
                committer=b'committer <committer@example.com>',
160
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
161
162
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
163
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
164
        local = remote.sprout('local')
165
        self.assertEqual(
166
                default_mapping.revision_id_foreign_to_bzr(self.remote_real.head()),
167
                local.open_branch().last_revision())
168
169
    def test_sprout_with_tags(self):
170
        c1 = self.remote_real.do_commit(
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
171
                message=b'message',
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
172
                committer=b'committer <committer@example.com>',
173
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
174
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
175
                message=b'another commit',
176
                committer=b'committer <committer@example.com>',
177
                author=b'author <author@example.com>',
178
                ref=b'refs/tags/another')
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
179
        self.remote_real.refs[b'refs/tags/blah'] = self.remote_real.head()
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
180
181
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
182
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
183
        local = remote.sprout('local')
184
        local_branch = local.open_branch()
185
        self.assertEqual(
186
                default_mapping.revision_id_foreign_to_bzr(c1),
187
                local_branch.last_revision())
188
        self.assertEqual(
189
                {'blah': local_branch.last_revision(),
190
                 'another': default_mapping.revision_id_foreign_to_bzr(c2)},
191
                local_branch.tags.get_tag_dict())
192
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
193
    def test_sprout_with_annotated_tag(self):
194
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
195
                message=b'message',
196
                committer=b'committer <committer@example.com>',
197
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
198
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
199
                message=b'another commit',
200
                committer=b'committer <committer@example.com>',
201
                author=b'author <author@example.com>',
202
                ref=b'refs/heads/another')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
203
        porcelain.tag_create(
204
                self.remote_real,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
205
                tag=b"blah",
206
                author=b'author <author@example.com>',
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
207
                objectish=c2,
208
                tag_time=int(time.time()),
209
                tag_timezone=0,
210
                annotated=True,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
211
                message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
212
213
        remote = ControlDir.open(self.remote_url)
214
        self.make_controldir('local', format=self._to_format)
215
        local = remote.sprout('local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
216
        local_branch = local.open_branch()
217
        self.assertEqual(
218
                default_mapping.revision_id_foreign_to_bzr(c1),
219
                local_branch.last_revision())
220
        self.assertEqual(
221
                {'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
222
                local_branch.tags.get_tag_dict())
223
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
224
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
225
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase,TestCaseWithTransport):
226
227
    _to_format = '2a'
228
229
230
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase,TestCaseWithTransport):
231
232
    _to_format = 'git'
233
234
235
class PushToRemoteBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
236
237
    _test_needs_features = [ExecutableFeature('git')]
238
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
239
    _from_format = None
240
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
241
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
242
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
243
        self.remote_real = GitRepo.init('remote', mkdir=True)
244
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
245
        self.permit_url(self.remote_url)
246
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
247
    def test_push_branch_new(self):
248
        remote = ControlDir.open(self.remote_url)
249
        wt = self.make_branch_and_tree('local', format=self._from_format)
250
        self.build_tree(['local/blah'])
251
        wt.add(['blah'])
252
        revid = wt.commit('blah')
253
254
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
255
            result = remote.push_branch(wt.branch, name='newbranch')
256
        else:
257
            result = remote.push_branch(wt.branch, lossy=True, name='newbranch')
258
259
        self.assertEqual(0, result.old_revno)
260
        if self._from_format == 'git':
261
            self.assertEqual(1, result.new_revno)
262
        else:
263
            self.assertIs(None, result.new_revno)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
264
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
265
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
266
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
267
        self.assertEqual(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
268
                {b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
269
                },
270
                self.remote_real.get_refs())
271
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
272
    def test_push(self):
273
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
274
                message=b'message',
275
                committer=b'committer <committer@example.com>',
276
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
277
278
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
279
        self.make_controldir('local', format=self._from_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
280
        local = remote.sprout('local')
281
        self.build_tree(['local/blah'])
282
        wt = local.open_workingtree()
283
        wt.add(['blah'])
284
        revid = wt.commit('blah')
285
        wt.branch.tags.set_tag('sometag', revid)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
286
        wt.branch.get_config_stack().set('branch.fetch_tags', True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
287
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
288
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
289
            result = wt.branch.push(remote.create_branch('newbranch'))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
290
        else:
0.406.2 by Jelmer Vernooij
Add tests.
291
            result = wt.branch.push(remote.create_branch('newbranch'), lossy=True)
292
293
        self.assertEqual(0, result.old_revno)
294
        self.assertEqual(2, result.new_revno)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
295
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
296
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
297
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
298
        self.assertEqual(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
299
                {b'refs/heads/master': self.remote_real.head(),
300
                 b'HEAD': self.remote_real.head(),
301
                 b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
302
                 b'refs/tags/sometag': self.remote_real.refs[b'refs/heads/newbranch'],
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
303
                },
304
                self.remote_real.get_refs())
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
305
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
306
    def test_push_diverged(self):
307
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
308
                message=b'message',
309
                committer=b'committer <committer@example.com>',
310
                author=b'author <author@example.com>',
311
                ref=b'refs/heads/newbranch')
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
312
313
        remote = ControlDir.open(self.remote_url)
314
        wt = self.make_branch_and_tree('local', format=self._from_format)
315
        self.build_tree(['local/blah'])
316
        wt.add(['blah'])
317
        revid = wt.commit('blah')
318
319
        newbranch = remote.open_branch('newbranch')
320
        if self._from_format == 'git':
321
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch)
322
        else:
323
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch, lossy=True)
324
325
        self.assertEqual(
7018.3.2 by Jelmer Vernooij
Fix some git tests.
326
                {b'refs/heads/newbranch': c1 },
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
327
                self.remote_real.get_refs())
328
329
        if self._from_format == 'git':
330
            wt.branch.push(newbranch, overwrite=True)
331
        else:
332
            wt.branch.push(newbranch, lossy=True, overwrite=True)
333
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
334
        self.assertNotEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
335
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
336
337
class PushToRemoteFromBzrTests(PushToRemoteBase,TestCaseWithTransport):
338
339
    _from_format = '2a'
340
341
342
class PushToRemoteFromGitTests(PushToRemoteBase,TestCaseWithTransport):
343
344
    _from_format = 'git'
345
346
347
class RemoteControlDirTests(TestCaseWithTransport):
348
349
    _test_needs_features = [ExecutableFeature('git')]
350
351
    def setUp(self):
352
        TestCaseWithTransport.setUp(self)
353
        self.remote_real = GitRepo.init('remote', mkdir=True)
354
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
355
        self.permit_url(self.remote_url)
356
357
    def test_remove_branch(self):
358
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
359
                message=b'message',
360
                committer=b'committer <committer@example.com>',
361
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
362
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
363
                message=b'another commit',
364
                committer=b'committer <committer@example.com>',
365
                author=b'author <author@example.com>',
366
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
367
368
        remote = ControlDir.open(self.remote_url)
369
        remote.destroy_branch(name='blah')
370
        self.assertEqual(
371
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
372
                {b'refs/heads/master': self.remote_real.head(),
373
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
374
                })
375
376
    def test_list_branches(self):
377
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
378
                message=b'message',
379
                committer=b'committer <committer@example.com>',
380
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
381
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
382
                message=b'another commit',
383
                committer=b'committer <committer@example.com>',
384
                author=b'author <author@example.com>',
385
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
386
387
        remote = ControlDir.open(self.remote_url)
388
        self.assertEqual(
6997.1.1 by Jelmer Vernooij
Fix tests on Python3.5.
389
                set(['master', 'blah', 'master']),
390
                set([b.name for b in remote.list_branches()]))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
391
392
    def test_get_branches(self):
393
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
394
                message=b'message',
395
                committer=b'committer <committer@example.com>',
396
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
397
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
398
                message=b'another commit',
399
                committer=b'committer <committer@example.com>',
400
                author=b'author <author@example.com>',
401
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
402
403
        remote = ControlDir.open(self.remote_url)
404
        self.assertEqual(
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
405
                {'': 'master', 'blah': 'blah', 'master': 'master'},
406
                {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.
407
408
    def test_remove_tag(self):
409
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
410
                message=b'message',
411
                committer=b'committer <committer@example.com>',
412
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
413
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
414
                message=b'another commit',
415
                committer=b'committer <committer@example.com>',
416
                author=b'author <author@example.com>',
417
                ref=b'refs/tags/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
418
419
        remote = ControlDir.open(self.remote_url)
420
        remote_branch = remote.open_branch()
421
        remote_branch.tags.delete_tag('blah')
422
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
423
        self.assertEqual(
424
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
425
                {b'refs/heads/master': self.remote_real.head(),
426
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
427
                })
428
429
    def test_set_tag(self):
430
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
431
                message=b'message',
432
                committer=b'committer <committer@example.com>',
433
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
434
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
435
                message=b'another commit',
436
                committer=b'committer <committer@example.com>',
437
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
438
439
        remote = ControlDir.open(self.remote_url)
440
        remote.open_branch().tags.set_tag(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
441
            b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
442
        self.assertEqual(
443
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
444
                {b'refs/heads/master': self.remote_real.head(),
445
                 b'refs/tags/blah': c1,
446
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
447
                })
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
448
449
    def test_annotated_tag(self):
450
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
451
                message=b'message',
452
                committer=b'committer <committer@example.com>',
453
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
454
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
455
                message=b'another commit',
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
459
        porcelain.tag_create(
460
                self.remote_real,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
461
                tag=b"blah",
462
                author=b'author <author@example.com>',
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
463
                objectish=c2,
464
                tag_time=int(time.time()),
465
                tag_timezone=0,
466
                annotated=True,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
467
                message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
468
469
        remote = ControlDir.open(self.remote_url)
470
        remote_branch = remote.open_branch()
471
        self.assertEqual({
6973.13.2 by Jelmer Vernooij
Fix some more tests.
472
            'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
473
            remote_branch.tags.get_tag_dict())
474
475
    def tetst_get_branch_reference(self):
476
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
477
                message=b'message',
478
                committer=b'committer <committer@example.com>',
479
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
480
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
481
                message=b'another commit',
482
                committer=b'committer <committer@example.com>',
483
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
484
485
        remote = ControlDir.open(self.remote_url)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
486
        self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
487
        self.assertEqual(None, remote.get_branch_reference('master'))