/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,
7490.29.12 by Jelmer Vernooij
Parse stderr from remote git servers when they hang up.
44
    parse_git_hangup,
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,
7371.3.2 by Jelmer Vernooij
Fix URL parsing for Git.
48
    _git_url_and_path_from_transport,
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
49
    )
50
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
51
from dulwich import porcelain
7490.29.12 by Jelmer Vernooij
Parse stderr from remote git servers when they hang up.
52
from dulwich.errors import HangupException
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
53
from dulwich.repo import Repo as GitRepo
54
55
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
56
class SplitUrlTests(TestCase):
57
58
    def test_simple(self):
6964.2.3 by Jelmer Vernooij
Review comments.
59
        self.assertEqual(("foo", None, None, "/bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
60
                         split_git_url("git://foo/bar"))
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
61
62
    def test_port(self):
6964.2.3 by Jelmer Vernooij
Review comments.
63
        self.assertEqual(("foo", 343, None, "/bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
64
                         split_git_url("git://foo:343/bar"))
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
65
66
    def test_username(self):
6964.2.3 by Jelmer Vernooij
Review comments.
67
        self.assertEqual(("foo", None, "la", "/bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
68
                         split_git_url("git://la@foo/bar"))
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
69
7290.38.1 by Jelmer Vernooij
Backport python3.8 support patch to breezy 3.0.
70
    def test_username_password(self):
71
        self.assertEqual(
72
            ("foo", None, "la", "/bar"),
73
            split_git_url("git://la:passwd@foo/bar"))
74
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
75
    def test_nopath(self):
6964.2.3 by Jelmer Vernooij
Review comments.
76
        self.assertEqual(("foo", None, None, "/"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
77
                         split_git_url("git://foo/"))
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
78
79
    def test_slashpath(self):
6964.2.3 by Jelmer Vernooij
Review comments.
80
        self.assertEqual(("foo", None, None, "//bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
81
                         split_git_url("git://foo//bar"))
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
82
83
    def test_homedir(self):
6964.2.3 by Jelmer Vernooij
Review comments.
84
        self.assertEqual(("foo", None, None, "~bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
85
                         split_git_url("git://foo/~bar"))
0.200.1275 by Jelmer Vernooij
recognize missing repositories
86
7290.38.1 by Jelmer Vernooij
Backport python3.8 support patch to breezy 3.0.
87
    def test_file(self):
7290.38.2 by Jelmer Vernooij
More fixes.
88
        self.assertEqual(
89
            ("", None, None, "/bar"),
90
            split_git_url("file:///bar"))
7290.38.1 by Jelmer Vernooij
Backport python3.8 support patch to breezy 3.0.
91
0.200.1275 by Jelmer Vernooij
recognize missing repositories
92
93
class ParseGitErrorTests(TestCase):
94
95
    def test_unknown(self):
96
        e = parse_git_error("url", "foo")
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
97
        self.assertIsInstance(e, RemoteGitError)
0.200.1275 by Jelmer Vernooij
recognize missing repositories
98
99
    def test_notbrancherror(self):
100
        e = parse_git_error("url", "\n Could not find Repository foo/bar")
101
        self.assertIsInstance(e, NotBranchError)
0.295.1 by Jelmer Vernooij
Split up branch formats.
102
7104.2.1 by Jelmer Vernooij
Handle another way of formatting Git "repository not found" errors.
103
    def test_notbrancherror_launchpad(self):
104
        e = parse_git_error("url", "Repository 'foo/bar' not found.")
105
        self.assertIsInstance(e, NotBranchError)
106
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
107
    def test_notbrancherror_github(self):
108
        e = parse_git_error("url", "Repository not found.\n")
109
        self.assertIsInstance(e, NotBranchError)
110
7131.7.3 by Jelmer Vernooij
Handle one more error.
111
    def test_notbrancherror_normal(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
112
        e = parse_git_error(
113
            "url", "fatal: '/srv/git/lintian-brush' does not appear to be a git repository")
7131.7.3 by Jelmer Vernooij
Handle one more error.
114
        self.assertIsInstance(e, NotBranchError)
115
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
116
    def test_head_update(self):
117
        e = parse_git_error("url", "HEAD failed to update\n")
118
        self.assertIsInstance(e, HeadUpdateFailed)
119
7103.1.2 by Jelmer Vernooij
Handle PermissionDenied.
120
    def test_permission_dnied(self):
121
        e = parse_git_error(
122
            "url",
123
            "access denied or repository not exported: /debian/altermime.git")
124
        self.assertIsInstance(e, PermissionDenied)
125
7131.7.1 by Jelmer Vernooij
Handle permission denied by GitLab.
126
    def test_permission_denied_gitlab(self):
127
        e = parse_git_error(
128
            "url",
129
            'GitLab: You are not allowed to push code to this project.\n')
130
        self.assertIsInstance(e, PermissionDenied)
131
7131.7.2 by Jelmer Vernooij
Handle github PermissionDenied.
132
    def test_permission_denied_github(self):
133
        e = parse_git_error(
134
            "url",
135
            'Permission to porridge/gaduhistory.git denied to jelmer.')
136
        self.assertIsInstance(e, PermissionDenied)
137
        self.assertEqual(e.path, 'porridge/gaduhistory.git')
138
        self.assertEqual(e.extra, ': denied to jelmer')
139
7379.1.1 by Jelmer Vernooij
Handle invalid repository name on GitHub.
140
    def test_invalid_repo_name(self):
141
        e = parse_git_error(
142
            "url",
143
            """Gregwar/fatcat/tree/debian is not a valid repository name
144
Email support@github.com for help
145
""")
146
        self.assertIsInstance(e, NotBranchError)
147
0.295.1 by Jelmer Vernooij
Split up branch formats.
148
7490.29.12 by Jelmer Vernooij
Parse stderr from remote git servers when they hang up.
149
class ParseHangupTests(TestCase):
150
151
    def setUp(self):
152
        super(ParseHangupTests, self).setUp()
153
        try:
154
            HangupException(['foo'])
155
        except TypeError:
156
            self.skipTest('dulwich version too old')
157
158
    def test_not_set(self):
159
        self.assertIsInstance(
160
            parse_git_hangup('http://', HangupException()), HangupException)
161
162
    def test_single_line(self):
163
        self.assertEqual(
164
            RemoteGitError('foo bar'),
165
            parse_git_hangup('http://', HangupException(['foo bar'])))
166
167
    def test_multi_lines(self):
168
        self.assertEqual(
169
            RemoteGitError('foo bar\nbla bla'),
170
            parse_git_hangup(
171
                'http://', HangupException(['foo bar', 'bla bla'])))
172
173
    def test_filter_boring(self):
174
        self.assertEqual(
175
            RemoteGitError('foo bar'), parse_git_hangup('http://', HangupException(
176
                ['=======', 'foo bar', '======'])))
177
178
    def test_permission_denied(self):
179
        self.assertEqual(
180
            PermissionDenied('http://', 'You are not allowed to push code to this project.'),
181
            parse_git_hangup(
182
                'http://',
183
                HangupException(
184
                    ['=======',
185
                     'You are not allowed to push code to this project.', '', '======'])))
186
187
0.295.1 by Jelmer Vernooij
Split up branch formats.
188
class TestRemoteGitBranchFormat(TestCase):
189
190
    def setUp(self):
191
        super(TestRemoteGitBranchFormat, self).setUp()
192
        self.format = RemoteGitBranchFormat()
193
194
    def test_get_format_description(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
195
        self.assertEqual("Remote Git Branch",
196
                         self.format.get_format_description())
0.295.1 by Jelmer Vernooij
Split up branch formats.
197
198
    def test_get_network_name(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
199
        self.assertEqual(b"git", self.format.network_name())
0.295.1 by Jelmer Vernooij
Split up branch formats.
200
201
    def test_supports_tags(self):
202
        self.assertTrue(self.format.supports_tags())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
203
204
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
205
class TestRemoteGitBranch(TestCaseWithTransport):
206
7183.1.1 by Jelmer Vernooij
Add missing feature for git test that requires git executable.
207
    _test_needs_features = [ExecutableFeature('git')]
208
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
209
    def setUp(self):
210
        TestCaseWithTransport.setUp(self)
211
        self.remote_real = GitRepo.init('remote', mkdir=True)
212
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
213
        self.permit_url(self.remote_url)
214
215
    def test_set_last_revision_info(self):
216
        c1 = self.remote_real.do_commit(
7143.16.8 by Jelmer Vernooij
Fix E126
217
            message=b'message 1',
218
            committer=b'committer <committer@example.com>',
219
            author=b'author <author@example.com>',
220
            ref=b'refs/heads/newbranch')
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
221
        c2 = self.remote_real.do_commit(
7143.16.8 by Jelmer Vernooij
Fix E126
222
            message=b'message 2',
223
            committer=b'committer <committer@example.com>',
224
            author=b'author <author@example.com>',
225
            ref=b'refs/heads/newbranch')
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
226
227
        remote = ControlDir.open(self.remote_url)
228
        newbranch = remote.open_branch('newbranch')
229
        self.assertEqual(newbranch.lookup_foreign_revision_id(c2),
230
                         newbranch.last_revision())
231
        newbranch.set_last_revision_info(
232
            1, newbranch.lookup_foreign_revision_id(c1))
7131.12.2 by Jelmer Vernooij
Fix tests on python 3.
233
        self.assertEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
234
        self.assertEqual(newbranch.last_revision(),
235
                         newbranch.lookup_foreign_revision_id(c1))
236
237
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
238
class FetchFromRemoteTestBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
239
240
    _test_needs_features = [ExecutableFeature('git')]
241
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
242
    _to_format = None
243
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
244
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
245
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
246
        self.remote_real = GitRepo.init('remote', mkdir=True)
247
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
248
        self.permit_url(self.remote_url)
249
250
    def test_sprout_simple(self):
251
        self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
252
            message=b'message',
253
            committer=b'committer <committer@example.com>',
254
            author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
255
256
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
257
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
258
        local = remote.sprout('local')
259
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
260
            default_mapping.revision_id_foreign_to_bzr(
261
                self.remote_real.head()),
262
            local.open_branch().last_revision())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
263
264
    def test_sprout_with_tags(self):
265
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
266
            message=b'message',
267
            committer=b'committer <committer@example.com>',
268
            author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
269
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
270
            message=b'another commit',
271
            committer=b'committer <committer@example.com>',
272
            author=b'author <author@example.com>',
273
            ref=b'refs/tags/another')
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
274
        self.remote_real.refs[b'refs/tags/blah'] = self.remote_real.head()
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
275
276
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
277
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
278
        local = remote.sprout('local')
279
        local_branch = local.open_branch()
280
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
281
            default_mapping.revision_id_foreign_to_bzr(c1),
282
            local_branch.last_revision())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
283
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
284
            {'blah': local_branch.last_revision(),
285
             'another': default_mapping.revision_id_foreign_to_bzr(c2)},
286
            local_branch.tags.get_tag_dict())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
287
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
288
    def test_sprout_with_annotated_tag(self):
289
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
290
            message=b'message',
291
            committer=b'committer <committer@example.com>',
292
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
293
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
294
            message=b'another commit',
295
            committer=b'committer <committer@example.com>',
296
            author=b'author <author@example.com>',
297
            ref=b'refs/heads/another')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
298
        porcelain.tag_create(
7143.15.2 by Jelmer Vernooij
Run autopep8.
299
            self.remote_real,
300
            tag=b"blah",
301
            author=b'author <author@example.com>',
302
            objectish=c2,
303
            tag_time=int(time.time()),
304
            tag_timezone=0,
305
            annotated=True,
306
            message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
307
308
        remote = ControlDir.open(self.remote_url)
309
        self.make_controldir('local', format=self._to_format)
7143.15.2 by Jelmer Vernooij
Run autopep8.
310
        local = remote.sprout(
311
            'local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
312
        local_branch = local.open_branch()
313
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
314
            default_mapping.revision_id_foreign_to_bzr(c1),
315
            local_branch.last_revision())
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
316
        self.assertEqual(
7143.16.8 by Jelmer Vernooij
Fix E126
317
            {'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
318
            local_branch.tags.get_tag_dict())
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
319
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
320
    def test_sprout_with_annotated_tag_unreferenced(self):
321
        c1 = self.remote_real.do_commit(
7143.16.8 by Jelmer Vernooij
Fix E126
322
            message=b'message',
323
            committer=b'committer <committer@example.com>',
324
            author=b'author <author@example.com>')
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
325
        c2 = self.remote_real.do_commit(
7143.16.8 by Jelmer Vernooij
Fix E126
326
            message=b'another commit',
327
            committer=b'committer <committer@example.com>',
328
            author=b'author <author@example.com>')
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
329
        porcelain.tag_create(
7143.16.8 by Jelmer Vernooij
Fix E126
330
            self.remote_real,
331
            tag=b"blah",
332
            author=b'author <author@example.com>',
333
            objectish=c1,
334
            tag_time=int(time.time()),
335
            tag_timezone=0,
336
            annotated=True,
337
            message=b"Annotated tag")
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
338
339
        remote = ControlDir.open(self.remote_url)
340
        self.make_controldir('local', format=self._to_format)
341
        local = remote.sprout(
7143.16.8 by Jelmer Vernooij
Fix E126
342
            'local',
343
            revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
344
        local_branch = local.open_branch()
345
        self.assertEqual(
7143.16.8 by Jelmer Vernooij
Fix E126
346
            default_mapping.revision_id_foreign_to_bzr(c1),
347
            local_branch.last_revision())
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
348
        self.assertEqual(
7143.16.8 by Jelmer Vernooij
Fix E126
349
            {'blah': default_mapping.revision_id_foreign_to_bzr(c1)},
350
            local_branch.tags.get_tag_dict())
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
351
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
352
7143.16.21 by Jelmer Vernooij
Fix regressions.
353
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase, TestCaseWithTransport):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
354
355
    _to_format = '2a'
356
357
7143.15.2 by Jelmer Vernooij
Run autopep8.
358
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase, TestCaseWithTransport):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
359
360
    _to_format = 'git'
361
362
363
class PushToRemoteBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
364
365
    _test_needs_features = [ExecutableFeature('git')]
366
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
367
    _from_format = None
368
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
369
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
370
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
371
        self.remote_real = GitRepo.init('remote', mkdir=True)
372
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
373
        self.permit_url(self.remote_url)
374
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
375
    def test_push_branch_new(self):
376
        remote = ControlDir.open(self.remote_url)
377
        wt = self.make_branch_and_tree('local', format=self._from_format)
378
        self.build_tree(['local/blah'])
379
        wt.add(['blah'])
380
        revid = wt.commit('blah')
381
382
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
383
            result = remote.push_branch(wt.branch, name='newbranch')
384
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
385
            result = remote.push_branch(
386
                wt.branch, lossy=True, name='newbranch')
0.406.2 by Jelmer Vernooij
Add tests.
387
388
        self.assertEqual(0, result.old_revno)
389
        if self._from_format == 'git':
390
            self.assertEqual(1, result.new_revno)
391
        else:
392
            self.assertIs(None, result.new_revno)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
393
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
394
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
395
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
396
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
397
            {b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
398
             },
399
            self.remote_real.get_refs())
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
400
7484.1.2 by Jelmer Vernooij
Add some tests.
401
    def test_push_branch_symref(self):
402
        cfg = self.remote_real.get_config()
403
        cfg.set((b'core', ), b'bare', True)
404
        cfg.write_to_path()
405
        self.remote_real.refs.set_symbolic_ref(b'HEAD', b'refs/heads/master')
406
        c1 = self.remote_real.do_commit(
407
            message=b'message',
408
            committer=b'committer <committer@example.com>',
409
            author=b'author <author@example.com>',
410
            ref=b'refs/heads/master')
411
        remote = ControlDir.open(self.remote_url)
412
        wt = self.make_branch_and_tree('local', format=self._from_format)
413
        self.build_tree(['local/blah'])
414
        wt.add(['blah'])
415
        revid = wt.commit('blah')
416
417
        if self._from_format == 'git':
418
            result = remote.push_branch(wt.branch, overwrite=True)
419
        else:
420
            result = remote.push_branch(wt.branch, lossy=True, overwrite=True)
421
422
        self.assertEqual(None, result.old_revno)
423
        if self._from_format == 'git':
424
            self.assertEqual(1, result.new_revno)
425
        else:
426
            self.assertIs(None, result.new_revno)
427
428
        result.report(BytesIO())
429
430
        self.assertEqual(
7484.1.3 by Jelmer Vernooij
Fix formatting.
431
            {
432
                b'HEAD': self.remote_real.refs[b'refs/heads/master'],
433
                b'refs/heads/master': self.remote_real.refs[b'refs/heads/master'],
7484.1.2 by Jelmer Vernooij
Add some tests.
434
            },
435
            self.remote_real.get_refs())
436
7289.1.2 by Jelmer Vernooij
Fix pushing of tags as part of nascent git branches.
437
    def test_push_branch_new_with_tags(self):
438
        remote = ControlDir.open(self.remote_url)
439
        builder = self.make_branch_builder('local', format=self._from_format)
440
        builder.start_series()
441
        rev_1 = builder.build_snapshot(None, [
442
            ('add', ('', None, 'directory', '')),
443
            ('add', ('filename', None, 'file', b'content'))])
444
        rev_2 = builder.build_snapshot(
445
            [rev_1], [('modify', ('filename', b'new-content\n'))])
446
        rev_3 = builder.build_snapshot(
447
            [rev_1], [('modify', ('filename', b'new-new-content\n'))])
448
        builder.finish_series()
449
        branch = builder.get_branch()
450
        try:
451
            branch.tags.set_tag('atag', rev_2)
452
        except TagsNotSupported:
453
            raise TestNotApplicable('source format does not support tags')
454
455
        branch.get_config_stack().set('branch.fetch_tags', True)
456
        if self._from_format == 'git':
457
            result = remote.push_branch(branch, name='newbranch')
458
        else:
459
            result = remote.push_branch(
460
                branch, lossy=True, name='newbranch')
461
462
        self.assertEqual(0, result.old_revno)
463
        if self._from_format == 'git':
464
            self.assertEqual(2, result.new_revno)
465
        else:
466
            self.assertIs(None, result.new_revno)
467
468
        result.report(BytesIO())
469
470
        self.assertEqual(
471
            {b'refs/heads/newbranch', b'refs/tags/atag'},
472
            set(self.remote_real.get_refs().keys()))
473
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
474
    def test_push(self):
475
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
476
            message=b'message',
477
            committer=b'committer <committer@example.com>',
478
            author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
479
480
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
481
        self.make_controldir('local', format=self._from_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
482
        local = remote.sprout('local')
483
        self.build_tree(['local/blah'])
484
        wt = local.open_workingtree()
485
        wt.add(['blah'])
486
        revid = wt.commit('blah')
487
        wt.branch.tags.set_tag('sometag', revid)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
488
        wt.branch.get_config_stack().set('branch.fetch_tags', True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
489
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
490
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
491
            result = wt.branch.push(remote.create_branch('newbranch'))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
492
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
493
            result = wt.branch.push(
494
                remote.create_branch('newbranch'), lossy=True)
0.406.2 by Jelmer Vernooij
Add tests.
495
496
        self.assertEqual(0, result.old_revno)
497
        self.assertEqual(2, result.new_revno)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
498
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
499
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
500
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
501
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
502
            {b'refs/heads/master': self.remote_real.head(),
503
             b'HEAD': self.remote_real.head(),
504
             b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
505
             b'refs/tags/sometag': self.remote_real.refs[b'refs/heads/newbranch'],
506
             },
507
            self.remote_real.get_refs())
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
508
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
509
    def test_push_diverged(self):
510
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
511
            message=b'message',
512
            committer=b'committer <committer@example.com>',
513
            author=b'author <author@example.com>',
514
            ref=b'refs/heads/newbranch')
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
515
516
        remote = ControlDir.open(self.remote_url)
517
        wt = self.make_branch_and_tree('local', format=self._from_format)
518
        self.build_tree(['local/blah'])
519
        wt.add(['blah'])
520
        revid = wt.commit('blah')
521
522
        newbranch = remote.open_branch('newbranch')
523
        if self._from_format == 'git':
524
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch)
525
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
526
            self.assertRaises(DivergedBranches, wt.branch.push,
527
                              newbranch, lossy=True)
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
528
529
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
530
            {b'refs/heads/newbranch': c1},
531
            self.remote_real.get_refs())
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
532
533
        if self._from_format == 'git':
534
            wt.branch.push(newbranch, overwrite=True)
535
        else:
536
            wt.branch.push(newbranch, lossy=True, overwrite=True)
537
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
538
        self.assertNotEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
539
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
540
7143.15.2 by Jelmer Vernooij
Run autopep8.
541
class PushToRemoteFromBzrTests(PushToRemoteBase, TestCaseWithTransport):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
542
543
    _from_format = '2a'
544
545
7143.15.2 by Jelmer Vernooij
Run autopep8.
546
class PushToRemoteFromGitTests(PushToRemoteBase, TestCaseWithTransport):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
547
548
    _from_format = 'git'
549
550
551
class RemoteControlDirTests(TestCaseWithTransport):
552
553
    _test_needs_features = [ExecutableFeature('git')]
554
555
    def setUp(self):
556
        TestCaseWithTransport.setUp(self)
557
        self.remote_real = GitRepo.init('remote', mkdir=True)
558
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
559
        self.permit_url(self.remote_url)
560
561
    def test_remove_branch(self):
562
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
563
            message=b'message',
564
            committer=b'committer <committer@example.com>',
565
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
566
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
567
            message=b'another commit',
568
            committer=b'committer <committer@example.com>',
569
            author=b'author <author@example.com>',
570
            ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
571
572
        remote = ControlDir.open(self.remote_url)
573
        remote.destroy_branch(name='blah')
574
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
575
            self.remote_real.get_refs(),
576
            {b'refs/heads/master': self.remote_real.head(),
577
             b'HEAD': self.remote_real.head(),
578
             })
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
579
580
    def test_list_branches(self):
581
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
582
            message=b'message',
583
            committer=b'committer <committer@example.com>',
584
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
585
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
586
            message=b'another commit',
587
            committer=b'committer <committer@example.com>',
588
            author=b'author <author@example.com>',
589
            ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
590
591
        remote = ControlDir.open(self.remote_url)
592
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
593
            set(['master', 'blah', 'master']),
594
            set([b.name for b in remote.list_branches()]))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
