From 4e2d2c125c60518e7d4a2d17cb6eb694cd5dd442 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 22 Aug 2016 16:58:46 +0200 Subject: [PATCH] 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. --- share/functions/__fish_git_prompt.fish | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/share/functions/__fish_git_prompt.fish b/share/functions/__fish_git_prompt.fish index 9a5aa7b5f..827c9c48f 100644 --- a/share/functions/__fish_git_prompt.fish +++ b/share/functions/__fish_git_prompt.fish @@ -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