diff options
author | lieryan <lie.1296@gmail.com> | 2019-12-21 18:33:39 +1100 |
---|---|---|
committer | Robby Russell <robby@planetargon.com> | 2019-12-20 23:33:39 -0800 |
commit | e204c596ef5a1075914c5e7810ec1eba4bbe7411 (patch) | |
tree | c16019ce8f6b258ae7435abed2bf003c93039ebc /plugins/git-prompt | |
parent | feaee0446468798b9a9411dc5ea5f957c19b87a0 (diff) | |
download | zsh-e204c596ef5a1075914c5e7810ec1eba4bbe7411.tar.gz zsh-e204c596ef5a1075914c5e7810ec1eba4bbe7411.tar.bz2 zsh-e204c596ef5a1075914c5e7810ec1eba4bbe7411.zip |
Rewrite gitstatus collection to be more robust (#7322)
Fix the finicky parsing logic and just ask git the necessary information
directly.
Diffstat (limited to 'plugins/git-prompt')
-rw-r--r-- | plugins/git-prompt/gitstatus.py | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py index 390a50a6f..300365d71 100644 --- a/plugins/git-prompt/gitstatus.py +++ b/plugins/git-prompt/gitstatus.py @@ -4,26 +4,21 @@ from __future__ import print_function import os import sys import re -import shlex from subprocess import Popen, PIPE, check_output def get_tagname_or_hash(): """return tagname if exists else hash""" - cmd = 'git log -1 --format="%h%d"' - output = check_output(shlex.split(cmd)).decode('utf-8').strip() - hash_, tagname = None, None # get hash - m = re.search('\(.*\)$', output) - if m: - hash_ = output[:m.start()-1] + hash_cmd = ['git', 'rev-parse', '--short', 'HEAD'] + hash_ = check_output(hash_cmd).strip() + # get tagname - m = re.search('tag: .*[,\)]', output) - if m: - tagname = 'tags/' + output[m.start()+len('tag: '): m.end()-1] + 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() - if tagname: - return tagname.replace(' ', '') + if tags: + return tags[0] + ('+' if len(tags) > 1 else '') elif hash_: return hash_ return None |