595
596
    def test_get_branches(self):
597
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
598
            message=b'message',
599
            committer=b'committer <committer@example.com>',
600
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
601
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
602
            message=b'another commit',
603
            committer=b'committer <committer@example.com>',
604
            author=b'author <author@example.com>',
605
            ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
606
607
        remote = ControlDir.open(self.remote_url)
608
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
609
            {'': 'master', 'blah': 'blah', 'master': 'master'},
610
            {n: b.name for (n, b) in remote.get_branches().items()})
7490.13.6 by Jelmer Vernooij
Fix tests.
611
        self.assertEqual(
612
            set(['', 'blah', 'master']), set(remote.branch_names()))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
613
614
    def test_remove_tag(self):
615
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
616
            message=b'message',
617
            committer=b'committer <committer@example.com>',
618
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
619
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
620
            message=b'another commit',
621
            committer=b'committer <committer@example.com>',
622
            author=b'author <author@example.com>',
623
            ref=b'refs/tags/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
624
625
        remote = ControlDir.open(self.remote_url)
626
        remote_branch = remote.open_branch()
627
        remote_branch.tags.delete_tag('blah')
628
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
629
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
630
            self.remote_real.get_refs(),
631
            {b'refs/heads/master': self.remote_real.head(),
632
             b'HEAD': self.remote_real.head(),
633
             })
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
634
635
    def test_set_tag(self):
