/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
16
17
"""Test the smart client."""
18
0.358.3 by Jelmer Vernooij
Enable absolute import.
19
from __future__ import absolute_import
20
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
21
from io import BytesIO
0.406.3 by Jelmer Vernooij
Add extra tests.
22
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
23
import os
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
24
import time
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
25
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
26
from ...controldir import ControlDir
27
from ...errors import (
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
28
    DivergedBranches,
0.200.1275 by Jelmer Vernooij
recognize missing repositories
29
    NotBranchError,
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
30
    NoSuchTag,
7103.1.2 by Jelmer Vernooij
Handle PermissionDenied.
31
    PermissionDenied,
0.200.1275 by Jelmer Vernooij
recognize missing repositories
32
    )
33
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
34
from ...tests import (
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
35
    TestCase,
36
    TestCaseWithTransport,
37
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
38
from ...tests.features import ExecutableFeature
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
39
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
40
from ..mapping import default_mapping
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
41
from ..remote import (
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
42
    split_git_url,
0.200.1275 by Jelmer Vernooij
recognize missing repositories
43
    parse_git_error,
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
44
    HeadUpdateFailed,
45
    RemoteGitError,
0.295.1 by Jelmer Vernooij
Split up branch formats.
46
    RemoteGitBranchFormat,
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
47
    )
48
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
49
from dulwich import porcelain
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
50
from dulwich.repo import Repo as GitRepo
51
52
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
53
class SplitUrlTests(TestCase):
54
55
    def test_simple(self):
6964.2.3 by Jelmer Vernooij
Review comments.
56
        self.assertEqual(("foo", None, None, "/bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
57
                         split_git_url("git://foo/bar"))
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
58
59
    def test_port(self):
6964.2.3 by Jelmer Vernooij
Review comments.
60
        self.assertEqual(("foo", 343, None, "/bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
61
                         split_git_url("git://foo:343/bar"))
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
62
63
    def test_username(self):
6964.2.3 by Jelmer Vernooij
Review comments.
64
        self.assertEqual(("foo", None, "la", "/bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
65
                         split_git_url("git://la@foo/bar"))
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
66
67
    def test_nopath(self):
6964.2.3 by Jelmer Vernooij
Review comments.
68
        self.assertEqual(("foo", None, None, "/"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
69
                         split_git_url("git://foo/"))
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
70
71
    def test_slashpath(self):
6964.2.3 by Jelmer Vernooij
Review comments.
72
        self.assertEqual(("foo", None, None, "//bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
73
                         split_git_url("git://foo//bar"))
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
74
75
    def test_homedir(self):
6964.2.3 by Jelmer Vernooij
Review comments.
76
        self.assertEqual(("foo", None, None, "~bar"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
77
                         split_git_url("git://foo/~bar"))
0.200.1275 by Jelmer Vernooij
recognize missing repositories
78
79
80
class ParseGitErrorTests(TestCase):
81
82
    def test_unknown(self):
83
        e = parse_git_error("url", "foo")
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
84
        self.assertIsInstance(e, RemoteGitError)
0.200.1275 by Jelmer Vernooij
recognize missing repositories
85
86
    def test_notbrancherror(self):
87
        e = parse_git_error("url", "\n Could not find Repository foo/bar")
88
        self.assertIsInstance(e, NotBranchError)
0.295.1 by Jelmer Vernooij
Split up branch formats.
89
7104.2.1 by Jelmer Vernooij
Handle another way of formatting Git "repository not found" errors.
90
    def test_notbrancherror_launchpad(self):
91
        e = parse_git_error("url", "Repository 'foo/bar' not found.")
92
        self.assertIsInstance(e, NotBranchError)
93
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
94
    def test_notbrancherror_github(self):
95
        e = parse_git_error("url", "Repository not found.\n")
96
        self.assertIsInstance(e, NotBranchError)
97
7131.7.3 by Jelmer Vernooij
Handle one more error.
98
    def test_notbrancherror_normal(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
99
        e = parse_git_error(
100
            "url", "fatal: '/srv/git/lintian-brush' does not appear to be a git repository")
7131.7.3 by Jelmer Vernooij
Handle one more error.
101
        self.assertIsInstance(e, NotBranchError)
102
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
103
    def test_head_update(self):
104
        e = parse_git_error("url", "HEAD failed to update\n")
105
        self.assertIsInstance(e, HeadUpdateFailed)
106
7103.1.2 by Jelmer Vernooij
Handle PermissionDenied.
107
    def test_permission_dnied(self):
108
        e = parse_git_error(
109
            "url",
110
            "access denied or repository not exported: /debian/altermime.git")
111
        self.assertIsInstance(e, PermissionDenied)
112
7131.7.1 by Jelmer Vernooij
Handle permission denied by GitLab.
113
    def test_permission_denied_gitlab(self):
114
        e = parse_git_error(
115
            "url",
116
            'GitLab: You are not allowed to push code to this project.\n')
117
        self.assertIsInstance(e, PermissionDenied)
118
7131.7.2 by Jelmer Vernooij
Handle github PermissionDenied.
119
    def test_permission_denied_github(self):
120
        e = parse_git_error(
121
            "url",
122
            'Permission to porridge/gaduhistory.git denied to jelmer.')
123
        self.assertIsInstance(e, PermissionDenied)
124
        self.assertEqual(e.path, 'porridge/gaduhistory.git')
125
        self.assertEqual(e.extra, ': denied to jelmer')
126
0.295.1 by Jelmer Vernooij
Split up branch formats.
127
128
class TestRemoteGitBranchFormat(TestCase):
129
130
    def setUp(self):
131
        super(TestRemoteGitBranchFormat, self).setUp()
132
        self.format = RemoteGitBranchFormat()
133
134
    def test_get_format_description(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
135
        self.assertEqual("Remote Git Branch",
136
                         self.format.get_format_description())
0.295.1 by Jelmer Vernooij
Split up branch formats.
137
138
    def test_get_network_name(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
139
        self.assertEqual(b"git", self.format.network_name())
0.295.1 by Jelmer Vernooij
Split up branch formats.
140
141
    def test_supports_tags(self):
142
        self.assertTrue(self.format.supports_tags())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
143
144
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
145
class TestRemoteGitBranch(TestCaseWithTransport):
146
147
    def setUp(self):
148
        TestCaseWithTransport.setUp(self)
149
        self.remote_real = GitRepo.init('remote', mkdir=True)
150
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
151
        self.permit_url(self.remote_url)
152
153
    def test_set_last_revision_info(self):
154
        c1 = self.remote_real.do_commit(
7143.16.8 by Jelmer Vernooij
Fix E126
155
            message=b'message 1',
156
            committer=b'committer <committer@example.com>',
157
            author=b'author <author@example.com>',
158
            ref=b'refs/heads/newbranch')
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
159
        c2 = self.remote_real.do_commit(
7143.16.8 by Jelmer Vernooij
Fix E126
160
            message=b'message 2',
161
            committer=b'committer <committer@example.com>',
162
            author=b'author <author@example.com>',
163
            ref=b'refs/heads/newbranch')
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
164
165
        remote = ControlDir.open(self.remote_url)
166
        newbranch = remote.open_branch('newbranch')
167
        self.assertEqual(newbranch.lookup_foreign_revision_id(c2),
168
                         newbranch.last_revision())
169
        newbranch.set_last_revision_info(
170
            1, newbranch.lookup_foreign_revision_id(c1))
7131.12.2 by Jelmer Vernooij
Fix tests on python 3.
171
        self.assertEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
172
        self.assertEqual(newbranch.last_revision(),
173
                         newbranch.lookup_foreign_revision_id(c1))
174
175
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
176
class FetchFromRemoteTestBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
177
178
    _test_needs_features = [ExecutableFeature('git')]
179
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
180
    _to_format = None
181
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
182
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
183
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
184
        self.remote_real = GitRepo.init('remote', mkdir=True)
185
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
186
        self.permit_url(self.remote_url)
187
188
    def test_sprout_simple(self):
189
        self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
190
            message=b'message',
191
            committer=b'committer <committer@example.com>',
192
            author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
193
194
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
195
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
196
        local = remote.sprout('local')
197
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
198
            default_mapping.revision_id_foreign_to_bzr(
199
                self.remote_real.head()),
200
            local.open_branch().last_revision())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
201
202
    def test_sprout_with_tags(self):
203
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
204
            message=b'message',
205
            committer=b'committer <committer@example.com>',
206
            author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
207
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
208
            message=b'another commit',
209
            committer=b'committer <committer@example.com>',
210
            author=b'author <author@example.com>',
211
            ref=b'refs/tags/another')
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
212
        self.remote_real.refs[b'refs/tags/blah'] = self.remote_real.head()
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
213
214
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
215
        self.make_controldir('local', format=self._to_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
216
        local = remote.sprout('local')
217
        local_branch = local.open_branch()
218
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
219
            default_mapping.revision_id_foreign_to_bzr(c1),
220
            local_branch.last_revision())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
221
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
222
            {'blah': local_branch.last_revision(),
223
             'another': default_mapping.revision_id_foreign_to_bzr(c2)},
224
            local_branch.tags.get_tag_dict())
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
225
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
226
    def test_sprout_with_annotated_tag(self):
227
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
228
            message=b'message',
229
            committer=b'committer <committer@example.com>',
230
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
231
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
232
            message=b'another commit',
233
            committer=b'committer <committer@example.com>',
234
            author=b'author <author@example.com>',
235
            ref=b'refs/heads/another')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
236
        porcelain.tag_create(
7143.15.2 by Jelmer Vernooij
Run autopep8.
237
            self.remote_real,
238
            tag=b"blah",
239
            author=b'author <author@example.com>',
240
            objectish=c2,
241
            tag_time=int(time.time()),
242
            tag_timezone=0,
243
            annotated=True,
244
            message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
245
246
        remote = ControlDir.open(self.remote_url)
247
        self.make_controldir('local', format=self._to_format)
7143.15.2 by Jelmer Vernooij
Run autopep8.
248
        local = remote.sprout(
249
            'local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
250
        local_branch = local.open_branch()
251
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
252
            default_mapping.revision_id_foreign_to_bzr(c1),
253
            local_branch.last_revision())
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
254
        self.assertEqual(
7143.16.8 by Jelmer Vernooij
Fix E126
255
            {'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
256
            local_branch.tags.get_tag_dict())
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
257
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
258
    def test_sprout_with_annotated_tag_unreferenced(self):
259
        c1 = self.remote_real.do_commit(
7143.16.8 by Jelmer Vernooij
Fix E126
260
            message=b'message',
261
            committer=b'committer <committer@example.com>',
262
            author=b'author <author@example.com>')
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
263
        c2 = self.remote_real.do_commit(
7143.16.8 by Jelmer Vernooij
Fix E126
264
            message=b'another commit',
265
            committer=b'committer <committer@example.com>',
266
            author=b'author <author@example.com>')
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
267
        porcelain.tag_create(
7143.16.8 by Jelmer Vernooij
Fix E126
268
            self.remote_real,
269
            tag=b"blah",
270
            author=b'author <author@example.com>',
271
            objectish=c1,
272
            tag_time=int(time.time()),
273
            tag_timezone=0,
274
            annotated=True,
275
            message=b"Annotated tag")
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
276
277
        remote = ControlDir.open(self.remote_url)
278
        self.make_controldir('local', format=self._to_format)
279
        local = remote.sprout(
7143.16.8 by Jelmer Vernooij
Fix E126
280
            'local',
281
            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.
282
        local_branch = local.open_branch()
283
        self.assertEqual(
7143.16.8 by Jelmer Vernooij
Fix E126
284
            default_mapping.revision_id_foreign_to_bzr(c1),
285
            local_branch.last_revision())
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
286
        self.assertEqual(
7143.16.8 by Jelmer Vernooij
Fix E126
287
            {'blah': default_mapping.revision_id_foreign_to_bzr(c1)},
288
            local_branch.tags.get_tag_dict())
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
289
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
290
7143.16.21 by Jelmer Vernooij
Fix regressions.
291
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase, TestCaseWithTransport):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
292
293
    _to_format = '2a'
294
295
7143.15.2 by Jelmer Vernooij
Run autopep8.
296
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase, TestCaseWithTransport):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
297
298
    _to_format = 'git'
299
300
301
class PushToRemoteBase(object):
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
302
303
    _test_needs_features = [ExecutableFeature('git')]
304
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
305
    _from_format = None
306
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
307
    def setUp(self):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
308
        TestCaseWithTransport.setUp(self)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
309
        self.remote_real = GitRepo.init('remote', mkdir=True)
310
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
311
        self.permit_url(self.remote_url)
312
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
313
    def test_push_branch_new(self):
314
        remote = ControlDir.open(self.remote_url)
315
        wt = self.make_branch_and_tree('local', format=self._from_format)
316
        self.build_tree(['local/blah'])
317
        wt.add(['blah'])
318
        revid = wt.commit('blah')
319
320
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
321
            result = remote.push_branch(wt.branch, name='newbranch')
322
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
323
            result = remote.push_branch(
324
                wt.branch, lossy=True, name='newbranch')
0.406.2 by Jelmer Vernooij
Add tests.
325
326
        self.assertEqual(0, result.old_revno)
327
        if self._from_format == 'git':
328
            self.assertEqual(1, result.new_revno)
329
        else:
330
            self.assertIs(None, result.new_revno)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
331
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
332
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
333
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
334
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
335
            {b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
336
             },
337
            self.remote_real.get_refs())
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
338
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
339
    def test_push(self):
340
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
341
            message=b'message',
342
            committer=b'committer <committer@example.com>',
343
            author=b'author <author@example.com>')
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
344
345
        remote = ControlDir.open(self.remote_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
346
        self.make_controldir('local', format=self._from_format)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
347
        local = remote.sprout('local')
348
        self.build_tree(['local/blah'])
349
        wt = local.open_workingtree()
350
        wt.add(['blah'])
351
        revid = wt.commit('blah')
352
        wt.branch.tags.set_tag('sometag', revid)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
353
        wt.branch.get_config_stack().set('branch.fetch_tags', True)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
354
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
355
        if self._from_format == 'git':
0.406.2 by Jelmer Vernooij
Add tests.
356
            result = wt.branch.push(remote.create_branch('newbranch'))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
357
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
358
            result = wt.branch.push(
359
                remote.create_branch('newbranch'), lossy=True)
0.406.2 by Jelmer Vernooij
Add tests.
360
361
        self.assertEqual(0, result.old_revno)
362
        self.assertEqual(2, result.new_revno)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
363
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
364
        result.report(BytesIO())
0.406.3 by Jelmer Vernooij
Add extra tests.
365
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
366
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
367
            {b'refs/heads/master': self.remote_real.head(),
368
             b'HEAD': self.remote_real.head(),
369
             b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
370
             b'refs/tags/sometag': self.remote_real.refs[b'refs/heads/newbranch'],
371
             },
372
            self.remote_real.get_refs())
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
373
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
374
    def test_push_diverged(self):
375
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
376
            message=b'message',
377
            committer=b'committer <committer@example.com>',
378
            author=b'author <author@example.com>',
379
            ref=b'refs/heads/newbranch')
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
380
381
        remote = ControlDir.open(self.remote_url)
382
        wt = self.make_branch_and_tree('local', format=self._from_format)
383
        self.build_tree(['local/blah'])
384
        wt.add(['blah'])
385
        revid = wt.commit('blah')
386
387
        newbranch = remote.open_branch('newbranch')
388
        if self._from_format == 'git':
389
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch)
390
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
391
            self.assertRaises(DivergedBranches, wt.branch.push,
392
                              newbranch, lossy=True)
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
393
394
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
395
            {b'refs/heads/newbranch': c1},
396
            self.remote_real.get_refs())
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
397
398
        if self._from_format == 'git':
399
            wt.branch.push(newbranch, overwrite=True)
400
        else:
401
            wt.branch.push(newbranch, lossy=True, overwrite=True)
402
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
403
        self.assertNotEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
404
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
405
7143.15.2 by Jelmer Vernooij
Run autopep8.
406
class PushToRemoteFromBzrTests(PushToRemoteBase, TestCaseWithTransport):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
407
408
    _from_format = '2a'
409
410
7143.15.2 by Jelmer Vernooij
Run autopep8.
411
class PushToRemoteFromGitTests(PushToRemoteBase, TestCaseWithTransport):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
412
413
    _from_format = 'git'
414
415
416
class RemoteControlDirTests(TestCaseWithTransport):
417
418
    _test_needs_features = [ExecutableFeature('git')]
419
420
    def setUp(self):
421
        TestCaseWithTransport.setUp(self)
422
        self.remote_real = GitRepo.init('remote', mkdir=True)
423
        self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
424
        self.permit_url(self.remote_url)
425
426
    def test_remove_branch(self):
427
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
428
            message=b'message',
429
            committer=b'committer <committer@example.com>',
430
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
431
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
432
            message=b'another commit',
433
            committer=b'committer <committer@example.com>',
434
            author=b'author <author@example.com>',
435
            ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
436
437
        remote = ControlDir.open(self.remote_url)
438
        remote.destroy_branch(name='blah')
439
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
440
            self.remote_real.get_refs(),
441
            {b'refs/heads/master': self.remote_real.head(),
442
             b'HEAD': self.remote_real.head(),
443
             })
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
444
445
    def test_list_branches(self):
446
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
447
            message=b'message',
448
            committer=b'committer <committer@example.com>',
449
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
450
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
451
            message=b'another commit',
452
            committer=b'committer <committer@example.com>',
453
            author=b'author <author@example.com>',
454
            ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
455
456
        remote = ControlDir.open(self.remote_url)
457
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
458
            set(['master', 'blah', 'master']),
459
            set([b.name for b in remote.list_branches()]))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
