Skip to content

Commit

Permalink
CP: Use git rev-parse to get last commit sha (#6366) (#6375)
Browse files Browse the repository at this point in the history
Do not use `git describe`, it is using tags which might be out of date
and unrelated to the current build and version.

(cherry picked from commit aaab2a7)
  • Loading branch information
hekota authored Feb 29, 2024
1 parent 99c7810 commit c9660a8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions utils/version/gen_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@ def get_output_of(cmd):
output = subprocess.check_output(cmd, cwd=enlistment_root)
return output.decode('ASCII').strip()

def is_dirty():
diff = get_output_of(["git", "diff", "HEAD", "--shortstat"])
return len(diff.strip()) != 0

def get_last_commit_sha():
try:
return get_output_of([ "git", "describe", "--always", "--dirty" ])
sha = get_output_of(["git", "rev-parse", "--short", "HEAD"])
if is_dirty():
sha += "-dirty"
return sha
except subprocess.CalledProcessError:
return "00000000"

def get_current_branch():
try:
return get_output_of([ "git", "rev-parse", "--abbrev-ref", "HEAD" ])
return get_output_of(["git", "rev-parse", "--abbrev-ref", "HEAD"])
except subprocess.CalledProcessError:
return "private"

def get_commit_count(sha):
try:
return get_output_of([ "git", "rev-list", "--count", sha ])
return get_output_of(["git", "rev-list", "--count", sha])
except subprocess.CalledProcessError:
return 0

Expand Down

0 comments on commit c9660a8

Please sign in to comment.