Fix get_git_version on OS X

Apparently Apple's `git --version` provides different output than
Linux's. Improve the version parsing by splitting on all whitespace and
taking the exact element that should be the version out of that rather
than relying on the version we want being a suffix of the command
output.

Story: 2010002
Change-Id: I40356ee81b98c1210de348e51335a20be48bec1d
This commit is contained in:
Clark Boylan 2022-04-19 08:44:45 -07:00
parent 82a2c8df2e
commit b39c812e01
1 changed files with 7 additions and 1 deletions

View File

@ -229,7 +229,13 @@ def get_git_version():
output = run_command("git version")
if "git version" in output:
try:
v = output.rsplit(None, 1)[1]
# Git version on Linux is of the form:
# git version 2.35.3
# But on OS X we get:
# git version 2.20.1 (Apple Git-117)
# Keep this as simple as possible by splitting on whitespace
# and then selecting the 3rd element which should be the version.
v = output.split()[2]
LOCAL_GIT_VERSION = tuple(map(int, v.split('.')[:3]))
except Exception:
printwrap("Could not determine git version!")