/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tests/test_remote.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
 
55
55
    def test_simple(self):
56
56
        self.assertEqual(("foo", None, None, "/bar"),
57
 
            split_git_url("git://foo/bar"))
 
57
                         split_git_url("git://foo/bar"))
58
58
 
59
59
    def test_port(self):
60
60
        self.assertEqual(("foo", 343, None, "/bar"),
61
 
            split_git_url("git://foo:343/bar"))
 
61
                         split_git_url("git://foo:343/bar"))
62
62
 
63
63
    def test_username(self):
64
64
        self.assertEqual(("foo", None, "la", "/bar"),
65
 
            split_git_url("git://la@foo/bar"))
 
65
                         split_git_url("git://la@foo/bar"))
66
66
 
67
67
    def test_nopath(self):
68
68
        self.assertEqual(("foo", None, None, "/"),
69
 
            split_git_url("git://foo/"))
 
69
                         split_git_url("git://foo/"))
70
70
 
71
71
    def test_slashpath(self):
72
72
        self.assertEqual(("foo", None, None, "//bar"),
73
 
            split_git_url("git://foo//bar"))
 
73
                         split_git_url("git://foo//bar"))
74
74
 
75
75
    def test_homedir(self):
76
76
        self.assertEqual(("foo", None, None, "~bar"),
77
 
            split_git_url("git://foo/~bar"))
 
77
                         split_git_url("git://foo/~bar"))
78
78
 
79
79
 
80
80
class ParseGitErrorTests(TestCase):
96
96
        self.assertIsInstance(e, NotBranchError)
97
97
 
98
98
    def test_notbrancherror_normal(self):
99
 
        e = parse_git_error("url", "fatal: '/srv/git/lintian-brush' does not appear to be a git repository")
 
99
        e = parse_git_error(
 
100
            "url", "fatal: '/srv/git/lintian-brush' does not appear to be a git repository")
100
101
        self.assertIsInstance(e, NotBranchError)
101
102
 
102
103
    def test_head_update(self):
131
132
        self.format = RemoteGitBranchFormat()
132
133
 
133
134
    def test_get_format_description(self):
134
 
        self.assertEqual("Remote Git Branch", self.format.get_format_description())
 
135
        self.assertEqual("Remote Git Branch",
 
136
                         self.format.get_format_description())
135
137
 
136
138
    def test_get_network_name(self):
137
139
        self.assertEqual(b"git", self.format.network_name())
185
187
 
186
188
    def test_sprout_simple(self):
187
189
        self.remote_real.do_commit(
188
 
                message=b'message',
189
 
                committer=b'committer <committer@example.com>',
190
 
                author=b'author <author@example.com>')
 
190
            message=b'message',
 
191
            committer=b'committer <committer@example.com>',
 
192
            author=b'author <author@example.com>')
191
193
 
192
194
        remote = ControlDir.open(self.remote_url)
193
195
        self.make_controldir('local', format=self._to_format)
194
196
        local = remote.sprout('local')
195
197
        self.assertEqual(
196
 
                default_mapping.revision_id_foreign_to_bzr(self.remote_real.head()),
197
 
                local.open_branch().last_revision())
 
198
            default_mapping.revision_id_foreign_to_bzr(
 
199
                self.remote_real.head()),
 
200
            local.open_branch().last_revision())
198
201
 
199
202
    def test_sprout_with_tags(self):
200
203
        c1 = self.remote_real.do_commit(
201
 
                message=b'message',
202
 
                committer=b'committer <committer@example.com>',
203
 
                author=b'author <author@example.com>')
 
204
            message=b'message',
 
205
            committer=b'committer <committer@example.com>',
 
206
            author=b'author <author@example.com>')
204
207
        c2 = self.remote_real.do_commit(
205
 
                message=b'another commit',
206
 
                committer=b'committer <committer@example.com>',
207
 
                author=b'author <author@example.com>',
208
 
                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')
209
212
        self.remote_real.refs[b'refs/tags/blah'] = self.remote_real.head()
210
213
 
211
214
        remote = ControlDir.open(self.remote_url)
213
216
        local = remote.sprout('local')
214
217
        local_branch = local.open_branch()
215
218
        self.assertEqual(
216
 
                default_mapping.revision_id_foreign_to_bzr(c1),
217
 
                local_branch.last_revision())
 
219
            default_mapping.revision_id_foreign_to_bzr(c1),
 
220
            local_branch.last_revision())