460
461
    def test_get_branches(self):
462
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
463
            message=b'message',
464
            committer=b'committer <committer@example.com>',
465
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
466
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
467
            message=b'another commit',
468
            committer=b'committer <committer@example.com>',
469
            author=b'author <author@example.com>',
470
            ref=b'refs/heads/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
471
472
        remote = ControlDir.open(self.remote_url)
473
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
474
            {'': 'master', 'blah': 'blah', 'master': 'master'},
475
            {n: b.name for (n, b) in remote.get_branches().items()})
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
476
477
    def test_remove_tag(self):
478
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
479
            message=b'message',
480
            committer=b'committer <committer@example.com>',
481
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
482
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
483
            message=b'another commit',
484
            committer=b'committer <committer@example.com>',
485
            author=b'author <author@example.com>',
486
            ref=b'refs/tags/blah')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
487
488
        remote = ControlDir.open(self.remote_url)
489
        remote_branch = remote.open_branch()
490
        remote_branch.tags.delete_tag('blah')
491
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
492
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
493
            self.remote_real.get_refs(),
494
            {b'refs/heads/master': self.remote_real.head(),
495
             b'HEAD': self.remote_real.head(),
496
             })
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
497
498
    def test_set_tag(self):
499
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
500
            message=b'message',
501
            committer=b'committer <committer@example.com>',
