Last Updated: March 20, 2016
·
8.866K
· jasontorres

Fixing Capistrano 3 deployments after a repository change

I recently changed a repository url of a project. However, I found out that editing your project's capistrano repo_url isn't enough. This usually was easy with Capistrano 2.

set :deploy_via, :remote_cache doesn't work anymore with Capistrano 3. shared/cached-copy doesn't exist anymore as well and has been replaced with /data/appname/repo. (replace /data/appname with your actual deployment directory).

It was actually quite annoying since I can't find a decent way to fix the besides redoing the mirror (deleting /data/appname/repo?) or by manually updating the config. I went ahead with editing the config.

So, to get your instances updated...

vim /data/appname/repo/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = true
[remote "origin"]
    fetch = +refs/*:refs/*
    mirror = true
    url = git@github.com:username/oldrepo.git

to

[core]
    repositoryformatversion = 0
    filemode = true
    bare = true
[remote "origin"]
    fetch = +refs/*:refs/*
    mirror = true
    url = git@github.com:username/newrepo.git

Run cap deploy then all will be fine again.

Cheers.

Follow me on Twitter as @jasontorres

7 Responses
Add your response

I just ran into this issue, thank you for documenting this!

over 1 year ago ·

Jesus christ thank you. 5 hours later. Much appreciated!

over 1 year ago ·

Or update it from from Capistrano itself:

namespace :git do
  task :update_repo_url do
    on roles(:all) do
      within repo_path do
        execute :git, 'remote', 'set-url', 'origin', fetch(:repo_url)
      end
    end
  end
end
over 1 year ago ·

Great post, thanks for that.

over 1 year ago ·

This saved me today. Well done.

over 1 year ago ·

This saved me

over 1 year ago ·

Thank you!

over 1 year ago ·