summaryrefslogtreecommitdiff
path: root/lib/git.zsh
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2015-12-17 18:37:49 +0100
committerMarc Cornellà <marc.cornella@live.com>2015-12-17 18:37:49 +0100
commit0842384987e73f258474b7af87032daee56a5bc3 (patch)
treec52b642f7a8499c16b7b030dadebd8b06503f9f4 /lib/git.zsh
parent30ddf25fd7e23cb66ca70baaa66376c60ab8b2a5 (diff)
downloadzsh-0842384987e73f258474b7af87032daee56a5bc3.tar.gz
zsh-0842384987e73f258474b7af87032daee56a5bc3.tar.bz2
zsh-0842384987e73f258474b7af87032daee56a5bc3.zip
Put `local var` declaration in its own line in lib/git.zsh
In places, the local statement will override the exit code and the written command won't have the effect intended when it was written. For example, when it's not inside a git repo the exit code won't be true, but the local statement will make it true regardless. See #4708.
Diffstat (limited to 'lib/git.zsh')
-rw-r--r--lib/git.zsh20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/git.zsh b/lib/git.zsh
index 51e323a75..de51daafa 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -75,7 +75,8 @@ function git_current_branch() {
# Gets the number of commits ahead from remote
function git_commits_ahead() {
if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
- local COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')
+ local COMMITS
+ COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')
echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
fi
}
@@ -105,12 +106,14 @@ function git_prompt_remote() {
# Formats prompt string for current git commit short SHA
function git_prompt_short_sha() {
- local SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
+ local SHA
+ SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
}
# Formats prompt string for current git commit long SHA
function git_prompt_long_sha() {
- local SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
+ local SHA
+ SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
}
# Get the status of the working tree
@@ -165,11 +168,10 @@ function git_prompt_status() {
# Outputs -1, 0, or 1 if the installed version is less than, equal to, or
# greater than the input version, respectively.
function git_compare_version() {
- local INPUT_GIT_VERSION=$1;
- local INSTALLED_GIT_VERSION
- INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION});
- INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null));
- INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]});
+ local INPUT_GIT_VERSION INSTALLED_GIT_VERSION
+ INPUT_GIT_VERSION=(${(s/./)1})
+ INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null))
+ INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]})
for i in {1..3}; do
if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then
@@ -187,4 +189,4 @@ function git_compare_version() {
# This is unlikely to change so make it all statically assigned
POST_1_7_2_GIT=$(git_compare_version "1.7.2")
# Clean up the namespace slightly by removing the checker function
-unset -f git_compare_version
+unfunction git_compare_version