Capistrano: changing repository URL

Last week, we moved our git repositories to GitLab so we needed to change all deployment scripts. We deploy using Capistrano and looking at deploy.rb file the task looks simple. Right at the top is something like:

set :repo_url, 'user@domain:repo.git'

Having learnt from experience, I consulted the docs to verify my assumptions. It was exactly as I thought, I changed the URL, ran a deploy to make sure everything is ok and all permissions are set up properly. Deploy succeeded, done!

Next day, we deployed a new release of one of our supporting components. At least we thought we did but the new code wasn’t there. This lead to checking the natural suspects:

  1. Is the new code pushed to the correct repo? Yes
  2. Is it merged to the correct branch? Yes
  3. Is the change of the repo’s URL in the deploy configuration committed? Yes
  4. Was is pushed and merged? Yes
  5. Is it checked out on the computer which runs the deploy? Yes
  6. Is the URL really changed? Yes
  7. I mean really, for all components? Yes
  8. Head hitting the table again and again: Pain
  9. Googling: Justin Tanner’s answer at StackOverflow

As it turns out, Capistrano does not detect the change of the repo URL on the target machine. It just pulls new changes to the local clone of the repository like before and as long as that repo exists, it doesn’t complain. The solution is to delete the local copy of the repository on the target machine before deploying.

Since I considered this a bug, I searched Capistrano issues and as it turns out, it has been reported a year ago without an official fix or at least some consensus about the right solution. So if you change the URL of your repo, don’t forget to purge the clone on the target machines.

Update: Our PR with a note in the documentation was just merged.

We're looking for developers to help us save energy

If you're interested in what we do and you would like to help us save energy, drop us a line at jobs@enectiva.cz.

comments powered by Disqus