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