Not only git stash does not return a usable stash id that is unchanging, it does not provide a way to programmatically know if anything was stashed.
I am sure there are workarounds, but none is obvious by reading the man page. Provide recipes on the wiki page.