Don't blow up on vanishing HEAD

Closes #459.