From e405c1de7b41d8b505c130db116e34b3bf6e19cf Mon Sep 17 00:00:00 2001 From: Lucas Date: Sat, 14 Dec 2019 00:58:19 +0000 Subject: [PATCH] Only run git-status inside a work tree --- utils/shgit | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/utils/shgit b/utils/shgit index eb3a5b2..0ce738d 100644 --- a/utils/shgit +++ b/utils/shgit @@ -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)