/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
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
254
    def test_sprout_with_annotated_tag_unreferenced(self):
255
        c1 = self.remote_real.do_commit(
256
                message=b'message',
257
                committer=b'committer <committer@example.com>',
258
                author=b'author <author@example.com>')
259
        c2 = self.remote_real.do_commit(
260
                message=b'another commit',
261
                committer=b'committer <committer@example.com>',
262
                author=b'author <author@example.com>')
263
        porcelain.tag_create(
264
                self.remote_real,
265
                tag=b"blah",
266
                author=b'author <author@example.com>',
267
                objectish=c1,
268
                tag_time=int(time.time()),
269
                tag_timezone=0,
270
                annotated=True,
271
                message=b"Annotated tag")
272
273
        remote = ControlDir.open(self.remote_url)
274
        self.make_controldir('local', format=self._to_format)
275
        local = remote.sprout(
276
                'local',
277
                revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
278
        local_branch = local.open_branch()
279
        self.assertEqual(
280
                default_mapping.revision_id_foreign_to_bzr(c1),
281
                local_branch.last_revision())
282
        self.assertEqual(
283
                {'blah': default_mapping.revision_id_foreign_to_bzr(c1)},
284
                local_branch.tags.get_tag_dict())
285
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
286
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
287
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase,TestCaseWithTransport):
288
289
    _to_format = '2a'
290
291
292
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase,TestCaseWithTransport):
293
294
    _to_format = 'git'
295
296
297
class PushToRemoteBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
298
299
    _test_needs_features = [ExecutableFeature('git')]
300
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
301
    _from_format = None
302
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
303
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
304
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
305
        self.remote_real = GitRepo.init('remote', mkdir=True)
306
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
307
        self.permit_url(self.remote_url)
308
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
309
    def test_push_branch_new(self):
310
        remote = ControlDir.open(self.remote_url)
311
        wt = self.make_branch_and_tree('local', format=self._from_format)
312
        self.build_tree(['local/blah'])
313
        wt.add(['blah'])
314
        revid = wt.commit('blah')
315
316
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
317
            result = remote.push_branch(wt.branch, name='newbranch')
318
        else:
319
            result = remote.push_branch(wt.branch, lossy=True, name='newbranch')
320
321
        self.assertEqual(0, result.old_revno)
322
        if self._from_format == 'git':
323
            self.assertEqual(1, result.new_revno)
324
        else:
325
            self.assertIs(None, result.new_revno)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
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.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
329
        self.assertEqual(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
330
                {b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
331
                },
332
                self.remote_real.get_refs())
333
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
334
    def test_push(self):
335
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
336
                message=b'message',
337
                committer=b'committer <committer@example.com>',
338
                author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
339
340
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
341
        self.make_controldir('local', format=self._from_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
342
        local = remote.sprout('local')
343
        self.build_tree(['local/blah'])
344
        wt = local.open_workingtree()
345
        wt.add(['blah'])
346
        revid = wt.commit('blah')
347
        wt.branch.tags.set_tag('sometag', revid)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
348
        wt.branch.get_config_stack().set('branch.fetch_tags', True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
349
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
350
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
351
            result = wt.branch.push(remote.create_branch('newbranch'))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
352
        else:
0.406.2 by Jelmer Vernooij
Add tests.
353
            result = wt.branch.push(remote.create_branch('newbranch'), lossy=True)
354
355
        self.assertEqual(0, result.old_revno)
356
        self.assertEqual(2, result.new_revno)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
357
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
358
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
359
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
360
        self.assertEqual(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
361
                {b'refs/heads/master': self.remote_real.head(),
362
                 b'HEAD': self.remote_real.head(),
363
                 b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
364
                 b'refs/tags/sometag': self.remote_real.refs[b'refs/heads/newbranch'],
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
365
                },
366
                self.remote_real.get_refs())
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
367
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
368
    def test_push_diverged(self):
369
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
370
                message=b'message',
371
                committer=b'committer <committer@example.com>',
372
                author=b'author <author@example.com>',
373
                ref=b'refs/heads/newbranch')
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
374
375
        remote = ControlDir.open(self.remote_url)
376
        wt = self.make_branch_and_tree('local', format=self._from_format)
377
        self.build_tree(['local/blah'])
378
        wt.add(['blah'])
379
        revid = wt.commit('blah')
380
381
        newbranch = remote.open_branch('newbranch')
382
        if self._from_format == 'git':
383
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch)
384
        else:
385
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch, lossy=True)
386
387
        self.assertEqual(
7018.3.2 by Jelmer Vernooij
Fix some git tests.
388
                {b'refs/heads/newbranch': c1 },
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
389
                self.remote_real.get_refs())
390
391
        if self._from_format == 'git':
392
            wt.branch.push(newbranch, overwrite=True)
393
        else:
394
            wt.branch.push(newbranch, lossy=True, overwrite=True)
395
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
396
        self.assertNotEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