636
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
637
            message=b'message',
638
            committer=b'committer <committer@example.com>',
639
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
640
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
641
            message=b'another commit',
642
            committer=b'committer <committer@example.com>',
643
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
644
645
        remote = ControlDir.open(self.remote_url)
646
        remote.open_branch().tags.set_tag(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
647
            b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
648
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
649
            self.remote_real.get_refs(),
650
            {b'refs/heads/master': self.remote_real.head(),
651
             b'refs/tags/blah': c1,
652
             b'HEAD': self.remote_real.head(),
653
             })
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
654
655
    def test_annotated_tag(self):
656
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
657
            message=b'message',
658
            committer=b'committer <committer@example.com>',
659
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
660
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
661
            message=b'another commit',
662
            committer=b'committer <committer@example.com>',
663
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
664
665
        porcelain.tag_create(
7143.15.2 by Jelmer Vernooij
Run autopep8.
666
            self.remote_real,
667
            tag=b"blah",
668
            author=b'author <author@example.com>',
669
            objectish=c2,
670
            tag_time=int(time.time()),
671
            tag_timezone=0,
672
            annotated=True,
673
            message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
674
675
        remote = ControlDir.open(self.remote_url)
676
        remote_branch = remote.open_branch()
677
        self.assertEqual({
6973.13.2 by Jelmer Vernooij
Fix some more tests.
678
            'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
679
            remote_branch.tags.get_tag_dict())
680
7142.3.1 by Jelmer Vernooij
Support .nick on remote branches and fix get_branch_reference.
681
    def test_get_branch_reference(self):
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
682
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
683
            message=b'message',
684
            committer=b'committer <committer@example.com>',
685
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
686
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
687
            message=b'another commit',
688
            committer=b'committer <committer@example.com>',
689
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
690
691
        remote = ControlDir.open(self.remote_url)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
692
        self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
693
        self.assertEqual(None, remote.get_branch_reference('master'))
7142.3.1 by Jelmer Vernooij
Support .nick on remote branches and fix get_branch_reference.
694
695
    def test_get_branch_nick(self):
696
        c1 = self.remote_real.do_commit(
7143.16.21 by Jelmer Vernooij
Fix regressions.
697
            message=b'message',
698
            committer=b'committer <committer@example.com>',
699
            author=b'author <author@example.com>')
7142.3.1 by Jelmer Vernooij
Support .nick on remote branches and fix get_branch_reference.
700
        remote = ControlDir.open(self.remote_url)
701
        self.assertEqual('master', remote.open_branch().nick)
7371.3.2 by Jelmer Vernooij
Fix URL parsing for Git.
702
703
704
class GitUrlAndPathFromTransportTests(TestCase):
705
706
    def test_file(self):
707
        split_url = _git_url_and_path_from_transport('file:///home/blah')
708
        self.assertEqual(split_url.scheme, 'file')
709
        self.assertEqual(split_url.path, '/home/blah')
710
711
    def test_file_segment_params(self):
712
        split_url = _git_url_and_path_from_transport('file:///home/blah,branch=master')
713
        self.assertEqual(split_url.scheme, 'file')
714
        self.assertEqual(split_url.path, '/home/blah')
715
716
    def test_git_smart(self):
717
        split_url = _git_url_and_path_from_transport(
718
            'git://github.com/dulwich/dulwich,branch=master')
719
        self.assertEqual(split_url.scheme, 'git')
720
        self.assertEqual(split_url.path, '/dulwich/dulwich')
721
722
    def test_https(self):
723
        split_url = _git_url_and_path_from_transport(
724
            'https://github.com/dulwich/dulwich')
725
        self.assertEqual(split_url.scheme, 'https')
726
        self.assertEqual(split_url.path, '/dulwich/dulwich')
727
728
    def test_https_segment_params(self):
729
        split_url = _git_url_and_path_from_transport(
730
            'https://github.com/dulwich/dulwich,branch=master')
731
        self.assertEqual(split_url.scheme, 'https')
732
        self.assertEqual(split_url.path, '/dulwich/dulwich')