diff --git a/news/fix-gistatus-for-detached-head-no-tags.rst b/news/fix-gistatus-for-detached-head-no-tags.rst new file mode 100644 index 000000000..2a348dbd5 --- /dev/null +++ b/news/fix-gistatus-for-detached-head-no-tags.rst @@ -0,0 +1,13 @@ +**Added:** None + +**Changed:** None + +**Deprecated:** None + +**Removed:** None + +**Fixed:** + +* gistatus: Fixed hash not being shown when in detaced HEAD and there are no tags + +**Security:** None diff --git a/xonsh/prompt/gitstatus.py b/xonsh/prompt/gitstatus.py index 2503c2d21..95e8ac562 100644 --- a/xonsh/prompt/gitstatus.py +++ b/xonsh/prompt/gitstatus.py @@ -70,11 +70,10 @@ def _get_def(key): def _get_tag_or_hash(): - tag = _check_output(['git', 'describe', '--exact-match']).strip() - if tag: - return tag + tag_or_hash = _check_output(['git', 'describe', '--always']).strip() hash_ = _check_output(['git', 'rev-parse', '--short', 'HEAD']).strip() - return _get_def('HASH') + hash_ + have_tag_name = tag_or_hash != hash_ + return tag_or_hash if have_tag_name else _get_def('HASH') + hash_ def _get_stash(gitdir):