diff options
author | Clark Boylan <clark.boylan@gmail.com> | 2022-04-19 08:44:45 -0700 |
---|---|---|
committer | Clark Boylan <clark.boylan@gmail.com> | 2022-04-19 08:44:45 -0700 |
commit | b39c812e01f096dec57fcfe07068c1fa83da6a86 (patch) | |
tree | 5d0ac25150c5e8fec5a4c83c9f54c162baa5cbfa | |
parent | 82a2c8df2e6deada5770d1ea48e5d0ce0eaeab36 (diff) | |
download | git-review-b39c812e01f096dec57fcfe07068c1fa83da6a86.tar.gz |
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
-rw-r--r-- | git_review/cmd.py | 8 |
1 files changed, 7 insertions, 1 deletions
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!") |