From 63f7f1925e0940393a2109446d1a48c6768e5cba Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 20 Jun 2020 20:12:16 +0200 Subject: [PATCH] git prompt: Simplify "staged" logic This had this weird "pass along the sha, then check" logic to it which is entirely unnecessary. This function just says when something is staged, nothing more. Why that is you can figure out for yourself. This makes it easier to call this function, and it no longer prints an empty line if nothing is staged. --- share/functions/fish_git_prompt.fish | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/share/functions/fish_git_prompt.fish b/share/functions/fish_git_prompt.fish index 375932c50..d9e529279 100644 --- a/share/functions/fish_git_prompt.fish +++ b/share/functions/fish_git_prompt.fish @@ -408,7 +408,11 @@ function fish_git_prompt --description "Prompt function for Git" # This has to be set explicitly. if test "$dirty" = true set w (__fish_git_prompt_dirty) - set i (__fish_git_prompt_staged $sha) + if test -n "$sha" + set i (__fish_git_prompt_staged) + else + set i $___fish_git_prompt_char_invalidstate + end end if set -q __fish_git_prompt_showstashstate @@ -485,23 +489,11 @@ end ### helper functions function __fish_git_prompt_staged --description "fish_git_prompt helper, tells whether or not the current branch has staged files" - set -l sha $argv[1] - set -l staged - set -l ret 0 - - if test -n "$sha" - # The "diff" functions all return > 0 if there _is_ a diff, - # but we want to return 0 if there are staged changes. - # So we invert the status. - not command git diff-index --cached --quiet HEAD -- 2>/dev/null - and set staged $___fish_git_prompt_char_stagedstate - set ret $status - else - set staged $___fish_git_prompt_char_invalidstate - set ret 2 - end - echo $staged - return $ret + # The "diff" functions all return > 0 if there _is_ a diff, + # but we want to return 0 if there are staged changes. + # So we invert the status. + not command git diff-index --cached --quiet HEAD -- 2>/dev/null + and echo $___fish_git_prompt_char_stagedstate end function __fish_git_prompt_untracked --description "fish_git_prompt helper, tells whether or not the current repository has untracked files"