218
221
        self.assertEqual(
219
 
                {'blah': local_branch.last_revision(),
220
 
                 'another': default_mapping.revision_id_foreign_to_bzr(c2)},
221
 
                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())
222
225
 
223
226
    def test_sprout_with_annotated_tag(self):
224
227
        c1 = self.remote_real.do_commit(
225
 
                message=b'message',
226
 
                committer=b'committer <committer@example.com>',
227
 
                author=b'author <author@example.com>')
 
228
            message=b'message',
 
229
            committer=b'committer <committer@example.com>',
 
230
            author=b'author <author@example.com>')
228
231
        c2 = self.remote_real.do_commit(
229
 
                message=b'another commit',
230
 
                committer=b'committer <committer@example.com>',
231
 
                author=b'author <author@example.com>',
232
 
                ref=b'refs/heads/another')
 
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')
233
236
        porcelain.tag_create(
234
 
                self.remote_real,
235
 
                tag=b"blah",
236
 
                author=b'author <author@example.com>',
237
 
                objectish=c2,
238
 
                tag_time=int(time.time()),
239
 
                tag_timezone=0,
240
 
                annotated=True,
241
 
                message=b"Annotated tag")
 
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")
242
245
 
243
246
        remote = ControlDir.open(self.remote_url)
244
247
        self.make_controldir('local', format=self._to_format)
245
 
        local = remote.sprout('local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
 
248
        local = remote.sprout(
 
249
            'local', revision_id=default_mapping.revision_id_foreign_to_bzr(c1))
246
250
        local_branch = local.open_branch()
247
251
        self.assertEqual(
248
 
                default_mapping.revision_id_foreign_to_bzr(c1),
249
 
                local_branch.last_revision())
 
252
            default_mapping.revision_id_foreign_to_bzr(c1),
 
253
            local_branch.last_revision())
250
254
        self.assertEqual(
251
255
                {'blah': default_mapping.revision_id_foreign_to_bzr(c2)},
252
256
                local_branch.tags.get_tag_dict())
289
293
    _to_format = '2a'
290
294
 
291
295
 
292
 
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase,TestCaseWithTransport):
 
296
class FetchFromRemoteToGitTests(FetchFromRemoteTestBase, TestCaseWithTransport):
293
297
 
294
298
    _to_format = 'git'
295
299
 
316
320
        if self._from_format == 'git':
317
321
            result = remote.push_branch(wt.branch, name='newbranch')
318
322
        else:
319
 
            result = remote.push_branch(wt.branch, lossy=True, name='newbranch')
 
323
            result = remote.push_branch(
 
324
                wt.branch, lossy=True, name='newbranch')
320
325
 
321
326
        self.assertEqual(0, result.old_revno)
322
327
        if self._from_format == 'git':
327
332
        result.report(BytesIO())
328
333
 
329
334
        self.assertEqual(
330
 
                {b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
331
 
                },
332
 
                self.remote_real.get_refs())
 
335
            {b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
 
336
             },
 
337
            self.remote_real.get_refs())
333
338
 
334
339
    def test_push(self):
335
340
        c1 = self.remote_real.do_commit(
336
 
                message=b'message',
337
 
                committer=b'committer <committer@example.com>',
338
 
                author=b'author <author@example.com>')
 
341
            message=b'message',
 
342
            committer=b'committer <committer@example.com>',
 
343
            author=b'author <author@example.com>')
339
344
 
340
345
        remote = ControlDir.open(self.remote_url)
341
346
        self.make_controldir('local', format=self._from_format)
350
355
        if self._from_format == 'git':
351
356
            result = wt.branch.push(remote.create_branch('newbranch'))
352
357
        else:
353
 
            result = wt.branch.push(remote.create_branch('newbranch'), lossy=True)
 
358
            result = wt.branch.push(
 
359
                remote.create_branch('newbranch'), lossy=True)
354
360
 
355
361
        self.assertEqual(0, result.old_revno)
356
362
        self.assertEqual(2, result.new_revno)
358
364
        result.report(BytesIO())
359
365
 
360
366
        self.assertEqual(
361
 
                {b'refs/heads/master': self.remote_real.head(),
362
 
                 b'HEAD': self.remote_real.head(),
363
 
                 b'refs/heads/newbranch': self.remote_real.refs[b'refs/heads/newbranch'],
364
 
                 b'refs/tags/sometag': self.remote_real.refs[b'refs/heads/newbranch'],
365
 
                },
366
 
                self.remote_real.get_refs())
 
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())
367
373
 
368
374
    def test_push_diverged(self):
