fix(git-prompt): make gitstatus.py python3-compatible (#9186)

check_output() in get_tagname_or_hash() returns bytes instead of str in
python3.  Decode the return value to utf-8, this works in both python2
and python3.

Co-authored-by: Stimim Chen <stimim@google.com>
This commit is contained in:
Stimim Chen 2020-12-03 19:00:56 +08:00 committed by GitHub
parent 3f8af040e9
commit 1ac40cd445
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,11 +11,11 @@ def get_tagname_or_hash():
"""return tagname if exists else hash""" """return tagname if exists else hash"""
# get hash # get hash
hash_cmd = ['git', 'rev-parse', '--short', 'HEAD'] hash_cmd = ['git', 'rev-parse', '--short', 'HEAD']
hash_ = check_output(hash_cmd).strip() hash_ = check_output(hash_cmd).decode('utf-8').strip()
# get tagname # get tagname
tags_cmd = ['git', 'for-each-ref', '--points-at=HEAD', '--count=2', '--sort=-version:refname', '--format=%(refname:short)', 'refs/tags'] tags_cmd = ['git', 'for-each-ref', '--points-at=HEAD', '--count=2', '--sort=-version:refname', '--format=%(refname:short)', 'refs/tags']
tags = check_output(tags_cmd).split() tags = check_output(tags_cmd).decode('utf-8').split()
if tags: if tags:
return tags[0] + ('+' if len(tags) > 1 else '') return tags[0] + ('+' if len(tags) > 1 else '')