Would the `git symbolic-ref` below maybe fail too? I am wondering if it is enough to use the exit status of that command.