56
55
def test_simple(self):
57
56
self.assertEqual(("foo", None, None, "/bar"),
58
split_git_url("git://foo/bar"))
57
split_git_url("git://foo/bar"))
60
59
def test_port(self):
61
60
self.assertEqual(("foo", 343, None, "/bar"),
62
split_git_url("git://foo:343/bar"))
61
split_git_url("git://foo:343/bar"))
64
63
def test_username(self):
65
64
self.assertEqual(("foo", None, "la", "/bar"),
66
split_git_url("git://la@foo/bar"))
65
split_git_url("git://la@foo/bar"))
68
67
def test_nopath(self):
69
68
self.assertEqual(("foo", None, None, "/"),
70
split_git_url("git://foo/"))
69
split_git_url("git://foo/"))
72
71
def test_slashpath(self):
73
72
self.assertEqual(("foo", None, None, "//bar"),
74
split_git_url("git://foo//bar"))
73
split_git_url("git://foo//bar"))
76
75
def test_homedir(self):
77
76
self.assertEqual(("foo", None, None, "~bar"),
78
split_git_url("git://foo/~bar"))
77
split_git_url("git://foo/~bar"))
81
80
class ParseGitErrorTests(TestCase):
123
142
self.assertTrue(self.format.supports_tags())
145
class TestRemoteGitBranch(TestCaseWithTransport):
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)
153
def test_set_last_revision_info(self):
154
c1 = self.remote_real.do_commit(
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')
159
c2 = self.remote_real.do_commit(
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')
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))
171
self.assertEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
172
self.assertEqual(newbranch.last_revision(),
173
newbranch.lookup_foreign_revision_id(c1))
126
176
class FetchFromRemoteTestBase(object):
128
178
_test_needs_features = [ExecutableFeature('git')]
138
188
def test_sprout_simple(self):
139
189
self.remote_real.do_commit(
141
committer=b'committer <committer@example.com>',
142
author=b'author <author@example.com>')
191
committer=b'committer <committer@example.com>',
192
author=b'author <author@example.com>')
144
194
remote = ControlDir.open(self.remote_url)
145
195
self.make_controldir('local', format=self._to_format)
146
196
local = remote.sprout('local')
147
197
self.assertEqual(
148
default_mapping.revision_id_foreign_to_bzr(self.remote_real.head()),
149
local.open_branch().last_revision())
198
default_mapping.revision_id_foreign_to_bzr(
199
self.remote_real.head()),
200
local.open_branch().last_revision())
151
202
def test_sprout_with_tags(self):
152
203
c1 = self.remote_real.do_commit(
154
committer=b'committer <committer@example.com>',
155
author=b'author <author@example.com>')
205
committer=b'committer <committer@example.com>',
206
author=b'author <author@example.com>')
156
207
c2 = self.remote_real.do_commit(
157
message=b'another commit',
158
committer=b'committer <committer@example.com>',
159
author=b'author <author@example.com>',
160
ref=b'refs/tags/another')
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')
161
212
self.remote_real.refs[b'refs/tags/blah'] = self.remote_real.head()
163
214
remote = ControlDir.open(self.remote_url)
165
216
local = remote.sprout('local')
166
217
local_branch = local.open_branch()
167
218
self.assertEqual(
168
default_mapping.revision_id_foreign_to_bzr(c1),
169
local_branch.last_revision())
219
default_mapping.revision_id_foreign_to_bzr(c1),
220
local_branch.last_revision())
170
221
self.assertEqual(
171
{'blah': local_branch.last_revision(),
172
'another': default_mapping.revision_id_foreign_to_bzr(c2)},
173
local_branch.tags.get_tag_dict())
222
{'blah': local_branch.last_revision(),
223
'another': default_mapping.revision_id_foreign_to_bzr(c2)},
224
local_branch.tags.get_tag_dict())
175
226
def test_sprout_with_annotated_tag(self):
176
227
c1 = self.remote_real.do_commit(
178
committer=b'committer <committer@example.com>',
179
author=b'author <author@example.com>')
180
c2 = self.remote_real.do_commit(
181
message=b'another commit',
182
committer=b'committer <committer@example.com>',
183
author=b'author <author@example.com>',
184
ref=b'refs/heads/another')
185
porcelain.tag_create(
188
author=b'author <author@example.com>',
190
tag_time=int(time.time()),
193
message=b"Annotated tag")
195
remote = ControlDir.open(self.remote_url)
196
self.make_controldir('local', format=self._to_format)
197
local = remote.sprout('local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
198
local_branch = local.open_branch()
200
default_mapping.revision_id_foreign_to_bzr(c1),
201
local_branch.last_revision())
203
{'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
204
local_branch.tags.get_tag_dict())
207
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase,TestCaseWithTransport):
229
committer=b'committer <committer@example.com>',
230
author=b'author <author@example.com>')
231
c2 = self.remote_real.do_commit(
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')
236
porcelain.tag_create(
239
author=b'author <author@example.com>',
241
tag_time=int(time.time()),
244
message=b"Annotated tag")
246
remote = ControlDir.open(self.remote_url)
247
self.make_controldir('local', format=self._to_format)
248
local = remote.sprout(
249
'local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
250
local_branch = local.open_branch()
252
default_mapping.revision_id_foreign_to_bzr(c1),
253
local_branch.last_revision())
255
{'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
256
local_branch.tags.get_tag_dict())
258
def test_sprout_with_annotated_tag_unreferenced(self):
259
c1 = self.remote_real.do_commit(
261
committer=b'committer <committer@example.com>',
262
author=b'author <author@example.com>')
263
c2 = self.remote_real.do_commit(
264
message=b'another commit',
265
committer=b'committer <committer@example.com>',
266
author=b'author <author@example.com>')
267
porcelain.tag_create(
270
author=b'author <author@example.com>',
272
tag_time=int(time.time()),
275
message=b"Annotated tag")
277
remote = ControlDir.open(self.remote_url)
278
self.make_controldir('local', format=self._to_format)
279
local = remote.sprout(
281
revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
282
local_branch = local.open_branch()
284
default_mapping.revision_id_foreign_to_bzr(c1),
285
local_branch.last_revision())
287
{'blah': default_mapping.revision_id_foreign_to_bzr(c1)},
288
local_branch.tags.get_tag_dict())
291
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase, TestCaseWithTransport):
209
293
_to_format = '2a'
212
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase,TestCaseWithTransport):
296
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase, TestCaseWithTransport):
214
298
_to_format = 'git'
339
426
def test_remove_branch(self):
340
427
c1 = self.remote_real.do_commit(
342
committer=b'committer <committer@example.com>',
343
author=b'author <author@example.com>')
429
committer=b'committer <committer@example.com>',
430
author=b'author <author@example.com>')
344
431
c2 = self.remote_real.do_commit(
345
message=b'another commit',
346
committer=b'committer <committer@example.com>',
347
author=b'author <author@example.com>',
348
ref=b'refs/heads/blah')
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')
350
437
remote = ControlDir.open(self.remote_url)
351
438
remote.destroy_branch(name='blah')
352
439
self.assertEqual(
353
self.remote_real.get_refs(),
354
{b'refs/heads/master': self.remote_real.head(),
355
b'HEAD': self.remote_real.head(),
440
self.remote_real.get_refs(),
441
{b'refs/heads/master': self.remote_real.head(),
442
b'HEAD': self.remote_real.head(),
358
445
def test_list_branches(self):
359
446
c1 = self.remote_real.do_commit(
361
committer=b'committer <committer@example.com>',
362
author=b'author <author@example.com>')
448
committer=b'committer <committer@example.com>',
449
author=b'author <author@example.com>')
363
450
c2 = self.remote_real.do_commit(
364
message=b'another commit',
365
committer=b'committer <committer@example.com>',
366
author=b'author <author@example.com>',
367
ref=b'refs/heads/blah')
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')
369
456
remote = ControlDir.open(self.remote_url)
370
457
self.assertEqual(
371
set(['master', 'blah', 'master']),
372
set([b.name for b in remote.list_branches()]))
458
set(['master', 'blah', 'master']),
459
set([b.name for b in remote.list_branches()]))
374
461
def test_get_branches(self):
375
462
c1 = self.remote_real.do_commit(
377
committer=b'committer <committer@example.com>',
378
author=b'author <author@example.com>')
464
committer=b'committer <committer@example.com>',
465
author=b'author <author@example.com>')
379
466
c2 = self.remote_real.do_commit(
380
message=b'another commit',
381
committer=b'committer <committer@example.com>',
382
author=b'author <author@example.com>',
383
ref=b'refs/heads/blah')
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')
385
472
remote = ControlDir.open(self.remote_url)
386
473
self.assertEqual(
387
{'': 'master', 'blah': 'blah', 'master': 'master'},
388
{n: b.name for (n, b) in remote.get_branches().items()})
474
{'': 'master', 'blah': 'blah', 'master': 'master'},
475
{n: b.name for (n, b) in remote.get_branches().items()})
390
477
def test_remove_tag(self):
391
478
c1 = self.remote_real.do_commit(
393
committer=b'committer <committer@example.com>',
394
author=b'author <author@example.com>')
480
committer=b'committer <committer@example.com>',
481
author=b'author <author@example.com>')
395
482
c2 = self.remote_real.do_commit(
396
message=b'another commit',
397
committer=b'committer <committer@example.com>',
398
author=b'author <author@example.com>',
399
ref=b'refs/tags/blah')
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')
401
488
remote = ControlDir.open(self.remote_url)
402
489
remote_branch = remote.open_branch()
403
490
remote_branch.tags.delete_tag('blah')
404
491
self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
405
492
self.assertEqual(
406
self.remote_real.get_refs(),
407
{b'refs/heads/master': self.remote_real.head(),
408
b'HEAD': self.remote_real.head(),
493
self.remote_real.get_refs(),
494
{b'refs/heads/master': self.remote_real.head(),
495
b'HEAD': self.remote_real.head(),
411
498
def test_set_tag(self):
412
499
c1 = self.remote_real.do_commit(
414
committer=b'committer <committer@example.com>',
415
author=b'author <author@example.com>')
501
committer=b'committer <committer@example.com>',
502
author=b'author <author@example.com>')
416
503
c2 = self.remote_real.do_commit(
417
message=b'another commit',
418
committer=b'committer <committer@example.com>',
419
author=b'author <author@example.com>')
504
message=b'another commit',
505
committer=b'committer <committer@example.com>',
506
author=b'author <author@example.com>')
421
508
remote = ControlDir.open(self.remote_url)
422
509
remote.open_branch().tags.set_tag(
423
510
b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
424
511
self.assertEqual(
425
self.remote_real.get_refs(),
426
{b'refs/heads/master': self.remote_real.head(),
427
b'refs/tags/blah': c1,
428
b'HEAD': self.remote_real.head(),
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(),
431
518
def test_annotated_tag(self):
432
519
c1 = self.remote_real.do_commit(
434
committer=b'committer <committer@example.com>',
435
author=b'author <author@example.com>')
521
committer=b'committer <committer@example.com>',
522
author=b'author <author@example.com>')
436
523
c2 = self.remote_real.do_commit(
437
message=b'another commit',
438
committer=b'committer <committer@example.com>',
439
author=b'author <author@example.com>')
524
message=b'another commit',
525
committer=b'committer <committer@example.com>',
526
author=b'author <author@example.com>')
441
528
porcelain.tag_create(
444
author=b'author <author@example.com>',
446
tag_time=int(time.time()),
449
message=b"Annotated tag")
531
author=b'author <author@example.com>',
533
tag_time=int(time.time()),
536
message=b"Annotated tag")
451
538
remote = ControlDir.open(self.remote_url)
452
539
remote_branch = remote.open_branch()
454
541
'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
455
542
remote_branch.tags.get_tag_dict())
457
def tetst_get_branch_reference(self):
544
def test_get_branch_reference(self):
458
545
c1 = self.remote_real.do_commit(
460
committer=b'committer <committer@example.com>',
461
author=b'author <author@example.com>')
547
committer=b'committer <committer@example.com>',
548
author=b'author <author@example.com>')
462
549
c2 = self.remote_real.do_commit(
463
message=b'another commit',
464
committer=b'committer <committer@example.com>',
465
author=b'author <author@example.com>')
550
message=b'another commit',
551
committer=b'committer <committer@example.com>',
552
author=b'author <author@example.com>')
467
554
remote = ControlDir.open(self.remote_url)
468
555
self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))
469
556
self.assertEqual(None, remote.get_branch_reference('master'))
558
def test_get_branch_nick(self):
559
c1 = self.remote_real.do_commit(
561
committer=b'committer <committer@example.com>',
562
author=b'author <author@example.com>')
563
remote = ControlDir.open(self.remote_url)
564
self.assertEqual('master', remote.open_branch().nick)