f558a460c289a41811e0c4b89f04d539c66224a1

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Merge pull request #4709 from mcornella/fix-local-vars-in-git-prompt

Put `local var` declaration in its own line in lib/git.zsh

Diff

 1diff --git a/lib/git.zsh b/lib/git.zsh
 2index 51e323a757e8b836cf9dee27a17d384563c39c02..de51daafac8978eacd8ba37671cd71e3b90209db 100644
 3--- a/lib/git.zsh
 4+++ b/lib/git.zsh
 5@@ -75,7 +75,8 @@ function git_current_branch() {
 6 # Gets the number of commits ahead from remote
 7 function git_commits_ahead() {
 8   if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
 9-    local COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')
10+    local COMMITS
11+    COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')
12     echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
13   fi
14 }
15@@ -105,12 +106,14 @@ function git_prompt_remote() {
16 
17 # Formats prompt string for current git commit short SHA
18 function git_prompt_short_sha() {
19-  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"
20+  local SHA
21+  SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
22 }
23 
24 # Formats prompt string for current git commit long SHA
25 function git_prompt_long_sha() {
26-  local SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
27+  local SHA
28+  SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
29 }
30 
31 # Get the status of the working tree
32@@ -165,11 +168,10 @@ function git_prompt_status() {
33 # Outputs -1, 0, or 1 if the installed version is less than, equal to, or
34 # greater than the input version, respectively.
35 function git_compare_version() {
36-  local INPUT_GIT_VERSION=$1;
37-  local INSTALLED_GIT_VERSION
38-  INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION});
39-  INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null));
40-  INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]});
41+  local INPUT_GIT_VERSION INSTALLED_GIT_VERSION
42+  INPUT_GIT_VERSION=(${(s/./)1})
43+  INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null))
44+  INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]})
45 
46   for i in {1..3}; do
47     if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then
48@@ -187,4 +189,4 @@ function git_compare_version() {
49 # This is unlikely to change so make it all statically assigned
50 POST_1_7_2_GIT=$(git_compare_version "1.7.2")
51 # Clean up the namespace slightly by removing the checker function
52-unset -f git_compare_version
53+unfunction git_compare_version