502
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
503
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
504
            message=b'another commit',
505
            committer=b'committer <committer@example.com>',
506
            author=b'author <author@example.com>')
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
507
508
        remote = ControlDir.open(self.remote_url)
509
        remote.open_branch().tags.set_tag(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
510
            b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
511
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
512
            self.remote_real.get_refs(),
513
            {b'refs/heads/master': self.remote_real.head(),
514
             b'refs/tags/blah': c1,
515
             b'HEAD': self.remote_real.head(),
516
             })
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
517
518
    def test_annotated_tag(self):
519
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
520
            message=b'message',
521
            committer=b'committer <committer@example.com>',
522
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
523
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
524
            message=b'another commit',
525
            committer=b'committer <committer@example.com>',
526
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
527
528
        porcelain.tag_create(
7143.15.2 by Jelmer Vernooij
Run autopep8.
529
            self.remote_real,
530
            tag=b"blah",
531
            author=b'author <author@example.com>',
532
            objectish=c2,
533
            tag_time=int(time.time()),
534
            tag_timezone=0,
535
            annotated=True,
536
            message=b"Annotated tag")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
537
538
        remote = ControlDir.open(self.remote_url)
539
        remote_branch = remote.open_branch()
540
        self.assertEqual({
6973.13.2 by Jelmer Vernooij
Fix some more tests.
541
            'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
542
            remote_branch.tags.get_tag_dict())
543
7142.3.1 by Jelmer Vernooij
Support .nick on remote branches and fix get_branch_reference.
544
    def test_get_branch_reference(self):
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
545
        c1 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
546
            message=b'message',
547
            committer=b'committer <committer@example.com>',
548
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
549
        c2 = self.remote_real.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
550
            message=b'another commit',
551
            committer=b'committer <committer@example.com>',
552
            author=b'author <author@example.com>')
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
553
554
        remote = ControlDir.open(self.remote_url)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
555
        self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
556
        self.assertEqual(None, remote.get_branch_reference('master'))
7142.3.1 by Jelmer Vernooij
Support .nick on remote branches and fix get_branch_reference.
557
558
    def test_get_branch_nick(self):
559
        c1 = self.remote_real.do_commit(
7143.16.21 by Jelmer Vernooij
Fix regressions.
560
            message=b'message',
561
            committer=b'committer <committer@example.com>',
562
            author=b'author <author@example.com>')
7142.3.1 by Jelmer Vernooij
Support .nick on remote branches and fix get_branch_reference.
563
        remote = ControlDir.open(self.remote_url)
564
        self.assertEqual('master', remote.open_branch().nick)