/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tests/test_remote.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Test the smart client."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from io import BytesIO
20
22
 
21
23
import os
39
41
from ..remote import (
40
42
    split_git_url,
41
43
    parse_git_error,
42
 
    parse_git_hangup,
43
44
    HeadUpdateFailed,
44
45
    RemoteGitError,
45
46
    RemoteGitBranchFormat,
46
 
    _git_url_and_path_from_transport,
47
47
    )
48
48
 
49
49
from dulwich import porcelain
50
 
from dulwich.errors import HangupException
51
50
from dulwich.repo import Repo as GitRepo
52
51
 
53
52
 
65
64
        self.assertEqual(("foo", None, "la", "/bar"),
66
65
                         split_git_url("git://la@foo/bar"))
67
66
 
68
 
    def test_username_password(self):
69
 
        self.assertEqual(
70
 
            ("foo", None, "la", "/bar"),
71
 
            split_git_url("git://la:passwd@foo/bar"))
72
 
 
73
67
    def test_nopath(self):
74
68
        self.assertEqual(("foo", None, None, "/"),
75
69
                         split_git_url("git://foo/"))
82
76
        self.assertEqual(("foo", None, None, "~bar"),
83
77
                         split_git_url("git://foo/~bar"))
84
78
 
85
 
    def test_file(self):
86
 
        self.assertEqual(
87
 
            ("", None, None, "/bar"),
88
 
            split_git_url("file:///bar"))
89
 
 
90
79
 
91
80
class ParseGitErrorTests(TestCase):
92
81
 
135
124
        self.assertEqual(e.path, 'porridge/gaduhistory.git')
136
125
        self.assertEqual(e.extra, ': denied to jelmer')
137
126
 
138
 
    def test_pre_receive_hook_declined(self):
139
 
        e = parse_git_error(
140
 
            "url",
141
 
            'pre-receive hook declined')
142
 
        self.assertIsInstance(e, PermissionDenied)
143
 
        self.assertEqual(e.path, "url")
144
 
        self.assertEqual(e.extra, ': pre-receive hook declined')
145
 
 
146
 
    def test_invalid_repo_name(self):
147
 
        e = parse_git_error(
148
 
            "url",
149
 
            """Gregwar/fatcat/tree/debian is not a valid repository name
150
 
Email support@github.com for help
151
 
""")
152
 
        self.assertIsInstance(e, NotBranchError)
153
 
 
154
 
    def test_invalid_git_error(self):
155
 
        self.assertEqual(
156
 
            PermissionDenied(
157
 
                'url',
158
 
                'GitLab: You are not allowed to push code to protected '
159
 
                'branches on this project.'),
160
 
            parse_git_error(
161
 
                'url',
162
 
                RemoteGitError(
163
 
                    'GitLab: You are not allowed to push code to '
164
 
                    'protected branches on this project.')))
165
 
 
166
 
 
167
 
class ParseHangupTests(TestCase):
168
 
 
169
 
    def setUp(self):
170
 
        super(ParseHangupTests, self).setUp()
171
 
        try:
172
 
            HangupException([b'foo'])
173
 
        except TypeError:
174
 
            self.skipTest('dulwich version too old')
175
 
 
176
 
    def test_not_set(self):
177
 
        self.assertIsInstance(
178
 
            parse_git_hangup('http://', HangupException()), HangupException)
179
 
 
180
 
    def test_single_line(self):
181
 
        self.assertEqual(
182
 
            RemoteGitError('foo bar'),
183
 
            parse_git_hangup('http://', HangupException([b'foo bar'])))
184
 
 
185
 
    def test_multi_lines(self):
186
 
        self.assertEqual(
187
 
            RemoteGitError('foo bar\nbla bla'),
188
 
            parse_git_hangup(
189
 
                'http://', HangupException([b'foo bar', b'bla bla'])))
190
 
 
191
 
    def test_filter_boring(self):
192
 
        self.assertEqual(
193
 
            RemoteGitError('foo bar'), parse_git_hangup('http://', HangupException(
194
 
                [b'=======', b'foo bar', b'======'])))
195
 
        self.assertEqual(
196
 
            RemoteGitError('foo bar'), parse_git_hangup('http://', HangupException(
197
 
                [b'remote: =======', b'remote: foo bar', b'remote: ======'])))
198
 
 
199
 
    def test_permission_denied(self):
