Skip to content

Commit

Permalink
Tools: size_compare_branches: allow use in detached-head state
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Apr 15, 2023
1 parent 3b2e92c commit 8c92787
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Tools/scripts/size_compare_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self,
extra_hwdef_branch=[],
extra_hwdef_master=[]):
if branch is None:
branch = self.find_current_git_branch()
branch = self.find_current_git_branch_or_sha1()

self.master_branch = master_branch
self.branch = branch
Expand Down Expand Up @@ -220,8 +220,16 @@ def run_program(self, prefix, cmd_list, show_output=True, env=None):
returncode, cmd_list)
return output

def find_current_git_branch(self):
output = self.run_git(["symbolic-ref", "--short", "HEAD"])
def find_current_git_branch_or_sha1(self):
try:
output = self.run_git(["symbolic-ref", "--short", "HEAD"])
output = output.strip()
return output
except subprocess.CalledProcessError:
pass

# probably in a detached-head state. Get a sha1 instead:
output = self.run_git(["rev-parse", "--short", "HEAD"])
output = output.strip()
return output

Expand Down

0 comments on commit 8c92787

Please sign in to comment.