1
0
Fork 0
mirror of synced 2024-05-24 11:10:30 -04:00

Remove git-info dependency on is-true function

from `git` module. Actually, the function is a little bit of
over-engineering and it's currently only being used for checking the
result of `git rev-parse --is-inside-work-tree`, even in the `git`
module code.

Checking for the return code of `git rev-parse --is-inside-work-tree` is
enough. Also refactored other portions of the code where return codes
are being checked.

Fixes #161, Closes #162
This commit is contained in:
Eric Nielsen 2017-04-03 18:17:31 -05:00 committed by Matt Hamilton
parent 43096df5cb
commit 262f4992e9

View file

@ -96,7 +96,7 @@ git-info() {
typeset -gA git_info typeset -gA git_info
# Return if not inside a Git repository work tree. # Return if not inside a Git repository work tree.
if ! is-true $(git rev-parse --is-inside-work-tree 2>/dev/null); then if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
return 1 return 1
fi fi
@ -230,9 +230,7 @@ git-info() {
zstyle -s ':zim:git-info:clean' format 'clean_format' zstyle -s ':zim:git-info:clean' format 'clean_format'
local dirty local dirty
local indexed
local indexed_formatted local indexed_formatted
local unindexed
local unindexed_formatted local unindexed_formatted
local untracked_formatted local untracked_formatted
if ! zstyle -t ':zim:git-info' verbose; then if ! zstyle -t ':zim:git-info' verbose; then
@ -240,11 +238,9 @@ git-info() {
local unindexed_format local unindexed_format
zstyle -s ':zim:git-info:unindexed' format 'unindexed_format' zstyle -s ':zim:git-info:unindexed' format 'unindexed_format'
if [[ -n ${unindexed_format} || -n ${dirty_format} || -n ${clean_format} ]]; then if [[ -n ${unindexed_format} || -n ${dirty_format} || -n ${clean_format} ]]; then
(git diff-files --no-ext-diff --quiet --ignore-submodules=${ignore_submodules} 2>/dev/null) if ! git diff-files --no-ext-diff --quiet --ignore-submodules=${ignore_submodules} >/dev/null 2>&1; then
unindexed=$?
if (( unindexed )); then
unindexed_formatted=${unindexed_format} unindexed_formatted=${unindexed_format}
dirty=${unindexed} dirty=1
fi fi
fi fi
@ -252,11 +248,9 @@ git-info() {
local indexed_format local indexed_format
zstyle -s ':zim:git-info:indexed' format 'indexed_format' zstyle -s ':zim:git-info:indexed' format 'indexed_format'
if [[ -n ${indexed_format} || (${dirty} -eq 0 && (-n ${dirty_format} || -n ${clean_format})) ]]; then if [[ -n ${indexed_format} || (${dirty} -eq 0 && (-n ${dirty_format} || -n ${clean_format})) ]]; then
(git diff-index --no-ext-diff --quiet --cached --ignore-submodules=${ignore_submodules} HEAD 2>/dev/null) if ! git diff-index --no-ext-diff --quiet --cached --ignore-submodules=${ignore_submodules} HEAD >/dev/null 2>&1; then
indexed=$?
if (( indexed )); then
indexed_formatted=${indexed_format} indexed_formatted=${indexed_format}
dirty=${indexed} dirty=1
fi fi
fi fi
@ -270,6 +264,8 @@ git-info() {
# Use porcelain status for easy parsing. # Use porcelain status for easy parsing.
local status_cmd="git status --porcelain --ignore-submodules=${ignore_submodules}" local status_cmd="git status --porcelain --ignore-submodules=${ignore_submodules}"
local indexed
local unindexed
local untracked local untracked
# Get current status. # Get current status.
while IFS=$'\n' read line; do while IFS=$'\n' read line; do