397
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
398
399
class PushToRemoteFromBzrTests(PushToRemoteBase,TestCaseWithTransport):
400
401
    _from_format = '2a'
402
403
404
class PushToRemoteFromGitTests(PushToRemoteBase,TestCaseWithTransport):
405
406
    _from_format = 'git'
407
408
409
class RemoteControlDirTests(TestCaseWithTransport):
410
411
    _test_needs_features = [ExecutableFeature('git')]
412
413
    def setUp(self):
414
        TestCaseWithTransport.setUp(self)
415
        self.remote_real = GitRepo.init('remote', mkdir=True)
416
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
417
        self.permit_url(self.remote_url)
418
419
    def test_remove_branch(self):
420
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
421
                message=b'message',
422
                committer=b'committer <committer@example.com>',
423
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
424
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
425
                message=b'another commit',
426
                committer=b'committer <committer@example.com>',
427
                author=b'author <author@example.com>',
428
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
429
430
        remote = ControlDir.open(self.remote_url)
431
        remote.destroy_branch(name='blah')
432
        self.assertEqual(
433
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
434
                {b'refs/heads/master': self.remote_real.head(),
435
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
436
                })
437
438
    def test_list_branches(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/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
448
449
        remote = ControlDir.open(self.remote_url)
450
        self.assertEqual(
6997.1.1 by Jelmer Vernooij
Fix tests on Python3.5.
451
                set(['master', 'blah', 'master']),
452
                set([b.name for b in remote.list_branches()]))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
453
454
    def test_get_branches(self):
455
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
456
                message=b'message',
457
                committer=b'committer <committer@example.com>',
458
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
459
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
460
                message=b'another commit',
461
                committer=b'committer <committer@example.com>',
462
                author=b'author <author@example.com>',
463
                ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
464
465
        remote = ControlDir.open(self.remote_url)
466
        self.assertEqual(
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
467
                {'': 'master', 'blah': 'blah', 'master': 'master'},
468
                {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.
469
470
    def test_remove_tag(self):
471
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
472
                message=b'message',
473
                committer=b'committer <committer@example.com>',
474
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
475
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
476
                message=b'another commit',
477
                committer=b'committer <committer@example.com>',
478
                author=b'author <author@example.com>',
479
                ref=b'refs/tags/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
480
481
        remote = ControlDir.open(self.remote_url)
482
        remote_branch = remote.open_branch()
483
        remote_branch.tags.delete_tag('blah')
484
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
485
        self.assertEqual(
486
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
487
                {b'refs/heads/master': self.remote_real.head(),
488
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
489
                })
490
491
    def test_set_tag(self):
492
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
493
                message=b'message',
494
                committer=b'committer <committer@example.com>',
495
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
496
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
497
                message=b'another commit',
498
                committer=b'committer <committer@example.com>',
499
                author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
500
501
        remote = ControlDir.open(self.remote_url)
502
        remote.open_branch().tags.set_tag(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
503
            b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
504
        self.assertEqual(
505
                self.remote_real.get_refs(),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
506
                {b'refs/heads/master': self.remote_real.head(),
507
                 b'refs/tags/blah': c1,
508
                 b'HEAD': self.remote_real.head(),
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
509
                })
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
510
511
    def test_annotated_tag(self):
512
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
513
                message=b'message',
514
                committer=b'committer <committer@example.com>',
515
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
516
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
517
                message=b'another commit',
518
                committer=b'committer <committer@example.com>',
519
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
520
521
        porcelain.tag_create(
522
                self.remote_real,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
523
                tag=b"blah",
524
                author=b'author <author@example.com>',
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
525
                objectish=c2,
526
                tag_time=int(time.time()),
527
                tag_timezone=0,
528
                annotated=True,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
529
                message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
530
531
        remote = ControlDir.open(self.remote_url)
532
        remote_branch = remote.open_branch()
533
        self.assertEqual({
6973.13.2 by Jelmer Vernooij
Fix some more tests.
534
            'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
535
            remote_branch.tags.get_tag_dict())
536
7142.3.1 by Jelmer Vernooij
Support .nick on remote branches and fix get_branch_reference.
537
    def test_get_branch_reference(self):
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
538
        c1 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
539
                message=b'message',
540
                committer=b'committer <committer@example.com>',
541
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
542
        c2 = self.remote_real.do_commit(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
543
                message=b'another commit',
544
                committer=b'committer <committer@example.com>',
545
                author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
546
547
        remote = ControlDir.open(self.remote_url)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
548
        self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
549
        self.assertEqual(None, remote.get_branch_reference('master'))
7142.3.1 by Jelmer Vernooij
Support .nick on remote branches and fix get_branch_reference.
550
551
    def test_get_branch_nick(self):
552
        c1 = self.remote_real.do_commit(
553
                message=b'message',
554
                committer=b'committer <committer@example.com>',
555
                author=b'author <author@example.com>')
556
        remote = ControlDir.open(self.remote_url)
557
        self.assertEqual('master', remote.open_branch().nick)