@@ -252,8 +252,8 @@ def test_fetch_depth_one(testrepo):
252
252
253
253
def test_transfer_progress (emptyrepo ):
254
254
class MyCallbacks (pygit2 .RemoteCallbacks ):
255
- def transfer_progress (emptyrepo , stats ):
256
- emptyrepo .tp = stats
255
+ def transfer_progress (self , stats ):
256
+ self .tp = stats
257
257
258
258
callbacks = MyCallbacks ()
259
259
remote = emptyrepo .remotes [0 ]
@@ -362,6 +362,59 @@ def test_push_when_up_to_date_succeeds(origin, clone, remote):
362
362
assert origin_tip == clone_tip
363
363
364
364
365
+ def test_push_transfer_progress (origin , clone , remote ):
366
+ tip = clone [clone .head .target ]
367
+ new_tip_id = clone .create_commit (
368
+ 'refs/heads/master' ,
369
+ tip .author ,
370
+ tip .author ,
371
+ 'empty commit' ,
372
+ tip .tree .id ,
373
+ [tip .id ],
374
+ )
375
+
376
+ # NOTE: We're currently not testing bytes_pushed due to a bug in libgit2
377
+ # 1.9.0: it passes a junk value for bytes_pushed when pushing to a remote
378
+ # on the local filesystem, as is the case in this unit test. (When pushing
379
+ # to a remote over the network, the value is correct.)
380
+ class MyCallbacks (pygit2 .RemoteCallbacks ):
381
+ def push_transfer_progress (self , objects_pushed , total_objects , bytes_pushed ):
382
+ self .objects_pushed = objects_pushed
383
+ self .total_objects = total_objects
384
+
385
+ assert origin .branches ['master' ].target == tip .id
386
+
387
+ callbacks = MyCallbacks ()
388
+ remote .push (['refs/heads/master' ], callbacks = callbacks )
389
+ assert callbacks .objects_pushed == 1
390
+ assert callbacks .total_objects == 1
391
+ assert origin .branches ['master' ].target == new_tip_id
392
+
393
+
394
+ def test_push_interrupted_from_callbacks (origin , clone , remote ):
395
+ tip = clone [clone .head .target ]
396
+ clone .create_commit (
397
+ 'refs/heads/master' ,
398
+ tip .author ,
399
+ tip .author ,
400
+ 'empty commit' ,
401
+ tip .tree .id ,
402
+ [tip .id ],
403
+ )
404
+
405
+ class MyCallbacks (pygit2 .RemoteCallbacks ):
406
+ def push_transfer_progress (self , objects_pushed , total_objects , bytes_pushed ):
407
+ raise InterruptedError ('retreat! retreat!' )
408
+
409
+ assert origin .branches ['master' ].target == tip .id
410
+
411
+ callbacks = MyCallbacks ()
412
+ with pytest .raises (InterruptedError , match = 'retreat! retreat!' ):
413
+ remote .push (['refs/heads/master' ], callbacks = callbacks )
414
+
415
+ assert origin .branches ['master' ].target == tip .id
416
+
417
+
365
418
def test_push_non_fast_forward_commits_to_remote_fails (origin , clone , remote ):
366
419
tip = origin [origin .head .target ]
367
420
origin .create_commit (
0 commit comments