/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
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
144
class TestRemoteGitBranch(TestCaseWithTransport):
145
146
    def setUp(self):
147
        TestCaseWithTransport.setUp(self)
148
        self.remote_real = GitRepo.init('remote', mkdir=True)
149
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
150
        self.permit_url(self.remote_url)
151
152
    def test_set_last_revision_info(self):
153
        c1 = self.remote_real.do_commit(
154
                message=b'message 1',
155
                committer=b'committer <committer@example.com>',
156
                author=b'author <author@example.com>',
157
                ref=b'refs/heads/newbranch')
158
        c2 = self.remote_real.do_commit(
159
                message=b'message 2',
160
                committer=b'committer <committer@example.com>',
161
                author=b'author <author@example.com>',
162
                ref=b'refs/heads/newbranch')
163
164
        remote = ControlDir.open(self.remote_url)
165
        newbranch = remote.open_branch('newbranch')
166
        self.assertEqual(newbranch.lookup_foreign_revision_id(c2),
167
                         newbranch.last_revision())
168
        newbranch.set_last_revision_info(
169
            1, newbranch.lookup_foreign_revision_id(c1))
7131.12.2 by Jelmer Vernooij
Fix tests on python 3.
170
        self.assertEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
171
        self.assertEqual(newbranch.last_revision(),
172
                         newbranch.lookup_foreign_revision_id(c1))
173
174
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
175
class FetchFromRemoteTestBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
176
177
    _test_needs_features = [ExecutableFeature('git')]
178
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
179
    _to_format = None
180
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
181
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
182
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
183
        self.remote_real = GitRepo.init('remote', mkdir=True)
184
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
185
        self.permit_url(self.remote_url)
186
187
    def test_sprout_simple(self):
188
        self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
189
                message=b'message',
190
                committer=b'committer <committer@example.com>',
191
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
192
193
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
194
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
195
        local = remote.sprout('local')
196
        self.assertEqual(
197
                default_mapping.revision_id_foreign_to_bzr(self.remote_real.head()),
198
                local.open_branch().last_revision())
199
200
    def test_sprout_with_tags(self):
201
        c1 = self.remote_real.do_commit(
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
202
                message=b'message',
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
203
                committer=b'committer <committer@example.com>',
204
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
205
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
206
                message=b'another commit',
207
                committer=b'committer <committer@example.com>',
208
                author=b'author <author@example.com>',
209
                ref=b'refs/tags/another')
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
210
        self.remote_real.refs[b'refs/tags/blah'] = self.remote_real.head()
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
211
212
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
213
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
214
        local = remote.sprout('local')
215
        local_branch = local.open_branch()
216
        self.assertEqual(
217
                default_mapping.revision_id_foreign_to_bzr(c1),
218
                local_branch.last_revision())
219
        self.assertEqual(
220
                {'blah': local_branch.last_revision(),
221
                 'another': default_mapping.revision_id_foreign_to_bzr(c2)},
222
                local_branch.tags.get_tag_dict())
223
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
224
    def test_sprout_with_annotated_tag(self):
225
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
226
                message=b'message',
227
                committer=b'committer <committer@example.com>',
228
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
229
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
230
                message=b'another commit',
231
                committer=b'committer <committer@example.com>',
232
                author=b'author <author@example.com>',
233
                ref=b'refs/heads/another')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
