'Ensure a refname is valid and lives in refs or is HEAD.
HEAD is not a valid refname according to git-check-ref-format, but this
class needs to be able to touch HEAD. Also, check_ref_format expects
refnames without the leading \'refs/\', but this class requires that
so it cannot touch anything outside the refs dir (or HEAD).
:param name: The name of the reference.
:raises KeyError: if a refname is not HEAD or is otherwise not valid.'

def _check_refname(self, name):

    if (name in ('HEAD', 'refs/stash')):
        return
    if ((not name.startswith('refs/')) or (not check_ref_format(name[5:]))):
        raise RefFormatError(name)
