Use git's plumbing to lookup HEAD

Implements current branch in terms of git plumbing, guaranteeing that it doesn't explode in a repo without `.git/HEAD`, eg a submodule.