234
        porcelain.tag_create(
235
                self.remote_real,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
236
                tag=b"blah",
237
                author=b'author <author@example.com>',
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
238
                objectish=c2,
239
                tag_time=int(time.time()),
240
                tag_timezone=0,
241
                annotated=True,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
242
                message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
243
244
        remote = ControlDir.open(self.remote_url)
245
        self.make_controldir('local', format=self._to_format)
246
        local = remote.sprout('local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
247
        local_branch = local.open_branch()
248
        self.assertEqual(
249
                default_mapping.revision_id_foreign_to_bzr(c1),
250
                local_branch.last_revision())
251
        self.assertEqual(
252
                {'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
253
                local_branch.tags.get_tag_dict())
254
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
255
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
256
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase,TestCaseWithTransport):
257
258
    _to_format = '2a'
259
260
261
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase,TestCaseWithTransport):
262
263
    _to_format = 'git'
264
265
266
class PushToRemoteBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
267
268
    _test_needs_features = [ExecutableFeature('git')]
269
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
270
    _from_format = None
271
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
272
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
273
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
274
        self.remote_real = GitRepo.init('remote', mkdir=True)
275
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
276
        self.permit_url(self.remote_url)
277
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
278
    def test_push_branch_new(self):
279
        remote = ControlDir.open(self.remote_url)
280
        wt = self.make_branch_and_tree('local', format=self._from_format)
281
        self.build_tree(['local/blah'])
282
        wt.add(['blah'])
283
        revid = wt.commit('blah')
284
285
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
286
            result = remote.push_branch(wt.branch, name='newbranch')
287
        else:
288
            result = remote.push_branch(wt.branch, lossy=True, name='newbranch')
289
290
        self.assertEqual(0, result.old_revno)
291
        if self._from_format == 'git':
292
            self.assertEqual(1, result.new_revno)
293
        else:
294
            self.assertIs(None, result.new_revno)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
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.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
298
        self.assertEqual(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
299
                {b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
300
                },
301
                self.remote_real.get_refs())
302
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
303
    def test_push(self):
304
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
305
                message=b'message',
306
                committer=b'committer <committer@example.com>',
307
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
308
309
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
310
        self.make_controldir('local', format=self._from_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
311
        local = remote.sprout('local')
312
        self.build_tree(['local/blah'])
313
        wt = local.open_workingtree()
314
        wt.add(['blah'])
315
        revid = wt.commit('blah')
316
        wt.branch.tags.set_tag('sometag', revid)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
317
        wt.branch.get_config_stack().set('branch.fetch_tags', True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
318
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
319
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
320
            result = wt.branch.push(remote.create_branch('newbranch'))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
321
        else:
0.406.2 by Jelmer Vernooij
Add tests.
322
            result = wt.branch.push(remote.create_branch('newbranch'), lossy=True)
323
324
        self.assertEqual(0, result.old_revno)
325
        self.assertEqual(2, result.new_revno)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
326
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
327
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
328
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
329
        self.assertEqual(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
330
                {b'refs/heads/master': self.remote_real.head(),
331
                 b'HEAD': self.remote_real.head(),
332
                 b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
333
                 b'refs/tags/sometag': self.remote_real.refs[b'refs/heads/newbranch'],
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
334
                },
335
                self.remote_real.get_refs())
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
336
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
337
    def test_push_diverged(self):
338
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
339
                message=b'message',
340
                committer=b'committer <committer@example.com>',
341
                author=b'author <author@example.com>',
342
                ref=b'refs/heads/newbranch')
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
343
344
        remote = ControlDir.open(self.remote_url)
345
        wt = self.make_branch_and_tree('local', format=self._from_format)
346
        self.build_tree(['local/blah'])
347
        wt.add(['blah'])
348
        revid = wt.commit('blah')
349
350
        newbranch = remote.open_branch('newbranch')
351
        if self._from_format == 'git':
352
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch)
353
        else:
354
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch, lossy=True)
355
356
        self.assertEqual(
7018.3.2 by Jelmer Vernooij
Fix some git tests.
357
                {b'refs/heads/newbranch': c1 },
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
358
                self.remote_real.get_refs())
359
360
        if self._from_format == 'git':
361
            wt.branch.push(newbranch, overwrite=True)
362
        else:
363
            wt.branch.push(newbranch, lossy=True, overwrite=True)
364
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
365
        self.assertNotEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
366
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
367
368
class PushToRemoteFromBzrTests(PushToRemoteBase,TestCaseWithTransport):
369
370
    _from_format = '2a'
