TeamCity unable to load changes from Git due to an existing remote

I’ve recently been doing a lot of work in TeamCity, including switching over from SVN to Git (more to come on that in future blog posts). I’ve just had to deal with an odd issue which was entirely my fault but took a bit of head-scratching to figure out.

I got the following exception (where <URL_TO_GIT_REPOSITORY> is a placeholder I’ve substituted for the original URL):

jetbrains.buildServer.VCS – Error while loading changes for root <URL_TO_GIT_REPOSITORY> #master {instance id=43, parent id=3}, cause: ‘git fetch’ command failed.
stderr: The repository at directory ‘D:\Development\Infrastructure\.BuildServer\system\caches\git\git-4D05D25B.git’ cannot be opened or created, reason: The specified directory D:\Development\Infrastructure\.BuildServer\system\caches\git\git-4D05D25B.git is already used for another remote <URL_TO_GIT_REPOSITORY> and cannot be used for others (<URL_TO_GIT_REPOSITORY> ). Please specify the other directory explicitly.

What this essentially seems to be saying is that it can’t checkout changes from my remote Git repository because its local repository is currently tracking a different remote repository… which just happens to have the same URL! This didn’t make any sense – why was it thinking there were two different URLs here when they were clearly the same?

Well the eagle-eyed amongst you may spot that there is actually a subtle difference between the two reported URLs – the one in brackets has a trailing space after it. Turns out that I was setting the VCS root URL via a build parameter and had accidentally left the trailing space in there for one of my build configurations, giving me two different values in theory, even though to a human eye they looked the same. Clearly TeamCity doesn’t trim whitespace from VCS root URLs, otherwise it would have normalised them and treated them as one and the same.

Needless to say, removing the trailing space prompted everything to spring back into life.

This entry was posted in Fixes and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Leave a Reply