200
 
        self.assertEqual(
201
 
            PermissionDenied('http://', 'You are not allowed to push code to this project.'),
202
 
            parse_git_hangup(
203
 
                'http://',
204
 
                HangupException(
205
 
                    [b'=======',
206
 
                     b'You are not allowed to push code to this project.', b'', b'======'])))
207
 
 
208
127
 
209
128
class TestRemoteGitBranchFormat(TestCase):
210
129
 
419
338
             },
420
339
            self.remote_real.get_refs())
421
340
 
422
 
    def test_push_branch_symref(self):
423
 
        cfg = self.remote_real.get_config()
424
 
        cfg.set((b'core', ), b'bare', True)
425
 
        cfg.write_to_path()
426
 
        self.remote_real.refs.set_symbolic_ref(b'HEAD', b'refs/heads/master')
427
 
        c1 = self.remote_real.do_commit(
428
 
            message=b'message',
429
 
            committer=b'committer <committer@example.com>',
430
 
            author=b'author <author@example.com>',
431
 
            ref=b'refs/heads/master')
432
 
        remote = ControlDir.open(self.remote_url)
433
 
        wt = self.make_branch_and_tree('local', format=self._from_format)
434
 
        self.build_tree(['local/blah'])
435
 
        wt.add(['blah'])
436
 
        revid = wt.commit('blah')
437
 
 
438
 
        if self._from_format == 'git':
439
 
            result = remote.push_branch(wt.branch, overwrite=True)
440
 
        else:
441
 
            result = remote.push_branch(wt.branch, lossy=True, overwrite=True)
442
 
 
443
 
        self.assertEqual(None, result.old_revno)
444
 
        if self._from_format == 'git':
445
 
            self.assertEqual(1, result.new_revno)
446
 
        else:
447
 
            self.assertIs(None, result.new_revno)
448
 
 
449
 
        result.report(BytesIO())
450
 
 
451
 
        self.assertEqual(
452
 
            {
453
 
                b'HEAD': self.remote_real.refs[b'refs/heads/master'],
454
 
                b'refs/heads/master': self.remote_real.refs[b'refs/heads/master'],
455
 
            },
456
 
            self.remote_real.get_refs())
457
 
 
458
341
    def test_push_branch_new_with_tags(self):
459
342
        remote = ControlDir.open(self.remote_url)
460
343
        builder = self.make_branch_builder('local', format=self._from_format)
629
512
        self.assertEqual(
630
513
            {'': 'master', 'blah': 'blah', 'master': 'master'},
631
514
            {n: b.name for (n, b) in remote.get_branches().items()})
632
 
        self.assertEqual(
633
 
            set(['', 'blah', 'master']), set(remote.branch_names()))
634
515
 
635
516
    def test_remove_tag(self):
636
517
        c1 = self.remote_real.do_commit(
720
601
            author=b'author <author@example.com>')
721
602
        remote = ControlDir.open(self.remote_url)
722
603
        self.assertEqual('master', remote.open_branch().nick)
723
 
 
724
 
 
725
 
class GitUrlAndPathFromTransportTests(TestCase):
726
 
 
727
 
    def test_file(self):
728
 
        split_url = _git_url_and_path_from_transport('file:///home/blah')
729
 
        self.assertEqual(split_url.scheme, 'file')
730
 
        self.assertEqual(split_url.path, '/home/blah')
731
 
 
732
 
    def test_file_segment_params(self):
733
 
        split_url = _git_url_and_path_from_transport('file:///home/blah,branch=master')
734
 
        self.assertEqual(split_url.scheme, 'file')
735
 
        self.assertEqual(split_url.path, '/home/blah')
736
 
 
737
 
    def test_git_smart(self):
738
 
        split_url = _git_url_and_path_from_transport(
739
 
            'git://github.com/dulwich/dulwich,branch=master')
740
 
        self.assertEqual(split_url.scheme, 'git')
741
 
        self.assertEqual(split_url.path, '/dulwich/dulwich')
742
 
 
743
 
    def test_https(self):
744
 
        split_url = _git_url_and_path_from_transport(
745
 
            'https://github.com/dulwich/dulwich')
746
 
        self.assertEqual(split_url.scheme, 'https')
747
 
        self.assertEqual(split_url.path, '/dulwich/dulwich')
748
 
 
749
 
    def test_https_segment_params(self):
750
 
        split_url = _git_url_and_path_from_transport(
751
 
            'https://github.com/dulwich/dulwich,branch=master')
752
 
        self.assertEqual(split_url.scheme, 'https')
753
 
        self.assertEqual(split_url.path, '/dulwich/dulwich')