@@ -890,12 +890,12 @@ async def get_current_branch(self, current_path):
890
890
to the `branch` command to get the name.
891
891
See https://git-blame.blogspot.com/2013/06/checking-current-branch-programatically.html
892
892
"""
893
- command = ["git" , "symbolic-ref" , "HEAD" ]
893
+ command = ["git" , "symbolic-ref" , "--short" , " HEAD" ]
894
894
code , output , error = await execute (
895
895
command , cwd = os .path .join (self .root_dir , current_path )
896
896
)
897
897
if code == 0 :
898
- return output .split ( "/" )[ - 1 ]. strip ()
898
+ return output .strip ()
899
899
elif "not a symbolic ref" in error .lower ():
900
900
current_branch = await self ._get_current_branch_detached (current_path )
901
901
return current_branch
@@ -939,18 +939,22 @@ async def get_upstream_branch(self, current_path, branch_name):
939
939
code , output , error = await execute (
940
940
command , cwd = os .path .join (self .root_dir , current_path )
941
941
)
942
- if code == 0 :
943
- return output .strip ()
944
- elif "fatal: no upstream configured for branch" in error .lower ():
945
- return None
946
- elif "unknown revision or path not in the working tree" in error .lower ():
947
- return None
948
- else :
949
- raise Exception (
950
- "Error [{}] occurred while executing [{}] command to get upstream branch." .format (
951
- error , " " .join (command )
952
- )
953
- )
942
+ if code != 0 :
943
+ return {"code" : code , "command" : " " .join (cmd ), "message" : error }
944
+ rev_parse_output = output .strip ()
945
+
946
+ command = ["git" , "config" , "--local" , f"branch.{ branch_name } .remote" ]
947
+ code , output , error = await execute (
948
+ command , cwd = os .path .join (self .root_dir , current_path )
949
+ )
950
+ if code != 0 :
951
+ return {"code" : code , "command" : " " .join (cmd ), "message" : error }
952
+
953
+ remote_name = output .strip ()
954
+ remote_branch = rev_parse_output .strip ().lstrip (remote_name + "/" )
955
+ return {"code" : code , "remote_short_name" : remote_name , "remote_branch" : remote_branch }
956
+
957
+
954
958
955
959
async def _get_tag (self , current_path , commit_sha ):
956
960
"""Execute 'git describe commit_sha' to get
0 commit comments