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