Silence math errors in git prompt

It's not ideal since we can't get the real result so we just assume it's
"0". That triggers the easier path, which still might display the wrong
thing, but we have to pick something.

Possible fix for #3321.
This commit is contained in:
Fabian Homborg 2016-08-22 16:58:46 +02:00
parent f25d5a0f52
commit 4e2d2c125c

View file

@ -475,14 +475,16 @@ function __fish_git_prompt_informative_status
set -l changedFiles (command git diff --name-status | cut -c 1-2)
set -l stagedFiles (command git diff --staged --name-status | cut -c 1-2)
set -l dirtystate (math (count $changedFiles) - (count (echo $changedFiles | grep "U")))
set -l dirtystate (math (count $changedFiles) - (count (echo $changedFiles | grep "U")) ^/dev/null)
set -l invalidstate (count (echo $stagedFiles | grep "U"))
set -l stagedstate (math (count $stagedFiles) - $invalidstate)
set -l stagedstate (math (count $stagedFiles) - $invalidstate ^/dev/null)
set -l untrackedfiles (command git ls-files --others --exclude-standard | wc -l | string trim)
set -l info
if [ (math $dirtystate + $invalidstate + $stagedstate + $untrackedfiles) = 0 ]
# If `math` fails for some reason, assume the state is clean - it's the simpler path
set -l state (math $dirtystate + $invalidstate + $stagedstate + $untrackedfiles ^/dev/null)
if test -z "$state"; or test "$state" = 0
set info $___fish_git_prompt_color_cleanstate$___fish_git_prompt_char_cleanstate$___fish_git_prompt_color_cleanstate_done
else
for i in $___fish_git_prompt_status_order