1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-24 14:50:07 +00:00

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.
This commit is contained in:
Marc Cornellà 2015-12-17 18:37:49 +01:00
parent 30ddf25fd7
commit 0842384987

View file

@ -75,7 +75,8 @@ function git_current_branch() {
# Gets the number of commits ahead from remote # Gets the number of commits ahead from remote
function git_commits_ahead() { function git_commits_ahead() {
if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then 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" echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
fi fi
} }
@ -105,12 +106,14 @@ function git_prompt_remote() {
# Formats prompt string for current git commit short SHA # Formats prompt string for current git commit short SHA
function git_prompt_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 # Formats prompt string for current git commit long SHA
function git_prompt_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 # 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 # Outputs -1, 0, or 1 if the installed version is less than, equal to, or
# greater than the input version, respectively. # greater than the input version, respectively.
function git_compare_version() { function git_compare_version() {
local INPUT_GIT_VERSION=$1; local INPUT_GIT_VERSION INSTALLED_GIT_VERSION
local INSTALLED_GIT_VERSION INPUT_GIT_VERSION=(${(s/./)1})
INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION}); INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null))
INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null)); INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]})
INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]});
for i in {1..3}; do for i in {1..3}; do
if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then 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 # This is unlikely to change so make it all statically assigned
POST_1_7_2_GIT=$(git_compare_version "1.7.2") POST_1_7_2_GIT=$(git_compare_version "1.7.2")
# Clean up the namespace slightly by removing the checker function # Clean up the namespace slightly by removing the checker function
unset -f git_compare_version unfunction git_compare_version