Removing some unnecessary lines
Being a little smarter about detecting a detached HEAD in the cache dir