Only run git-status inside a work tree

This commit is contained in:
Lucas 2019-12-14 00:58:19 +00:00
parent dab4dcce0c
commit e405c1de7b
1 changed files with 11 additions and 2 deletions

View File

@ -13,8 +13,11 @@ shgit()
{
: ${SHGIT_BEGIN:=} ${SHGIT_END:= } ${SHGIT_SEP:=:}
gitdir=$(git rev-parse --git-dir 2>/dev/null) && [ -n "$gitdir" ] ||
args=$(git rev-parse --git-dir --is-inside-work-tree 2>/dev/null) ||
return
set -- $args
gitdir=${1:-}
worktree=${2:-}
if ! name=$(git symbolic-ref -q --short HEAD); then
name=$(git rev-parse --short HEAD 2>/dev/null)
@ -34,7 +37,13 @@ shgit()
fi
status=
[ -n "$(git status --porcelain)" ] && status=${SHGIT_SEP}*
if [ "$worktree" = "true" ]; then
if [ -n "$(git status --porcelain)" ]; then
status=${SHGIT_SEP}*
fi
else
status=${SHGIT_SEP}?
fi
IFS=" " set -- $(git rev-list --left-right --count \
@{upstream}...HEAD 2>/dev/null)