From b46a96a7cee43ed35c319e04800a5d043e371163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maggioni?= Date: Tue, 22 Mar 2016 17:29:34 +0100 Subject: [PATCH 1/6] Git tag not replacing branch --- functions/vcs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 9d3883ca..847275fa 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -64,7 +64,7 @@ function +vi-git-tagname() { local tag tag=$(git describe --tags --exact-match HEAD 2>/dev/null) - [[ -n "${tag}" ]] && hook_com[branch]="$(print_icon 'VCS_TAG_ICON')${tag}" + [[ -n "${tag}" ]] && hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" } # Show count of stashed changes From 89fefbdf6edb353e557bde8fd484d8d2460518d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maggioni?= Date: Tue, 22 Mar 2016 17:51:01 +0100 Subject: [PATCH 2/6] DETACHED_HEAD handling --- functions/vcs.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 847275fa..92731d52 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -61,10 +61,12 @@ function +vi-git-remotebranch() { } function +vi-git-tagname() { + if [[ -n "$(git status | grep 'HEAD detached')" ]] ; then local tag tag=$(git describe --tags --exact-match HEAD 2>/dev/null) [[ -n "${tag}" ]] && hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" + fi } # Show count of stashed changes From 4fdf5df25884ecfaa6668dbc152ee5e7c573d8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maggioni?= Date: Tue, 22 Mar 2016 18:24:34 +0100 Subject: [PATCH 3/6] Documentation --- functions/vcs.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 92731d52..af247d9c 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -61,10 +61,13 @@ 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 [[ -n "$(git status | grep 'HEAD detached')" ]] ; then local tag tag=$(git describe --tags --exact-match HEAD 2>/dev/null) + # Append the tag segment to the branch one [[ -n "${tag}" ]] && hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" fi } From 1ab41d9a6c9e2a4f62e3ebaac71cb2a87dde20cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maggioni?= Date: Fri, 25 Mar 2016 10:51:33 +0100 Subject: [PATCH 4/6] Better DETACHED_HEAD detection --- functions/vcs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index af247d9c..368251b6 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -63,7 +63,7 @@ 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 [[ -n "$(git status | grep 'HEAD detached')" ]] ; then + if [[ -z "$(git symbolic-ref HEAD 2>/dev/null)" ]] ; then local tag tag=$(git describe --tags --exact-match HEAD 2>/dev/null) From ce16b087c6c0f51570903cf89d7e8b7f87287380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maggioni?= Date: Mon, 11 Apr 2016 21:37:28 +0200 Subject: [PATCH 5/6] Avoid tag/branch duplication if same value --- functions/vcs.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 368251b6..f112e6a1 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -67,8 +67,12 @@ function +vi-git-tagname() { local tag tag=$(git describe --tags --exact-match HEAD 2>/dev/null) - # Append the tag segment to the branch one - [[ -n "${tag}" ]] && hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" + 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}" + fi fi } From 14e213bd681d9e6733f753cb068fb491a4e174f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maggioni?= Date: Mon, 11 Apr 2016 23:02:58 +0200 Subject: [PATCH 6/6] Weird conditions handling Become a programmer, they said. It'll be fun, they said. --- functions/vcs.zsh | 20 ++++++++++++-------- 1 file 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 }