@@ -44,7 +44,7 @@ async def test_get_current_branch_success():
44
44
45
45
# Then
46
46
mock_execute .assert_called_once_with (
47
- ["git" , "symbolic-ref" , "HEAD" ], cwd = os .path .join ("/bin" , "test_curr_path" )
47
+ ["git" , "symbolic-ref" , "--short" , " HEAD" ], cwd = os .path .join ("/bin" , "test_curr_path" )
48
48
)
49
49
assert "feature-foo" == actual_response
50
50
@@ -337,11 +337,11 @@ async def test_get_current_branch_failure():
337
337
338
338
# Then
339
339
mock_execute .assert_called_once_with (
340
- ["git" , "symbolic-ref" , "HEAD" ], cwd = os .path .join ("/bin" , "test_curr_path" )
340
+ ["git" , "symbolic-ref" , "--short" , " HEAD" ], cwd = os .path .join ("/bin" , "test_curr_path" )
341
341
)
342
342
assert (
343
343
"Error [fatal: Not a git repository (or any of the parent directories): .git] "
344
- "occurred while executing [git symbolic-ref HEAD] command to get current branch."
344
+ "occurred while executing [git symbolic-ref --short HEAD] command to get current branch."
345
345
== str (error .value )
346
346
)
347
347
@@ -403,29 +403,42 @@ async def test_get_current_branch_detached_failure():
403
403
404
404
@pytest .mark .asyncio
405
405
@pytest .mark .parametrize (
406
- "branch,upstream" ,
406
+ "branch,upstream,remotename " ,
407
407
[
408
- ("feature-foo" , "origin/master " ),
409
- ("master" , "origin/ master" ),
410
- ("feature- bar" , "feature-foo" ),
408
+ ("feature-foo" , "master" , " origin/withslash " ),
409
+ ("master" , "master" , "origin " ),
410
+ ("feature/ bar" , "feature-foo" , " " ),
411
411
],
412
412
)
413
- async def test_get_upstream_branch_success (branch , upstream ):
413
+ async def test_get_upstream_branch_success (branch , upstream , remotename ):
414
414
with patch ("jupyterlab_git.git.execute" ) as mock_execute :
415
415
# Given
416
- mock_execute .return_value = maybe_future ((0 , upstream , "" ))
416
+ mock_execute .side_effect = [
417
+ maybe_future ((0 , remotename + '/' + upstream , '' )),
418
+ maybe_future ((0 , remotename , '' ))
419
+ ]
417
420
418
421
# When
419
422
actual_response = await Git (FakeContentManager ("/bin" )).get_upstream_branch (
420
423
current_path = "test_curr_path" , branch_name = branch
421
424
)
422
425
423
426
# Then
424
- mock_execute .assert_called_once_with (
425
- ["git" , "rev-parse" , "--abbrev-ref" , "{}@{{upstream}}" .format (branch )],
426
- cwd = os .path .join ("/bin" , "test_curr_path" ),
427
+ mock_execute .assert_has_calls (
428
+ [
429
+ call (
430
+ ["git" , "rev-parse" , "--abbrev-ref" , "{}@{{upstream}}" .format (branch )],
431
+ cwd = os .path .join ("/bin" , "test_curr_path" ),
432
+ ),
433
+ call (
434
+ ['git' , 'config' , '--local' , f'branch.{ branch } .remote' ],
435
+ cwd = '/bin/test_curr_path' ,
436
+ ),
437
+
438
+ ],
439
+ any_order = False ,
427
440
)
428
- assert upstream == actual_response
441
+ assert { 'code' : 0 , 'remote_branch' : upstream , 'remote_short_name' : remotename } == actual_response
429
442
430
443
431
444
@pytest .mark .asyncio
@@ -454,17 +467,12 @@ async def test_get_upstream_branch_failure(outputs, message):
454
467
mock_execute .return_value = maybe_future (outputs )
455
468
456
469
# When
457
- if message :
458
- with pytest .raises (Exception ) as error :
459
- await Git (FakeContentManager ("/bin" )).get_upstream_branch (
460
- current_path = "test_curr_path" , branch_name = "blah"
461
- )
462
- assert message == str (error .value )
463
- else :
464
- response = await Git (FakeContentManager ("/bin" )).get_upstream_branch (
465
- current_path = "test_curr_path" , branch_name = "blah"
466
- )
467
- assert response is None
470
+ response = await Git (FakeContentManager ("/bin" )).get_upstream_branch (
471
+ current_path = "test_curr_path" , branch_name = "blah"
472
+ )
473
+ expected = {'code' : 128 , 'command' : 'git rev-parse --abbrev-ref blah@{upstream}' , 'message' : outputs [2 ]}
474
+
475
+ assert response == expected
468
476
469
477
# Then
470
478
mock_execute .assert_has_calls (
@@ -807,7 +815,7 @@ async def test_branch_success_detached_head():
807
815
),
808
816
# call to get current branch
809
817
call (
810
- ["git" , "symbolic-ref" , "HEAD" ],
818
+ ["git" , "symbolic-ref" , "--short" , " HEAD" ],
811
819
cwd = os .path .join ("/bin" , "test_curr_path" ),
812
820
),
813
821
# call to get current branch name given a detached head
0 commit comments