From dc2f28e93667933a41debf7ff629c2bb1591ecce Mon Sep 17 00:00:00 2001 From: Alex Light Date: Thu, 26 Jan 2012 17:26:43 -0500 Subject: [PATCH 1/4] updated git.zsh so that the git status indicator will work even with older versions of git --- lib/git.zsh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/git.zsh b/lib/git.zsh index defa062c6..03f337941 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -6,6 +6,39 @@ function git_prompt_info() { # Checks if working tree is dirty parse_git_dirty() { +#do stuff here + ver=$(git --version | cut -d " " -f 3) + if $(is_legacy_git); then + echo $(parse_legacy_git_dirty) + else + echo $(parse_recent_git_dirty) + fi +} + +# echos the string 'true' if this git is old enough not to have --ignore-submodules +# echos false otherwise +is_legacy_git() { + checkit() { + if [ $1 -gt 1 -o $2 -gt 7 -o $3 -ge 2 ]; then + echo false + else + echo true + fi + } + echo $(checkit $(git --version | cut -d " " -f 3 | tr '.' ' ')) +} + +# Checks if working tree is dirty when --ignore-submodules is not present +parse_legacy_git_dirty() { + if [[ -n $(git status --porcelain 2> /dev/null) ]]; then + echo "$ZSH_THEME_GIT_PROMPT_DIRTY" + else + echo "$ZSH_THEME_GIT_PROMPT_CLEAN" + fi +} + +# Checks if working tree is dirty when git is recent +parse_recent_git_dirty() { if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then echo "$ZSH_THEME_GIT_PROMPT_DIRTY" else @@ -13,6 +46,8 @@ parse_git_dirty() { fi } + + # Checks if there are commits ahead from remote function git_prompt_ahead() { if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then From 468c5a20e39994a911914274368dd2bc8d3b5c6f Mon Sep 17 00:00:00 2001 From: Alex Light Date: Thu, 26 Jan 2012 17:57:43 -0500 Subject: [PATCH 2/4] updated git.zsh so that the git status indicator will work even with older versions of git. Also cleaned up some crap --- lib/git.zsh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index 03f337941..7b4bc1224 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -6,8 +6,6 @@ function git_prompt_info() { # Checks if working tree is dirty parse_git_dirty() { -#do stuff here - ver=$(git --version | cut -d " " -f 3) if $(is_legacy_git); then echo $(parse_legacy_git_dirty) else @@ -46,8 +44,6 @@ parse_recent_git_dirty() { fi } - - # Checks if there are commits ahead from remote function git_prompt_ahead() { if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then From ef625adb0733d88fc406eeb60b45389754a0c3cf Mon Sep 17 00:00:00 2001 From: Alex Light Date: Thu, 26 Jan 2012 18:15:51 -0500 Subject: [PATCH 3/4] made the lib/git.zsh file check the version of git that is being used and ajust the arguments for the git status call accordingly --- lib/git.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index 7b4bc1224..a68a6e4d6 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -17,7 +17,11 @@ parse_git_dirty() { # echos false otherwise is_legacy_git() { checkit() { - if [ $1 -gt 1 -o $2 -gt 7 -o $3 -ge 2 ]; then + if [ $1 -gt 1 ]; then + echo false + elif [ $1 -eq 1 -a $2 -gt 7 ]; then + echo false + elif [ $1 -eq 1 -a $2 -eq 7 -a $3 -ge 2 ]; then echo false else echo true From 6bd2afe1b81cb838659a21961258016bfd7ea711 Mon Sep 17 00:00:00 2001 From: Alex Light Date: Fri, 27 Jan 2012 11:34:08 -0500 Subject: [PATCH 4/4] made the check for git version happen only once to save on time --- lib/git.zsh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index b6546d8e4..c1ecb2b77 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -6,7 +6,7 @@ function git_prompt_info() { # Checks if working tree is dirty parse_git_dirty() { - if $(is_legacy_git); then + if [ "true" = "$IS_LEGACY_GIT" ]; then echo $(parse_legacy_git_dirty) else echo $(parse_recent_git_dirty) @@ -15,21 +15,27 @@ parse_git_dirty() { # echos the string 'true' if this git is old enough not to have --ignore-submodules # echos false otherwise -is_legacy_git() { +get_is_legacy_git() { checkit() { if [ $1 -gt 1 ]; then - echo false + echo "false" elif [ $1 -eq 1 -a $2 -gt 7 ]; then - echo false + echo "false" elif [ $1 -eq 1 -a $2 -eq 7 -a $3 -ge 2 ]; then - echo false + echo "false" else - echo true + echo "true" fi } echo $(checkit $(git --version | cut -d " " -f 3 | tr '.' ' ')) } +#this is unlikely to change so make it all statically assigned +IS_LEGACY_GIT=$(get_is_legacy_git) + +#clean up the namespace slightly by removing the checker function +unset -f get_is_legacy_git + # Checks if working tree is dirty when --ignore-submodules is not present parse_legacy_git_dirty() { if [[ -n $(git status --porcelain 2> /dev/null) ]]; then @@ -96,4 +102,4 @@ git_prompt_status() { STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" fi echo $STATUS -} \ No newline at end of file +}