From 661ea418613dee90c322b025c4ee91aac55370f5 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 1 Jun 2022 17:08:33 +0200 Subject: [PATCH] fish_git_prompt: Use "dirty"/"staged" regex like informative When switching this to use `git status`, I neglected to use the correct definition of what a "dirty" and a "staged" change is. So this now showed already staged files still as "dirty". Fixes #8986 --- share/functions/fish_git_prompt.fish | 4 ++-- tests/checks/git.fish | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/share/functions/fish_git_prompt.fish b/share/functions/fish_git_prompt.fish index 555120c81..cdd2ab798 100644 --- a/share/functions/fish_git_prompt.fish +++ b/share/functions/fish_git_prompt.fish @@ -269,9 +269,9 @@ function fish_git_prompt --description "Prompt function for Git" test "$untracked" = true; and set opt -unormal set -l stat (command git -c core.fsmonitor= status --porcelain -z --ignored=no $opt | string split0) - set dirtystate (string match -qr '^.?M' -- $stat; and echo 1) + set dirtystate (string match -qr '^.[ACDMR]' -- $stat; and echo 1) if test -n "$sha" - set stagedstate (string match -qr '^[^? ]' -- $stat; and echo 1) + set stagedstate (string match -qr '^[ACDMR].' -- $stat; and echo 1) else set invalidstate 1 end diff --git a/tests/checks/git.fish b/tests/checks/git.fish index 2e426000b..ad2500891 100644 --- a/tests/checks/git.fish +++ b/tests/checks/git.fish @@ -85,6 +85,26 @@ fish_git_prompt echo #CHECK: (newbranch %) +set -e __fish_git_prompt_showuntrackedfiles +set -e __fish_git_prompt_status_order + +git -c user.email=banana@example.com -c user.name=banana commit -m foo >/dev/null +fish_git_prompt +echo +#CHECK: (newbranch) + +echo "test" > foo +fish_git_prompt +echo +#CHECK: (newbranch *) + +git add foo +fish_git_prompt +echo +#CHECK: (newbranch +) + + + # Turn on everything and verify we correctly ignore sus config files. set -g __fish_git_prompt_status_order stagedstate invalidstate dirtystate untrackedfiles stashstate set -g __fish_git_prompt_showdirtystate 1