From b46a96a7cee43ed35c319e04800a5d043e371163 Mon Sep 17 00:00:00 2001 From: Niccolò Maggioni Date: Tue, 22 Mar 2016 17:29:34 +0100 Subject: Git tag not replacing branch --- functions/vcs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'functions/vcs.zsh') 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 -- cgit v1.2.3 From 89fefbdf6edb353e557bde8fd484d8d2460518d8 Mon Sep 17 00:00:00 2001 From: Niccolò Maggioni Date: Tue, 22 Mar 2016 17:51:01 +0100 Subject: DETACHED_HEAD handling --- functions/vcs.zsh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'functions/vcs.zsh') 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 -- cgit v1.2.3 From 4fdf5df25884ecfaa6668dbc152ee5e7c573d8d2 Mon Sep 17 00:00:00 2001 From: Niccolò Maggioni Date: Tue, 22 Mar 2016 18:24:34 +0100 Subject: Documentation --- functions/vcs.zsh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'functions/vcs.zsh') 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 } -- cgit v1.2.3 From 1ab41d9a6c9e2a4f62e3ebaac71cb2a87dde20cb Mon Sep 17 00:00:00 2001 From: Niccolò Maggioni Date: Fri, 25 Mar 2016 10:51:33 +0100 Subject: Better DETACHED_HEAD detection --- functions/vcs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'functions/vcs.zsh') 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) -- cgit v1.2.3 From ce16b087c6c0f51570903cf89d7e8b7f87287380 Mon Sep 17 00:00:00 2001 From: Niccolò Maggioni Date: Mon, 11 Apr 2016 21:37:28 +0200 Subject: Avoid tag/branch duplication if same value --- functions/vcs.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'functions/vcs.zsh') 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 } -- cgit v1.2.3 From 14e213bd681d9e6733f753cb068fb491a4e174f0 Mon Sep 17 00:00:00 2001 From: Niccolò Maggioni Date: Mon, 11 Apr 2016 23:02:58 +0200 Subject: 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(-) (limited to 'functions/vcs.zsh') 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 } -- cgit v1.2.3 From 6fde7bf3fdce11ab38e50bbcc48e96cb22166d42 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Tue, 12 Apr 2016 09:30:28 -0400 Subject: git-tagname: reducing conditionals in logic --- functions/vcs.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'functions/vcs.zsh') diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 074d1e05..c2b8185a 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -67,7 +67,10 @@ function +vi-git-tagname() { local tag tag=$(git describe --tags --exact-match HEAD 2>/dev/null) - if [[ -z "$(git symbolic-ref HEAD 2>/dev/null)" || ! -z "${tag}" ]] ; then + # if [[ -z "$(git symbolic-ref HEAD 2>/dev/null)" || ! -z "${tag}" ]] ; then + if [[ -n "${tag}" ]] ; then + # There is a tag that points to our current commit. Need to determine if we + # are also on a branch, or are in a DETACHED_HEAD state. head=$(git describe --all) # Make sure that detached head or checked out name differs from tag name if [[ "${head}" != "${tag}" || -- cgit v1.2.3 From 0f4e3e7588fff005a8ad275915f390817f804345 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Tue, 12 Apr 2016 10:43:34 -0400 Subject: git-tagname: Now showing hash/branchname when sitting on a tag --- functions/vcs.zsh | 17 ++++++++--------- powerlevel9k.zsh-theme | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'functions/vcs.zsh') diff --git a/functions/vcs.zsh b/functions/vcs.zsh index c2b8185a..3a5a6cb5 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -67,18 +67,17 @@ function +vi-git-tagname() { local tag tag=$(git describe --tags --exact-match HEAD 2>/dev/null) - # if [[ -z "$(git symbolic-ref HEAD 2>/dev/null)" || ! -z "${tag}" ]] ; then if [[ -n "${tag}" ]] ; then # There is a tag that points to our current commit. Need to determine if we # are also on a branch, or are in a DETACHED_HEAD state. - head=$(git describe --all) - # 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}" + if [[ -z $(git symbolic-ref HEAD 2>/dev/null) ]]; then + # DETACHED_HEAD state. Print the commit hash and tag name. + local revision + revision=$(git rev-list -n 1 --abbrev-commit --abbrev=8 HEAD) + hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${revision} $(print_icon 'VCS_TAG_ICON')${tag}" + else + # We are on both a tag and a branch; print both. + hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" fi fi } diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7da17f99..faae532c 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -832,8 +832,8 @@ prompt_vcs() { VCS_CHANGESET_PREFIX='' if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then - # Default: Just display the first 12 characters of our changeset-ID. - local VCS_CHANGESET_HASH_LENGTH=12 + # Default: Just display the first 8 characters of our changeset-ID. + local VCS_CHANGESET_HASH_LENGTH=8 if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then VCS_CHANGESET_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" fi -- cgit v1.2.3 From a09eda677421bea934a08a0d1bc5196ab973d853 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Tue, 12 Apr 2016 10:54:10 -0400 Subject: Fixing comments in vi-git -tagname --- functions/vcs.zsh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'functions/vcs.zsh') diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 3a5a6cb5..63cdbc75 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -61,9 +61,7 @@ function +vi-git-remotebranch() { } function +vi-git-tagname() { - # Only show the tag name if we are not in DETACHED_HEAD state, - # or if the current branch's HEAD is the same commit as a tag but - # doesn't have the same name + # If we are on a tag, append the tagname to the current branch string. local tag tag=$(git describe --tags --exact-match HEAD 2>/dev/null) @@ -71,12 +69,15 @@ function +vi-git-tagname() { # There is a tag that points to our current commit. Need to determine if we # are also on a branch, or are in a DETACHED_HEAD state. if [[ -z $(git symbolic-ref HEAD 2>/dev/null) ]]; then - # DETACHED_HEAD state. Print the commit hash and tag name. + # DETACHED_HEAD state. We want to append the tag name to the commit hash + # and print it. Unfortunately, `vcs_info` blows away the hash when a tag + # exists, so we have to manually retrieve it and clobber the branch + # string. local revision revision=$(git rev-list -n 1 --abbrev-commit --abbrev=8 HEAD) hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${revision} $(print_icon 'VCS_TAG_ICON')${tag}" else - # We are on both a tag and a branch; print both. + # We are on both a tag and a branch; print both by appending the tag name. hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}" fi fi -- cgit v1.2.3 From 7b2e995299175a8d2e573413975ff8da43b0a9a2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 17 Apr 2016 17:51:31 +0200 Subject: Fix truncation of changeset in detached tag mode --- functions/vcs.zsh | 2 +- powerlevel9k.zsh-theme | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'functions/vcs.zsh') diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 63cdbc75..15f0177e 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -74,7 +74,7 @@ function +vi-git-tagname() { # exists, so we have to manually retrieve it and clobber the branch # string. local revision - revision=$(git rev-list -n 1 --abbrev-commit --abbrev=8 HEAD) + revision=$(git rev-list -n 1 --abbrev-commit --abbrev=${POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH} HEAD) hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${revision} $(print_icon 'VCS_TAG_ICON')${tag}" else # We are on both a tag and a branch; print both by appending the tag name. diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index faae532c..ed1c49cb 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -815,7 +815,14 @@ prompt_todo() { # VCS segment: shows the state of your repository, if you are in a folder under # version control set_default POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND "red" +# Default: Just display the first 8 characters of our changeset-ID. +set_default POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH "8" prompt_vcs() { + if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then + POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" + fi + + # Load VCS_INFO autoload -Uz vcs_info VCS_WORKDIR_DIRTY=false @@ -832,13 +839,7 @@ prompt_vcs() { VCS_CHANGESET_PREFIX='' if [[ "$POWERLEVEL9K_SHOW_CHANGESET" == true ]]; then - # Default: Just display the first 8 characters of our changeset-ID. - local VCS_CHANGESET_HASH_LENGTH=8 - if [[ -n "$POWERLEVEL9K_CHANGESET_HASH_LENGTH" ]]; then - VCS_CHANGESET_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" - fi - - VCS_CHANGESET_PREFIX="$(print_icon 'VCS_COMMIT_ICON')%0.$VCS_CHANGESET_HASH_LENGTH""i " + VCS_CHANGESET_PREFIX="$(print_icon 'VCS_COMMIT_ICON')%0.$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH""i " fi zstyle ':vcs_info:*' enable git hg -- cgit v1.2.3