diff --git a/share/functions/fish_git_prompt.fish b/share/functions/fish_git_prompt.fish index 6c91d8c31..7684f431b 100644 --- a/share/functions/fish_git_prompt.fish +++ b/share/functions/fish_git_prompt.fish @@ -298,7 +298,10 @@ function fish_git_prompt --description "Prompt function for Git" test "$untracked" = true; and set opt -unormal # Don't use `--ignored=no`; it was introduced in Git 2.16, from January 2018 # Ignored files are omitted by default - set -l stat (command git -c core.fsmonitor= status --porcelain -z $opt | string split0) + # Renames and copies in porcelain -z output have an extra NUL-delimited + # field for the source path. Filter to entries starting with a valid + # two-char status code followed by a space to skip those bare paths. + set -l stat (command git -c core.fsmonitor= status --porcelain -z $opt | string split0 | string match -r '^[ MADRCU?!]{2} .*') set dirtystate (string match -qr '^.[ACDMRTU]' -- $stat; and echo 1) if test -n "$sha" @@ -421,7 +424,10 @@ function __fish_git_prompt_informative_status # 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 $untr | string split0)) + # Renames and copies in porcelain -z output have an extra NUL-delimited + # field for the source path. Filter to entries starting with a valid + # two-char status code followed by a space to skip those bare paths. + set -l stats (string sub -l 2 (git -c core.fsmonitor= status --porcelain -z $untr | string split0 | string match -r '^[ MADRCU?!]{2} .*')) set -l invalidstate (string match -r '^UU' $stats | count) set -l stagedstate (string match -r '^[ACDMRT].' $stats | count) set -l dirtystate (string match -r '^.[ACDMRT]' $stats | count)