Improve logic for checking if inside a git repo

This commit is contained in:
Sindre Sorhus
2013-05-01 17:05:40 +02:00
parent ab01293a2d
commit dc640860ac

View File

@@ -34,8 +34,10 @@ zstyle ':vcs_info:git*' actionformats ' %b|%a'
# Fastest possible way to check if repo is dirty # Fastest possible way to check if repo is dirty
git_dirty() { git_dirty() {
[ -d .git ] || return # check if we're in a git repo
command git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo '*' command git rev-parse --is-inside-work-tree &>/dev/null || return
# check if it's dirty
command git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ] && echo '*'
} }
# Displays the exec time of the last command if set threshold was exceeded # Displays the exec time of the last command if set threshold was exceeded