369
375
        c1 = self.remote_real.do_commit(
370
 
                message=b'message',
371
 
                committer=b'committer <committer@example.com>',
372
 
                author=b'author <author@example.com>',
373
 
                ref=b'refs/heads/newbranch')
 
376
            message=b'message',
 
377
            committer=b'committer <committer@example.com>',
 
378
            author=b'author <author@example.com>',
 
379
            ref=b'refs/heads/newbranch')
374
380
 
375
381
        remote = ControlDir.open(self.remote_url)
376
382
        wt = self.make_branch_and_tree('local', format=self._from_format)
382
388
        if self._from_format == 'git':
383
389
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch)
384
390
        else:
385
 
            self.assertRaises(DivergedBranches, wt.branch.push, newbranch, lossy=True)
 
391
            self.assertRaises(DivergedBranches, wt.branch.push,
 
392
                              newbranch, lossy=True)
386
393
 
387
394
        self.assertEqual(
388
 
                {b'refs/heads/newbranch': c1 },
389
 
                self.remote_real.get_refs())
 
395
            {b'refs/heads/newbranch': c1},
 
396
            self.remote_real.get_refs())
390
397
 
391
398
        if self._from_format == 'git':
392
399
            wt.branch.push(newbranch, overwrite=True)
396
403
        self.assertNotEqual(c1, self.remote_real.refs[b'refs/heads/newbranch'])
397
404
 
398
405
 
399
 
class PushToRemoteFromBzrTests(PushToRemoteBase,TestCaseWithTransport):
 
406
class PushToRemoteFromBzrTests(PushToRemoteBase, TestCaseWithTransport):
400
407
 
401
408
    _from_format = '2a'
402
409
 
403
410
 
404
 
class PushToRemoteFromGitTests(PushToRemoteBase,TestCaseWithTransport):
 
411
class PushToRemoteFromGitTests(PushToRemoteBase, TestCaseWithTransport):
405
412
 
406
413
    _from_format = 'git'
407
414
 
418
425
 
419
426
    def test_remove_branch(self):
420
427
        c1 = self.remote_real.do_commit(
421
 
                message=b'message',
422
 
                committer=b'committer <committer@example.com>',
423
 
                author=b'author <author@example.com>')
 
428
            message=b'message',
 
429
            committer=b'committer <committer@example.com>',
 
430
            author=b'author <author@example.com>')
424
431
        c2 = self.remote_real.do_commit(
425
 
                message=b'another commit',
426
 
                committer=b'committer <committer@example.com>',
427
 
                author=b'author <author@example.com>',
428
 
                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')
429
436
 
430
437
        remote = ControlDir.open(self.remote_url)
431
438
        remote.destroy_branch(name='blah')
432
439
        self.assertEqual(
433
 
                self.remote_real.get_refs(),
434
 
                {b'refs/heads/master': self.remote_real.head(),
435
 
                 b'HEAD': self.remote_real.head(),
436
 
                })
 
440
            self.remote_real.get_refs(),
 
441
            {b'refs/heads/master': self.remote_real.head(),
 
442
             b'HEAD': self.remote_real.head(),
 
443
             })
437
444
 
438
445
    def test_list_branches(self):
439
446
        c1 = self.remote_real.do_commit(
440
 
                message=b'message',
441
 
                committer=b'committer <committer@example.com>',
442
 
                author=b'author <author@example.com>')
 
447
            message=b'message',
 
448
            committer=b'committer <committer@example.com>',
 
449
            author=b'author <author@example.com>')
443
450
        c2 = self.remote_real.do_commit(
444
 
                message=b'another commit',
445
 
                committer=b'committer <committer@example.com>',
446
 
                author=b'author <author@example.com>',
447
 
                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')
448
455
 
449
456
        remote = ControlDir.open(self.remote_url)
450
457
        self.assertEqual(
451
 
                set(['master', 'blah', 'master']),
452
 
                set([b.name for b in remote.list_branches()]))
 
458
            set(['master', 'blah', 'master']),
 
459
            set([b.name for b in remote.list_branches()]))
453
460
 
454
461
    def test_get_branches(self):
455
462
        c1 = self.remote_real.do_commit(
456
 
                message=b'message',
457
 
                committer=b'committer <committer@example.com>',
458
 
                author=b'author <author@example.com>')
 
463
            message=b'message',
 
464
            committer=b'committer <committer@example.com>',
 
465
            author=b'author <author@example.com>')
