I have a bash PS1 to get a red color if my git dir is changed or green if not is changed.
if [ $? -eq 0 ]; then \
echo "$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \
if [ "$?" -eq "0" ]; then \
# @4 - Clean repository - nothing to commit
echo "\n'$Green'"$(__git_ps1 "(%s)"'$Color_Off'); \
else \
# @5 - Changes to working tree
echo "\n'$IRed'"$(__git_ps1 "(%s)"'$Color_Off'); \
fi)\$ "; \
fi)'
This works fine! But the problem is that in some work dir is very slow because exists many changes and a big diff.
What is the better way to get git status boolean (yes changed or no changed) without a full
I tried with git status --short
or git status --porcelain
but is very slow yet.
Perhaps this answer might be useful: https://stackoverflow.com/a/2659808/3903076
In short, you can adapt the checks below to your needs. See the linked answer for more details.
if ! git diff-index --quiet --cached HEAD; then
# Index has changes.
exit 1;
elif ! git diff-files --quiet; then
# Working tree has changes.
exit 1;
elif [ -n "`git ls-files --others --exclude-standard`" ]; then
# There are untracked unignored files.
exit 1;
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With