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 |
||
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
21 |
import os |
22 |
||
23 |
from ....controldir import ControlDir |
|
|
0.200.1642
by Jelmer Vernooij
Use relative imports in tests. |
24 |
from ....errors import ( |
|
0.200.1275
by Jelmer Vernooij
recognize missing repositories |
25 |
BzrError, |
26 |
NotBranchError, |
|
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
27 |
NoSuchTag, |
|
0.200.1275
by Jelmer Vernooij
recognize missing repositories |
28 |
)
|
29 |
||
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
30 |
from ....tests import ( |
31 |
TestCase, |
|
32 |
TestCaseWithTransport, |
|
33 |
)
|
|
34 |
from ....tests.features import ExecutableFeature |
|
|
0.200.709
by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour. |
35 |
|
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
36 |
from ..mapping import default_mapping |
|
0.200.1642
by Jelmer Vernooij
Use relative imports in tests. |
37 |
from ..remote import ( |
|
0.200.709
by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour. |
38 |
split_git_url, |
|
0.200.1275
by Jelmer Vernooij
recognize missing repositories |
39 |
parse_git_error, |
|
0.295.1
by Jelmer Vernooij
Split up branch formats. |
40 |
RemoteGitBranchFormat, |
|
0.200.709
by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour. |
41 |
)
|
42 |
||
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
43 |
from dulwich.repo import Repo as GitRepo |
44 |
||
45 |
||
|
0.200.709
by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour. |
46 |
class SplitUrlTests(TestCase): |
47 |
||
48 |
def test_simple(self): |
|
|
0.246.2
by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories. |
49 |
self.assertEquals(("foo", None, None, "/bar"), |
|
0.200.709
by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour. |
50 |
split_git_url("git://foo/bar")) |
51 |
||
52 |
def test_port(self): |
|
|
0.246.2
by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories. |
53 |
self.assertEquals(("foo", 343, None, "/bar"), |
|
0.200.709
by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour. |
54 |
split_git_url("git://foo:343/bar")) |
55 |
||
56 |
def test_username(self): |
|
|
0.246.2
by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories. |
57 |
self.assertEquals(("foo", None, "la", "/bar"), |
|
0.200.709
by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour. |
58 |
split_git_url("git://la@foo/bar")) |
59 |
||
60 |
def test_nopath(self): |
|
|
0.246.2
by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories. |
61 |
self.assertEquals(("foo", None, None, "/"), |
|
0.200.709
by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour. |
62 |
split_git_url("git://foo/")) |
63 |
||
64 |
def test_slashpath(self): |
|
|
0.246.2
by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories. |
65 |
self.assertEquals(("foo", None, None, "//bar"), |
|
0.200.709
by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour. |
66 |
split_git_url("git://foo//bar")) |
|
0.246.2
by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories. |
67 |
|
68 |
def test_homedir(self): |
|
69 |
self.assertEquals(("foo", None, None, "~bar"), |
|
70 |
split_git_url("git://foo/~bar")) |
|
|
0.200.1275
by Jelmer Vernooij
recognize missing repositories |
71 |
|
72 |
||
73 |
class ParseGitErrorTests(TestCase): |
|
74 |
||
75 |
def test_unknown(self): |
|
76 |
e = parse_git_error("url", "foo") |
|
77 |
self.assertIsInstance(e, BzrError) |
|
78 |
||
79 |
def test_notbrancherror(self): |
|
80 |
e = parse_git_error("url", "\n Could not find Repository foo/bar") |
|
81 |
self.assertIsInstance(e, NotBranchError) |
|
|
0.295.1
by Jelmer Vernooij
Split up branch formats. |
82 |
|
83 |
||
84 |
class TestRemoteGitBranchFormat(TestCase): |
|
85 |
||
86 |
def setUp(self): |
|
87 |
super(TestRemoteGitBranchFormat, self).setUp() |
|
88 |
self.format = RemoteGitBranchFormat() |
|
89 |
||
90 |
def test_get_format_description(self): |
|
91 |
self.assertEquals("Remote Git Branch", self.format.get_format_description()) |
|
92 |
||
93 |
def test_get_network_name(self): |
|
94 |
self.assertEquals("git", self.format.network_name()) |
|
95 |
||
96 |
def test_supports_tags(self): |
|
97 |
self.assertTrue(self.format.supports_tags()) |
|
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
98 |
|
99 |
||
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
100 |
class FetchFromRemoteTestBase(object): |
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
101 |
|
102 |
_test_needs_features = [ExecutableFeature('git')] |
|
103 |
||
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
104 |
_to_format = None |
105 |
||
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
106 |
def setUp(self): |
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
107 |
TestCaseWithTransport.setUp(self) |
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
108 |
self.remote_real = GitRepo.init('remote', mkdir=True) |
109 |
self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path) |
|
110 |
self.permit_url(self.remote_url) |
|
111 |
||
112 |
def test_sprout_simple(self): |
|
113 |
self.remote_real.do_commit( |
|
114 |
message='message', |
|
115 |
committer='committer <committer@example.com>', |
|
116 |
author='author <author@example.com>') |
|
117 |
||
118 |
remote = ControlDir.open(self.remote_url) |
|
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
119 |
self.make_controldir('local', format=self._to_format) |
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
120 |
local = remote.sprout('local') |
121 |
self.assertEqual( |
|
122 |
default_mapping.revision_id_foreign_to_bzr(self.remote_real.head()), |
|
123 |
local.open_branch().last_revision()) |
|
124 |
||
125 |
def test_sprout_with_tags(self): |
|
126 |
c1 = self.remote_real.do_commit( |
|
127 |
message='message', |
|
128 |
committer='committer <committer@example.com>', |
|
129 |
author='author <author@example.com>') |
|
130 |
c2 = self.remote_real.do_commit( |
|
131 |
message='another commit', |
|
132 |
committer='committer <committer@example.com>', |
|
133 |
author='author <author@example.com>', |
|
134 |
ref='refs/tags/another') |
|
135 |
self.remote_real.refs['refs/tags/blah'] = self.remote_real.head() |
|
136 |
||
137 |
remote = ControlDir.open(self.remote_url) |
|
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
138 |
self.make_controldir('local', format=self._to_format) |
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
139 |
local = remote.sprout('local') |
140 |
local_branch = local.open_branch() |
|
141 |
self.assertEqual( |
|
142 |
default_mapping.revision_id_foreign_to_bzr(c1), |
|
143 |
local_branch.last_revision()) |
|
144 |
self.assertEqual( |
|
145 |
{'blah': local_branch.last_revision(), |
|
146 |
'another': default_mapping.revision_id_foreign_to_bzr(c2)}, |
|
147 |
local_branch.tags.get_tag_dict()) |
|
148 |
||
149 |
||
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
150 |
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase,TestCaseWithTransport): |
151 |
||
152 |
_to_format = '2a' |
|
153 |
||
154 |
||
155 |
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase,TestCaseWithTransport): |
|
156 |
||
157 |
_to_format = 'git' |
|
158 |
||
159 |
||
160 |
class PushToRemoteBase(object): |
|
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
161 |
|
162 |
_test_needs_features = [ExecutableFeature('git')] |
|
163 |
||
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
164 |
_from_format = None |
165 |
||
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
166 |
def setUp(self): |
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
167 |
TestCaseWithTransport.setUp(self) |
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
168 |
self.remote_real = GitRepo.init('remote', mkdir=True) |
169 |
self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path) |
|
170 |
self.permit_url(self.remote_url) |
|
171 |
||
172 |
def test_push(self): |
|
173 |
c1 = self.remote_real.do_commit( |
|
174 |
message='message', |
|
175 |
committer='committer <committer@example.com>', |
|
176 |
author='author <author@example.com>') |
|
177 |
||
178 |
remote = ControlDir.open(self.remote_url) |
|
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
179 |
self.make_controldir('local', format=self._from_format) |
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
180 |
local = remote.sprout('local') |
181 |
self.build_tree(['local/blah']) |
|
182 |
wt = local.open_workingtree() |
|
183 |
wt.add(['blah']) |
|
184 |
revid = wt.commit('blah') |
|
185 |
wt.branch.tags.set_tag('sometag', revid) |
|
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
186 |
wt.branch.get_config_stack().set('branch.fetch_tags', True) |
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
187 |
|
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
188 |
if self._from_format == 'git': |
189 |
wt.branch.push(remote.open_branch()) |
|
190 |
else: |
|
191 |
wt.branch.push(remote.open_branch(), lossy=True) |
|
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
192 |
|
193 |
self.assertNotEqual(self.remote_real.head(), c1) |
|
194 |
self.assertEqual( |
|
195 |
{'refs/heads/master': self.remote_real.head(), |
|
196 |
'HEAD': self.remote_real.head(), |
|
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
197 |
'refs/tags/sometag': self.remote_real.head(), |
|
0.376.1
by Jelmer Vernooij
Add tests for remote operations. |
198 |
},
|
199 |
self.remote_real.get_refs()) |
|
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
200 |
|
201 |
||
202 |
class PushToRemoteFromBzrTests(PushToRemoteBase,TestCaseWithTransport): |
|
203 |
||
204 |
_from_format = '2a' |
|
205 |
||
206 |
||
207 |
class PushToRemoteFromGitTests(PushToRemoteBase,TestCaseWithTransport): |
|
208 |
||
209 |
_from_format = 'git' |
|
210 |
||
211 |
||
212 |
class RemoteControlDirTests(TestCaseWithTransport): |
|
213 |
||
214 |
_test_needs_features = [ExecutableFeature('git')] |
|
215 |
||
216 |
def setUp(self): |
|
217 |
TestCaseWithTransport.setUp(self) |
|
218 |
self.remote_real = GitRepo.init('remote', mkdir=True) |
|
219 |
self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path) |
|
220 |
self.permit_url(self.remote_url) |
|
221 |
||
222 |
def test_remove_branch(self): |
|
223 |
c1 = self.remote_real.do_commit( |
|
224 |
message='message', |
|
225 |
committer='committer <committer@example.com>', |
|
226 |
author='author <author@example.com>') |
|
227 |
c2 = self.remote_real.do_commit( |
|
228 |
message='another commit', |
|
229 |
committer='committer <committer@example.com>', |
|
230 |
author='author <author@example.com>', |
|
231 |
ref='refs/heads/blah') |
|
232 |
||
233 |
remote = ControlDir.open(self.remote_url) |
|
234 |
remote.destroy_branch(name='blah') |
|
235 |
self.assertEqual( |
|
236 |
self.remote_real.get_refs(), |
|
237 |
{'refs/heads/master': self.remote_real.head(), |
|
238 |
'HEAD': self.remote_real.head(), |
|
239 |
})
|
|
240 |
||
241 |
def test_list_branches(self): |
|
242 |
c1 = self.remote_real.do_commit( |
|
243 |
message='message', |
|
244 |
committer='committer <committer@example.com>', |
|
245 |
author='author <author@example.com>') |
|
246 |
c2 = self.remote_real.do_commit( |
|
247 |
message='another commit', |
|
248 |
committer='committer <committer@example.com>', |
|
249 |
author='author <author@example.com>', |
|
250 |
ref='refs/heads/blah') |
|
251 |
||
252 |
remote = ControlDir.open(self.remote_url) |
|
253 |
self.assertEqual( |
|
254 |
['', 'blah', 'master'], |
|
255 |
[b.name for b in remote.list_branches()]) |
|
256 |
||
257 |
def test_get_branches(self): |
|
258 |
c1 = self.remote_real.do_commit( |
|
259 |
message='message', |
|
260 |
committer='committer <committer@example.com>', |
|
261 |
author='author <author@example.com>') |
|
262 |
c2 = self.remote_real.do_commit( |
|
263 |
message='another commit', |
|
264 |
committer='committer <committer@example.com>', |
|
265 |
author='author <author@example.com>', |
|
266 |
ref='refs/heads/blah') |
|
267 |
||
268 |
remote = ControlDir.open(self.remote_url) |
|
269 |
self.assertEqual( |
|
270 |
{'', 'blah', 'master'}, |
|
271 |
set(remote.get_branches().keys())) |
|
272 |
||
273 |
def test_remove_tag(self): |
|
274 |
c1 = self.remote_real.do_commit( |
|
275 |
message='message', |
|
276 |
committer='committer <committer@example.com>', |
|
277 |
author='author <author@example.com>') |
|
278 |
c2 = self.remote_real.do_commit( |
|
279 |
message='another commit', |
|
280 |
committer='committer <committer@example.com>', |
|
281 |
author='author <author@example.com>', |
|
282 |
ref='refs/tags/blah') |
|
283 |
||
284 |
remote = ControlDir.open(self.remote_url) |
|
285 |
remote_branch = remote.open_branch() |
|
286 |
remote_branch.tags.delete_tag('blah') |
|
287 |
self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah') |
|
288 |
self.assertEqual( |
|
289 |
self.remote_real.get_refs(), |
|
290 |
{'refs/heads/master': self.remote_real.head(), |
|
291 |
'HEAD': self.remote_real.head(), |
|
292 |
})
|
|
293 |
||
294 |
def test_set_tag(self): |
|
295 |
c1 = self.remote_real.do_commit( |
|
296 |
message='message', |
|
297 |
committer='committer <committer@example.com>', |
|
298 |
author='author <author@example.com>') |
|
299 |
c2 = self.remote_real.do_commit( |
|
300 |
message='another commit', |
|
301 |
committer='committer <committer@example.com>', |
|
302 |
author='author <author@example.com>') |
|
303 |
||
304 |
remote = ControlDir.open(self.remote_url) |
|
305 |
remote.open_branch().tags.set_tag( |
|
306 |
'blah', default_mapping.revision_id_foreign_to_bzr(c1)) |
|
307 |
self.assertEqual( |
|
308 |
self.remote_real.get_refs(), |
|
309 |
{'refs/heads/master': self.remote_real.head(), |
|
310 |
'refs/tags/blah': c1, |
|
311 |
'HEAD': self.remote_real.head(), |
|
312 |
})
|