diff --git a/doc_src/cmds/fish_git_prompt.rst b/doc_src/cmds/fish_git_prompt.rst index 3d8a1623c..3648ce8d3 100644 --- a/doc_src/cmds/fish_git_prompt.rst +++ b/doc_src/cmds/fish_git_prompt.rst @@ -26,7 +26,10 @@ The ``fish_git_prompt`` function displays information about the current git repo There are numerous customization options, which can be controlled with git options or fish variables. git options, where available, take precedence over the fish variable with the same function. git options can be set on a per-repository or global basis. git options can be set with the ``git config`` command, while fish variables can be set as usual with the :ref:`set ` command. -- ``$__fish_git_prompt_show_informative_status`` or the git option ``bash.showInformativeStatus`` can be set to enable the "informative" display, which will show a large amount of information - the number of untracked files, dirty files, unpushed/unpulled commits, and more. In large repositories, this can take a lot of time, so it you may wish to disable it in these repositories with ``git config --local bash.showInformativeStatus false``. It also changes the characters the prompt uses to less plain ones (``✚`` instead of ``*`` for the dirty state for example) , and if you are only interested in that, set ``$__fish_git_prompt_use_informative_chars`` instead. +- ``$__fish_git_prompt_show_informative_status`` or the git option ``bash.showInformativeStatus`` can be set to enable the "informative" display, which will show a large amount of information - the number of dirty files, unpushed/unpulled commits, and more. + In large repositories, this can take a lot of time, so it you may wish to disable it in these repositories with ``git config --local bash.showInformativeStatus false``. It also changes the characters the prompt uses to less plain ones (``✚`` instead of ``*`` for the dirty state for example) , and if you are only interested in that, set ``$__fish_git_prompt_use_informative_chars`` instead. + + Because counting untracked files requires a lot of time, the number of untracked files is only shown if enabled via ``$__fish_git_prompt_showuntrackedfiles`` or the git option ``bash.showUntrackedFiles``. - ``$__fish_git_prompt_showdirtystate`` or the git option ``bash.showDirtyState`` can be set to show if the repository is "dirty", i.e. has uncommitted changes. diff --git a/share/functions/fish_git_prompt.fish b/share/functions/fish_git_prompt.fish index 84bcf10e9..06477800d 100644 --- a/share/functions/fish_git_prompt.fish +++ b/share/functions/fish_git_prompt.fish @@ -251,9 +251,8 @@ function fish_git_prompt --description "Prompt function for Git" or begin set -q __fish_git_prompt_show_informative_status and test "$dirty" != false - and test "$untracked" != false end - set informative_status (__fish_git_prompt_informative_status $git_dir) + set informative_status (untracked=$untracked __fish_git_prompt_informative_status $git_dir) if test -n "$informative_status" set informative_status "$space$informative_status" end @@ -358,12 +357,17 @@ function __fish_git_prompt_informative_status set stashstate (count < $stashfile) end - # Use git status --porcelain. - # This uses the "normal" untracked mode so untracked directories are considered as 1 entry. - # It's quite a bit faster and unlikely anyone cares about the number of files if it's *all* of the files + # If we're not told to show untracked files, we don't. + # If we are, we still use the "normal" mode because it's a lot faster, + # and it's unlikely anyone cares about the number of files if it's *all* of the files # in that directory. + set -l untr -uno + test "$untracked" = true + and set untr -unormal + + # Use git status --porcelain. # The v2 format is better, but we don't actually care in this case. - set -l stats (string sub -l 2 (git -c core.fsmonitor= status --porcelain -z -unormal | string split0)) + set -l stats (string sub -l 2 (git -c core.fsmonitor= status --porcelain -z $untr | string split0)) set -l invalidstate (string match -r '^UU' $stats | count) set -l stagedstate (string match -r '^[ACDMR].' $stats | count) set -l dirtystate (string match -r '^.[ACDMR]' $stats | count) diff --git a/tests/checks/git.fish b/tests/checks/git.fish index ad2500891..de7403baf 100644 --- a/tests/checks/git.fish +++ b/tests/checks/git.fish @@ -54,8 +54,15 @@ echo # the git prompt doesn't print a newline set -g __fish_git_prompt_show_informative_status 1 fish_git_prompt echo +#CHECK: (newbranch|✔) + +# Informative mode only shows untracked files if explicitly told. +set -g __fish_git_prompt_showuntrackedfiles 1 +fish_git_prompt +echo #CHECK: (newbranch|…1) set -e __fish_git_prompt_show_informative_status +set -e __fish_git_prompt_showuntrackedfiles # Confirm the mode changes back fish_git_prompt