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