371
372
373
class PushToRemoteFromGitTests(PushToRemoteBase,TestCaseWithTransport):
374
375
    _from_format = 'git'
376
377
378
class RemoteControlDirTests(TestCaseWithTransport):
379
380
    _test_needs_features = [ExecutableFeature('git')]
381
382
    def setUp(self):
383
        TestCaseWithTransport.setUp(self)
384
        self.remote_real = GitRepo.init('remote', mkdir=True)
385
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
386
        self.permit_url(self.remote_url)
387
388
    def test_remove_branch(self):
389
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
390
                message=b'message',
391
                committer=b'committer <committer@example.com>',
392
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
393
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
394
                message=b'another commit',
395
                committer=b'committer <committer@example.com>',
396
                author=b'author <author@example.com>',
397
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
398
399
        remote = ControlDir.open(self.remote_url)
400
        remote.destroy_branch(name='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_list_branches(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>',
416
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
417
418
        remote = ControlDir.open(self.remote_url)
419
        self.assertEqual(
6997.1.1 by Jelmer Vernooij
Fix tests on Python3.5.
420
                set(['master', 'blah', 'master']),
421
                set([b.name for b in remote.list_branches()]))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
422
423
    def test_get_branches(self):
424
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
425
                message=b'message',
426
                committer=b'committer <committer@example.com>',
427
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
428
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
429
                message=b'another commit',
430
                committer=b'committer <committer@example.com>',
431
                author=b'author <author@example.com>',
432
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
433
434
        remote = ControlDir.open(self.remote_url)
435
        self.assertEqual(
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
436
                {'': 'master', 'blah': 'blah', 'master': 'master'},
437
                {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.
438
439
    def test_remove_tag(self):
440
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
441
                message=b'message',
442
                committer=b'committer <committer@example.com>',
443
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
444
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
445
                message=b'another commit',
446
                committer=b'committer <committer@example.com>',
447
                author=b'author <author@example.com>',
448
                ref=b'refs/tags/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
449
450
        remote = ControlDir.open(self.remote_url)
451
        remote_branch = remote.open_branch()
452
        remote_branch.tags.delete_tag('blah')
453
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
454
        self.assertEqual(
455
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
456
                {b'refs/heads/master': self.remote_real.head(),
457
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
458
                })
459
460
    def test_set_tag(self):
461
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
462
                message=b'message',
463
                committer=b'committer <committer@example.com>',
464
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
465
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
466
                message=b'another commit',
467
                committer=b'committer <committer@example.com>',
468
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
469
470
        remote = ControlDir.open(self.remote_url)
471
        remote.open_branch().tags.set_tag(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
472
            b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
473
        self.assertEqual(
474
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
475
                {b'refs/heads/master': self.remote_real.head(),
476
                 b'refs/tags/blah': c1,
477
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
478
                })
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
479
480
    def test_annotated_tag(self):
481
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
482
                message=b'message',
483
                committer=b'committer <committer@example.com>',
484
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
485
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
486
                message=b'another commit',
487
                committer=b'committer <committer@example.com>',
488
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
489
490
        porcelain.tag_create(
491
                self.remote_real,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
492
                tag=b"blah",
493
                author=b'author <author@example.com>',
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
494
                objectish=c2,
495
                tag_time=int(time.time()),
496
                tag_timezone=0,
497
                annotated=True,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
498
                message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
499
500
        remote = ControlDir.open(self.remote_url)
501
        remote_branch = remote.open_branch()
502
        self.assertEqual({
6973.13.2 by Jelmer Vernooij
Fix some more tests.
503
            'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
504
            remote_branch.tags.get_tag_dict())
505
506
    def tetst_get_branch_reference(self):
507
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
508
                message=b'message',
509
                committer=b'committer <committer@example.com>',
510
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
511
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
512
                message=b'another commit',
513
                committer=b'committer <committer@example.com>',
514
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
515
516
        remote = ControlDir.open(self.remote_url)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
517
        self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
518
        self.assertEqual(None, remote.get_branch_reference('master'))