File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,9 @@ def get_branch_name() -> str:
22
22
:returns: A `str` describing the current branch name.
23
23
"""
24
24
try :
25
- commands = ['git' , 'rev-parse' , '--abbrev-ref' , 'HEAD' ]
26
- branch_name = cmd_output (commands )
25
+ # Git 2.22 and above supports `git branch --show-current`
26
+ commands = ['git' , 'branch' , '--show-current' ]
27
+ branch_name = cmd_output (commands ) or "HEAD"
27
28
except CalledProcessError :
28
29
branch_name = ''
29
30
return branch_name .strip ()
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def test_get_branch_name(self, mocker):
25
25
retval = get_branch_name ()
26
26
assert m_cmd_output .call_count == 1
27
27
assert m_cmd_output .call_args [0 ][0 ] == [
28
- "git" , "rev-parse " , "--abbrev-ref" , "HEAD "
28
+ "git" , "branch " , "--show-current "
29
29
]
30
30
assert retval == "fake_branch_name"
31
31
@@ -45,7 +45,7 @@ def test_get_branch_name_with_exception(self, mocker):
45
45
retval = get_branch_name ()
46
46
assert m_cmd_output .call_count == 1
47
47
assert m_cmd_output .call_args [0 ][0 ] == [
48
- "git" , "rev-parse " , "--abbrev-ref" , "HEAD "
48
+ "git" , "branch " , "--show-current "
49
49
]
50
50
assert retval == ""
51
51
You can’t perform that action at this time.
0 commit comments