TeamCity and git and overlapping branches

1 minute read

Ran into an intersting edge case at work today with TeamCity’s git functionality that was fairly obscure, but Googling provided no useful information so I’ll stick it up here for posterity.

We had a set of working builds, and needed to update from a previous git branching strategy to use git-flow. Seemed a fairly straight-forward process, just update the VCS root to use the new release/foo branches and go.

However, in practice, what happened is all the builds failed with the not-overly-useful error:

[14:34:16] Failed to start build
[14:34:16] Failed to collect changes, error: 'git fetch' command failed.
stderr: Fail to update 'refs/heads/release/foo' (LOCK_FAILURE)

Eventually after pondering this for a bit I figured it had to be an issue with the cached copy of the git repo on the TeamCity server, and looking in {BuildServer}/system/caches/git found that the affected repos had a previously existing release branch from a few branch strategies in the past.

It’s quite reasonable that the TeamCity git functionality was unable to create a release/ folder for release/foo when there was a previously existing file named release in the same folder.

I opted to nuke the cached repos and have TeamCity re-fetch them all from the git server. It’s entirely possible that simply removing the release reference from the cached git repo would’ve worked, but I was already delayed and didn’t want to spend more time troubleshooting issues I could’ve potentially introduced.