diff options
author | Niccolò Maggioni <nicco.maggioni@gmail.com> | 2016-04-12 00:02:58 +0300 |
---|---|---|
committer | Niccolò Maggioni <nicco.maggioni@gmail.com> | 2016-04-12 00:02:58 +0300 |
commit | 14e213bd681d9e6733f753cb068fb491a4e174f0 (patch) | |
tree | f3b95d1273285e180c73d9734e917a793d6f5001 /functions/vcs.zsh | |
parent | ce16b087c6c0f51570903cf89d7e8b7f87287380 (diff) |
Weird conditions handling
Become a programmer, they said. It'll be fun, they said.
Diffstat (limited to 'functions/vcs.zsh')
-rw-r--r-- | functions/vcs.zsh | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/functions/vcs.zsh b/functions/vcs.zsh index f112e6a1..074d1e05 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -62,16 +62,20 @@ function +vi-git-remotebranch() { function +vi-git-tagname() { # Only show the tag name if we are not in DETACHED_HEAD state, - # since in that case it would already be displayed in the branch segment - if [[ -z "$(git symbolic-ref HEAD 2>/dev/null)" ]] ; then - local tag + # or if the current branch's HEAD is the same commit as a tag but + # doesn't have the same name + local tag + tag=$(git describe --tags --exact-match HEAD 2>/dev/null) - tag=$(git describe --tags --exact-match HEAD 2>/dev/null) + if [[ -z "$(git symbolic-ref HEAD 2>/dev/null)" || ! -z "${tag}" ]] ; then head=$(git describe --all) - # Make sure that detached head and tag differ in name - if [[ "${head}" != "${tag}" ]]; then - # Append the tag segment to the branch one - [[ -n "${tag}" ]] && hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" + # Make sure that detached head or checked out name differs from tag name + if [[ "${head}" != "${tag}" || + "$(git rev-parse --abbrev-ref HEAD)" != "${tag}" && + "$(git rev-parse --abbrev-ref HEAD)" != "HEAD" && + "$(git rev-list -n 1 HEAD)" == "$(git rev-list -n 1 ${tag})" ]]; then + # Append the tag segment to the branch one + [[ -n "${tag}" ]] && hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" fi fi } |