projects: make sure HEAD is a valid symref
The web UI will only allow HEAD to be set to a symref to an existing
refs/heads/* ref (or, if there are none of those present,
refs/heads/master).
However, if any initial clone fails to set a HEAD symref (clone.sh tries
very hard to get it right, but if the source is empty or not from a git
source it might not initially succeed), we need to try again to set a
valid HEAD until we get one.
The same for a push project. Initially they are empty with HEAD set to
refs/heads/master, but if the only content ever pushed is to other heads
and the web UI is never used to set a valid HEAD then we need to try to
set a valid HEAD ourselves.
Once a valid HEAD has been set we will stop trying to set one even if
that HEAD is later deleted. At that point it's no longer our
responsibility to make sure HEAD is valid, the project owner should
handle it at that point.
Signed-off-by: Kyle J. McKay <mackyle@gmail.com>