Fix NPE if bare repository HEAD is somehow invalid