From b39c812e01f096dec57fcfe07068c1fa83da6a86 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 19 Apr 2022 08:44:45 -0700 Subject: 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 --- git_review/cmd.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/git_review/cmd.py b/git_review/cmd.py index ad4c300..f3df728 100644 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -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!") -- cgit v1.2.1