fixes #4162 Error trying to switch the tag repository

Fixed the issue and committed the code for review, please check it.