diff --git a/user/fish/fish_prompt.fish b/user/fish/fish_prompt.fish index ec7774e..337c469 100644 --- a/user/fish/fish_prompt.fish +++ b/user/fish/fish_prompt.fish @@ -63,6 +63,21 @@ function _fish_prompt_git_unpushed_branches string split ', ' end +function _fish_prompt_git_remote_deleted -a git_branch + set -l git_remote (git config --get "branch.$git_branch.remote" 2> /dev/null) + set -l git_merge_ref (git config --get "branch.$git_branch.merge" 2> /dev/null) + + test -n "$git_remote" + and test -n "$git_merge_ref" + or return 1 + + set -l git_remote_ref "refs/remotes/$git_remote/"(string replace -r '^refs/heads/' '' "$git_merge_ref") + git show-ref --verify --quiet "$git_remote_ref" + and return 1 + + return 0 +end + function fish_git_prompt command -qs git or return @@ -81,6 +96,7 @@ function fish_git_prompt set -l git_branch (git branch --show-current 2> /dev/null);or return set -l git_detach (_fish_prompt_git_detached) set -l git_remote_branch (git rev-parse --abbrev-ref (git branch --show-current)@{u} 2> /dev/null) + set -l git_remote_deleted (_fish_prompt_git_remote_deleted "$git_branch"; and echo "1") set -l git_status_s (timeout 5s git status -s | string collect) set -l git_log_unpushed (_fish_prompt_git_unpushed_branches) @@ -100,26 +116,33 @@ function fish_git_prompt _fish_prompt_warn "$git_detach" else if test -n "$git_branch" _fish_prompt_accent "$git_branch" + if test -n "$git_remote_deleted" + _fish_prompt_warn "X" + end else _fish_prompt_warn "init" end # if we have at least one commit if git rev-parse HEAD -- &>/dev/null - # print a "↑" if ahead of origin - test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l) - and set -f _git_sync_ahead '↑' + # Only compare ahead/behind when upstream exists and resolves correctly. + if test -n "$git_remote_branch" + and git rev-parse --verify "$git_remote_branch" &>/dev/null + # print a "↑" if ahead of origin + test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l) + and set -f _git_sync_ahead '↑' - # print a "↓" if behind of origin - test 0 -lt (git log --oneline HEAD.."$git_remote_branch" -- | wc -l) - and set -l _git_sync_behind '↓' + # print a "↓" if behind of origin + test 0 -lt (git log --oneline HEAD.."$git_remote_branch" -- | wc -l) + and set -l _git_sync_behind '↓' - if set -q _git_sync_ahead _git_sync_behind - _fish_prompt_normal '⇅' - else if set -q _git_sync_ahead - _fish_prompt_normal '↑' - else if set -q _git_sync_behind - _fish_prompt_normal '↓' + if set -q _git_sync_ahead _git_sync_behind + _fish_prompt_normal '⇅' + else if set -q _git_sync_ahead + _fish_prompt_normal '↑' + else if set -q _git_sync_behind + _fish_prompt_normal '↓' + end end if test -n "$git_log_unpushed"