I've been researching the fastest way to check for changes in a repo to update the PS1 prompt. For reasons not worth elaborating, no access to the __git_ps1() macro, and anyway other posts have suggested various commands, including those used in __git_ps1().
Reason: I'm accessing repos on a remote server over VPN & ssh, with the remote repo tunnelled back through my connection to our in-house git server. I'm guessing (but really not sure if this is true) that this may be the reason that on a fresh connection on a new day, cd'ing into a repo on this remote server can cause git ls-files -m
to take 3 or 4 seconds to complete, and still take up to 1 second after file caching has helped.
To improve this I found git diff-index --quiet HEAD
is almost instant, but the next day it starts returning '1' even though there are actually no changes (no output from a very slow run of git status
). I've found that git update-index --refresh -q
seems to fix the issue (quickly) and also returns '0' if in fact there are no changes.
From what I've read I think it should be safe to run from PS1 prompt, but I understand this is a "lower level" git command and I may not be understanding all the implications. So, to be clear, I've currently got the following to check for changes, which always seems to be quick, but after a day starts outputting '*' in clean repos.
if git diff-index --quiet HEAD 2>/dev/null && [[ -z "$(git ls-files --others --exclude-standard --directory --no-empty-directory)" ]]
then echo -n " "
else echo -n " *"
fi
Can any "git gurus" out there see a problem with changing 1st test to git update-index --refresh -q
?