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):
147
_test_needs_features = [ExecutableFeature('git')]
150
TestCaseWithTransport.setUp(self)
151
self.remote_real = GitRepo.init('remote', mkdir=True)
152
self.remote_url = 'git://%s/' % os.path.abspath(self.remote_real.path)
153
self.permit_url(self.remote_url)
155
def test_set_last_revision_info(self):
156
c1 = self.remote_real.do_commit(
157
message=b'message 1',
158
committer=b'committer <committer@example.com>',
159
author=b'author <author@example.com>',
160
ref=b'refs/heads/newbranch')
161
c2 = self.remote_real.do_commit(
162
message=b'message 2',
163
committer=b'committer <committer@example.com>',
164
author=b'author <author@example.com>',
165
ref=b'refs/heads/newbranch')
167
remote = ControlDir.open(self.remote_url)
168
newbranch = remote.open_branch('newbranch')
169
self.assertEqual(newbranch.lookup_foreign_revision_id(c2),
170
newbranch.last_revision())
171
newbranch.set_last_revision_info(
172
1, newbranch.lookup_foreign_revision_id(c1))
173
self.assertEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
174
self.assertEqual(newbranch.last_revision(),
175
newbranch.lookup_foreign_revision_id(c1))
126
178
class FetchFromRemoteTestBase(object):
128
180
_test_needs_features = [ExecutableFeature('git')]
138
190
def test_sprout_simple(self):
139
191
self.remote_real.do_commit(
141
committer=b'committer <committer@example.com>',
142
author=b'author <author@example.com>')
193
committer=b'committer <committer@example.com>',
194
author=b'author <author@example.com>')
144
196
remote = ControlDir.open(self.remote_url)
145
197
self.make_controldir('local', format=self._to_format)
146
198
local = remote.sprout('local')
147
199
self.assertEqual(
148
default_mapping.revision_id_foreign_to_bzr(self.remote_real.head()),
149
local.open_branch().last_revision())
200
default_mapping.revision_id_foreign_to_bzr(
201
self.remote_real.head()),
202
local.open_branch().last_revision())
151
204
def test_sprout_with_tags(self):
152
205
c1 = self.remote_real.do_commit(
154
committer=b'committer <committer@example.com>',
155
author=b'author <author@example.com>')
207
committer=b'committer <committer@example.com>',
208
author=b'author <author@example.com>')
156
209
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')
210
message=b'another commit',
211
committer=b'committer <committer@example.com>',
212
author=b'author <author@example.com>',
213
ref=b'refs/tags/another')
161
214
self.remote_real.refs[b'refs/tags/blah'] = self.remote_real.head()
163
216
remote = ControlDir.open(self.remote_url)
165
218
local = remote.sprout('local')
166
219
local_branch = local.open_branch()
167
220
self.assertEqual(
168
default_mapping.revision_id_foreign_to_bzr(c1),
169
local_branch.last_revision())
221
default_mapping.revision_id_foreign_to_bzr(c1),
222
local_branch.last_revision())
170
223
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())
224
{'blah': local_branch.last_revision(),
225
'another': default_mapping.revision_id_foreign_to_bzr(c2)},
226
local_branch.tags.get_tag_dict())
175
228
def test_sprout_with_annotated_tag(self):
176
229
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):
231
committer=b'committer <committer@example.com>',
232
author=b'author <author@example.com>')
233
c2 = self.remote_real.do_commit(
234
message=b'another commit',
235
committer=b'committer <committer@example.com>',
236
author=b'author <author@example.com>',
237
ref=b'refs/heads/another')
238
porcelain.tag_create(
241
author=b'author <author@example.com>',
243
tag_time=int(time.time()),
246
message=b"Annotated tag")
248
remote = ControlDir.open(self.remote_url)
249
self.make_controldir('local', format=self._to_format)
250
local = remote.sprout(
251
'local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
252
local_branch = local.open_branch()
254
default_mapping.revision_id_foreign_to_bzr(c1),
255
local_branch.last_revision())
257
{'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
258
local_branch.tags.get_tag_dict())
260
def test_sprout_with_annotated_tag_unreferenced(self):
261
c1 = self.remote_real.do_commit(
263
committer=b'committer <committer@example.com>',
264
author=b'author <author@example.com>')
265
c2 = self.remote_real.do_commit(
266
message=b'another commit',
267
committer=b'committer <committer@example.com>',
268
author=b'author <author@example.com>')
269
porcelain.tag_create(
272
author=b'author <author@example.com>',
274
tag_time=int(time.time()),
277
message=b"Annotated tag")
279
remote = ControlDir.open(self.remote_url)
280
self.make_controldir('local', format=self._to_format)
281
local = remote.sprout(
283
revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
284
local_branch = local.open_branch()
286
default_mapping.revision_id_foreign_to_bzr(c1),
287
local_branch.last_revision())
289
{'blah': default_mapping.revision_id_foreign_to_bzr(c1)},
290
local_branch.tags.get_tag_dict())
293
class FetchFromRemoteToBzrTests(FetchFromRemoteTestBase, TestCaseWithTransport):
209
295
_to_format = '2a'
212
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase,TestCaseWithTransport):
298
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase, TestCaseWithTransport):
214
300
_to_format = 'git'
247
334
result.report(BytesIO())
249
336
self.assertEqual(
250
{b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
252
self.remote_real.get_refs())
337
{b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
339
self.remote_real.get_refs())
341
def test_push_branch_new_with_tags(self):
342
remote = ControlDir.open(self.remote_url)
343
builder = self.make_branch_builder('local', format=self._from_format)
344
builder.start_series()
345
rev_1 = builder.build_snapshot(None, [
346
('add', ('', None, 'directory', '')),
347
('add', ('filename', None, 'file', b'content'))])
348
rev_2 = builder.build_snapshot(
349
[rev_1], [('modify', ('filename', b'new-content\n'))])
350
rev_3 = builder.build_snapshot(
351
[rev_1], [('modify', ('filename', b'new-new-content\n'))])
352
builder.finish_series()
353
branch = builder.get_branch()
355
branch.tags.set_tag('atag', rev_2)
356
except TagsNotSupported:
357
raise TestNotApplicable('source format does not support tags')
359
branch.get_config_stack().set('branch.fetch_tags', True)
360
if self._from_format == 'git':
361
result = remote.push_branch(branch, name='newbranch')
363
result = remote.push_branch(
364
branch, lossy=True, name='newbranch')
366
self.assertEqual(0, result.old_revno)
367
if self._from_format == 'git':
368
self.assertEqual(2, result.new_revno)
370
self.assertIs(None, result.new_revno)
372
result.report(BytesIO())
375
{b'refs/heads/newbranch', b'refs/tags/atag'},
376
set(self.remote_real.get_refs().keys()))
254
378
def test_push(self):
255
379
c1 = self.remote_real.do_commit(
257
committer=b'committer <committer@example.com>',
258
author=b'author <author@example.com>')
381
committer=b'committer <committer@example.com>',
382
author=b'author <author@example.com>')
260
384
remote = ControlDir.open(self.remote_url)
261
385
self.make_controldir('local', format=self._from_format)
339
465
def test_remove_branch(self):
340
466
c1 = self.remote_real.do_commit(
342
committer=b'committer <committer@example.com>',
343
author=b'author <author@example.com>')
468
committer=b'committer <committer@example.com>',
469
author=b'author <author@example.com>')
344
470
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')
471
message=b'another commit',
472
committer=b'committer <committer@example.com>',
473
author=b'author <author@example.com>',
474
ref=b'refs/heads/blah')
350
476
remote = ControlDir.open(self.remote_url)
351
477
remote.destroy_branch(name='blah')
352
478
self.assertEqual(
353
self.remote_real.get_refs(),
354
{b'refs/heads/master': self.remote_real.head(),
355
b'HEAD': self.remote_real.head(),
479
self.remote_real.get_refs(),
480
{b'refs/heads/master': self.remote_real.head(),
481
b'HEAD': self.remote_real.head(),
358
484
def test_list_branches(self):
359
485
c1 = self.remote_real.do_commit(
361
committer=b'committer <committer@example.com>',
362
author=b'author <author@example.com>')
487
committer=b'committer <committer@example.com>',
488
author=b'author <author@example.com>')
363
489
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')
490
message=b'another commit',
491
committer=b'committer <committer@example.com>',
492
author=b'author <author@example.com>',
493
ref=b'refs/heads/blah')
369
495
remote = ControlDir.open(self.remote_url)
370
496
self.assertEqual(
371
set(['master', 'blah', 'master']),
372
set([b.name for b in remote.list_branches()]))
497
set(['master', 'blah', 'master']),
498
set([b.name for b in remote.list_branches()]))
374
500
def test_get_branches(self):
375
501
c1 = self.remote_real.do_commit(
377
committer=b'committer <committer@example.com>',
378
author=b'author <author@example.com>')
503
committer=b'committer <committer@example.com>',
504
author=b'author <author@example.com>')
379
505
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')
506
message=b'another commit',
507
committer=b'committer <committer@example.com>',
508
author=b'author <author@example.com>',
509
ref=b'refs/heads/blah')
385
511
remote = ControlDir.open(self.remote_url)
386
512
self.assertEqual(
387
{'': 'master', 'blah': 'blah', 'master': 'master'},
388
{n: b.name for (n, b) in remote.get_branches().items()})
513
{'': 'master', 'blah': 'blah', 'master': 'master'},
514
{n: b.name for (n, b) in remote.get_branches().items()})
390
516
def test_remove_tag(self):
391
517
c1 = self.remote_real.do_commit(
393
committer=b'committer <committer@example.com>',
394
author=b'author <author@example.com>')
519
committer=b'committer <committer@example.com>',
520
author=b'author <author@example.com>')
395
521
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')
522
message=b'another commit',
523
committer=b'committer <committer@example.com>',
524
author=b'author <author@example.com>',
525
ref=b'refs/tags/blah')
401
527
remote = ControlDir.open(self.remote_url)
402
528
remote_branch = remote.open_branch()
403
529
remote_branch.tags.delete_tag('blah')
404
530
self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
405
531
self.assertEqual(
406
self.remote_real.get_refs(),
407
{b'refs/heads/master': self.remote_real.head(),
408
b'HEAD': self.remote_real.head(),
532
self.remote_real.get_refs(),
533
{b'refs/heads/master': self.remote_real.head(),
534
b'HEAD': self.remote_real.head(),
411
537
def test_set_tag(self):
412
538
c1 = self.remote_real.do_commit(
414
committer=b'committer <committer@example.com>',
415
author=b'author <author@example.com>')
540
committer=b'committer <committer@example.com>',
541
author=b'author <author@example.com>')
416
542
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>')
543
message=b'another commit',
544
committer=b'committer <committer@example.com>',
545
author=b'author <author@example.com>')
421
547
remote = ControlDir.open(self.remote_url)
422
548
remote.open_branch().tags.set_tag(
423
549
b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
424
550
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(),
551
self.remote_real.get_refs(),
552
{b'refs/heads/master': self.remote_real.head(),
553
b'refs/tags/blah': c1,
554
b'HEAD': self.remote_real.head(),
431
557
def test_annotated_tag(self):
432
558
c1 = self.remote_real.do_commit(
434
committer=b'committer <committer@example.com>',
435
author=b'author <author@example.com>')
560
committer=b'committer <committer@example.com>',
561
author=b'author <author@example.com>')
436
562
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>')
563
message=b'another commit',
564
committer=b'committer <committer@example.com>',
565
author=b'author <author@example.com>')
441
567
porcelain.tag_create(
444
author=b'author <author@example.com>',
446
tag_time=int(time.time()),
449
message=b"Annotated tag")
570
author=b'author <author@example.com>',
572
tag_time=int(time.time()),
575
message=b"Annotated tag")
451
577
remote = ControlDir.open(self.remote_url)
452
578
remote_branch = remote.open_branch()
454
580
'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
455
581
remote_branch.tags.get_tag_dict())
457
def tetst_get_branch_reference(self):
583
def test_get_branch_reference(self):
458
584
c1 = self.remote_real.do_commit(
460
committer=b'committer <committer@example.com>',
461
author=b'author <author@example.com>')
586
committer=b'committer <committer@example.com>',
587
author=b'author <author@example.com>')
462
588
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>')
589
message=b'another commit',
590
committer=b'committer <committer@example.com>',
591
author=b'author <author@example.com>')
467
593
remote = ControlDir.open(self.remote_url)
468
594
self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))
469
595
self.assertEqual(None, remote.get_branch_reference('master'))
597
def test_get_branch_nick(self):
598
c1 = self.remote_real.do_commit(
600
committer=b'committer <committer@example.com>',
601
author=b'author <author@example.com>')
602
remote = ControlDir.open(self.remote_url)
603
self.assertEqual('master', remote.open_branch().nick)