1ac40cd4456230f09bf0258b173304929d118992

Author
Stimim Chen <106878+Stimim@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

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>

Diff

 1diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py
 2index 300365d71f5c9aca9926e30a85de4d5a0bdf77ed..bf3173614bda4872aa458379f1301354aca9e491 100644
 3--- a/plugins/git-prompt/gitstatus.py
 4+++ b/plugins/git-prompt/gitstatus.py
 5@@ -11,11 +11,11 @@ def get_tagname_or_hash():
 6     """return tagname if exists else hash"""
 7     # get hash
 8     hash_cmd = ['git', 'rev-parse', '--short', 'HEAD']
 9-    hash_ = check_output(hash_cmd).strip()
10+    hash_ = check_output(hash_cmd).decode('utf-8').strip()
11 
12     # get tagname
13     tags_cmd = ['git', 'for-each-ref', '--points-at=HEAD', '--count=2', '--sort=-version:refname', '--format=%(refname:short)', 'refs/tags']
14-    tags = check_output(tags_cmd).split()
15+    tags = check_output(tags_cmd).decode('utf-8').split()
16 
17     if tags:
18         return tags[0] + ('+' if len(tags) > 1 else '')