459
466
        c2 = self.remote_real.do_commit(
460
 
                message=b'another commit',
461
 
                committer=b'committer <committer@example.com>',
462
 
                author=b'author <author@example.com>',
463
 
                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')
464
471
 
465
472
        remote = ControlDir.open(self.remote_url)
466
473
        self.assertEqual(
467
 
                {'': 'master', 'blah': 'blah', 'master': 'master'},
468
 
                {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()})
469
476
 
470
477
    def test_remove_tag(self):
471
478
        c1 = self.remote_real.do_commit(
472
 
                message=b'message',
473
 
                committer=b'committer <committer@example.com>',
474
 
                author=b'author <author@example.com>')
 
479
            message=b'message',
 
480
            committer=b'committer <committer@example.com>',
 
481
            author=b'author <author@example.com>')
475
482
        c2 = self.remote_real.do_commit(
476
 
                message=b'another commit',
477
 
                committer=b'committer <committer@example.com>',
478
 
                author=b'author <author@example.com>',
479
 
                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')
480
487
 
481
488
        remote = ControlDir.open(self.remote_url)
482
489
        remote_branch = remote.open_branch()
483
490
        remote_branch.tags.delete_tag('blah')
484
491
        self.assertRaises(NoSuchTag, remote_branch.tags.delete_tag, 'blah')
485
492
        self.assertEqual(
486
 
                self.remote_real.get_refs(),
487
 
                {b'refs/heads/master': self.remote_real.head(),
488
 
                 b'HEAD': self.remote_real.head(),
489
 
                })
 
493
            self.remote_real.get_refs(),
 
494
            {b'refs/heads/master': self.remote_real.head(),
 
495
             b'HEAD': self.remote_real.head(),
 
496
             })
490
497
 
491
498
    def test_set_tag(self):
492
499
        c1 = self.remote_real.do_commit(
493
 
                message=b'message',
494
 
                committer=b'committer <committer@example.com>',
495
 
                author=b'author <author@example.com>')
 
500
            message=b'message',
 
501
            committer=b'committer <committer@example.com>',
 
502
            author=b'author <author@example.com>')
496
503
        c2 = self.remote_real.do_commit(
497
 
                message=b'another commit',
498
 
                committer=b'committer <committer@example.com>',
499
 
                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>')
500
507
 
501
508
        remote = ControlDir.open(self.remote_url)
502
509
        remote.open_branch().tags.set_tag(
503
510
            b'blah', default_mapping.revision_id_foreign_to_bzr(c1))
504
511
        self.assertEqual(
505
 
                self.remote_real.get_refs(),
506
 
                {b'refs/heads/master': self.remote_real.head(),
507
 
                 b'refs/tags/blah': c1,
508
 
                 b'HEAD': self.remote_real.head(),
509
 
                })
 
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
             })
510
517
 
511
518
    def test_annotated_tag(self):
512
519
        c1 = self.remote_real.do_commit(
513
 
                message=b'message',
514
 
                committer=b'committer <committer@example.com>',
515
 
                author=b'author <author@example.com>')
 
520
            message=b'message',
 
521
            committer=b'committer <committer@example.com>',
 
522
            author=b'author <author@example.com>')
516
523
        c2 = self.remote_real.do_commit(
517
 
                message=b'another commit',
518
 
                committer=b'committer <committer@example.com>',
519
 
                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>')
520
527
 
521
528
        porcelain.tag_create(
522
 
                self.remote_real,
523
 
                tag=b"blah",
524
 
                author=b'author <author@example.com>',
525
 
                objectish=c2,
526
 
                tag_time=int(time.time()),
527
 
                tag_timezone=0,
528
 
                annotated=True,
529
 
                message=b"Annotated tag")
 
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")
530
537
 
531
538
        remote = ControlDir.open(self.remote_url)
532
539
        remote_branch = remote.open_branch()
536
543
 
537
544
    def test_get_branch_reference(self):
538
545
        c1 = self.remote_real.do_commit(
539
 
                message=b'message',
540
 
                committer=b'committer <committer@example.com>',
541
 
                author=b'author <author@example.com>')
 
546
            message=b'message',
 
547
            committer=b'committer <committer@example.com>',
 
548
            author=b'author <author@example.com>')
542
549
        c2 = self.remote_real.do_commit(
543
 
                message=b'another commit',
544
 
                committer=b'committer <committer@example.com>',
545
 
                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>')
546
553
 
547
554
        remote = ControlDir.open(self.remote_url)
548
555
        self.assertEqual(b'refs/heads/master', remote.get_branch_reference(''))