git_prompt: Allow overriding informative status via git config

If either of the two git config variables:

- bash.showDirtyState
- bash.showUntrackedFiles

is explicitly set to false, we will disable informative status, and
fall back on the non-informative version (most likely still with
either dirty or untracked files, since we already use the variables
for that).

These vars are read by the official git prompt, so we use them instead
of inventing our own "fish.showInformativeStatus".

(Note: This also uses $__fish_git_prompt_showdirtystate and friends,
but only when there's nothing set in the repo, and there's really no
reason to set those to false if using the informative status)

Fixes #5551.

[ci skip]
This commit is contained in:
Fabian Homborg 2019-01-19 17:05:00 +01:00
parent 5c689bb50c
commit 15cf45a2a0

View File

@ -372,16 +372,35 @@ function __fish_git_prompt --description "Prompt function for Git"
set -l space "$___fish_git_prompt_color$___fish_git_prompt_char_stateseparator$___fish_git_prompt_color_done"
# Use our variables as defaults, but allow overrides via the local git config.
# That means if neither is set, this stays empty.
#
# So "!= true" or "!= false" are useful tests if you want to do something by default.
set -l dirty (command git config --bool bash.showDirtyState)
if not set -q dirty[1]
set -q __fish_git_prompt_showdirtystate
and set dirty true
end
set -l untracked (command git config --bool bash.showUntrackedFiles)
if not set -q untracked[1]
set -q __fish_git_prompt_showuntrackedfiles
and set untracked true
end
if test "true" = $inside_worktree
# Use informative status, unless dirty or untracked have been set to false.
#
# This is to allow overrides for the repository.
if set -q __fish_git_prompt_show_informative_status
and test "$dirty" != false
and test "$untracked" != false
set informative_status "$space"(__fish_git_prompt_informative_status)
else
if set -q __fish_git_prompt_showdirtystate
set -l config (command git config --bool bash.showDirtyState)
if test "$config" != "false"
set w (__fish_git_prompt_dirty)
set i (__fish_git_prompt_staged $sha)
end
# This has to be set explicitly.
if test "$dirty" = true
set w (__fish_git_prompt_dirty)
set i (__fish_git_prompt_staged $sha)
end
if set -q __fish_git_prompt_showstashstate
@ -389,11 +408,8 @@ function __fish_git_prompt --description "Prompt function for Git"
set s $___fish_git_prompt_char_stashstate
end
if set -q __fish_git_prompt_showuntrackedfiles
set -l config (command git config --bool bash.showUntrackedFiles)
if test "$config" != false
set u (__fish_git_prompt_untracked)
end
if test "$untracked" != true
set u (__fish_git_prompt_untracked)
end
end