Search code examples
gitgithubcapistrano

Capistrano looking for old Github repo after deploy.rb changed to new repo


Recently, a project I'm working on changed source repositories on Github.

The deploy.rb was updated to correctly point to the new github account, but when I run the cap staging deploy, it looks for the old repo.

cap staging deploy
      * executing `staging'
      * executing `deploy'
      * executing `deploy:updatify'
      * executing "cd /home/deploy/example/current; git fetch origin; git reset --hard origin/staging"
        servers: ["example.com"]
        Password: 
        [example.com] executing command
     ** [out :: example.com] ERROR: oldusername/example.git doesn't exist. Did you enter it correctly?
     ** [out :: example.com] fatal: The remote end hung up unexpectedly
     ** [out :: example.com] HEAD is now at 7c92a69 adding changes
        command finished in 4148ms
        triggering after callbacks for `deploy:updatify'
      * executing `bundle:install'
      * executing "cd /home/deploy/example/current && bundle install --gemfile /home/deploy/example/current/Gemfile --path /home/deploy/example/shared/bundle --deployment --quiet --without development test"
        servers: ["example.com"]
        [example.com] executing command
        command finished in 7442ms
      * executing `deploy:restart'
      * executing "cd /home/deploy/example/current; [ -f tmp/pids/unicorn.pid ] && kill -USR2 `cat tmp/pids/unicorn.pid` || bundle exec unicorn_rails -c ./config/unicorn.rb -E staging -D"
        servers: ["example.com"]
        [example.com] executing command
        command finished in 94ms

I tried to look for a cached-copy directory as mentioned here: Capistrano still trying to connect to my old repo but on my server, there is no cached-copy directory.

Where is it still referencing the old repository?

deploy.rb:

 require 'bundler/capistrano'

 load 'config/deploy/nginx'
 load 'config/deploy/unicorn'
 load 'config/deploy/updatify'

 # Base Settings ############################################################

 set :user,          'deploy'
 set :application,   'example'
 set :use_sudo,      false
 set :scm,           :git
 set :repository,    '[email protected]:new_repo_user/example.git'
 set :deploy_to,     "/home/#{user}/#{application}"

 # Fake using releases to just use git
 set :current_release, current_path

 ssh_options[:paranoid] = false
 default_run_options[:pty] = true

 # Multistage ###############################################################    ###

 task :production do
   server 'exampleprod.com', :app, :web, :db, :primary => true
   set  :branch,      'origin/production'
   set  :environment, 'production'
   set  :environment_database, defer { production_database }
   set  :environment_dbhost,   defer { production_dbhost }
 end

 task :staging do
   server 'example.com', :app, :web, :db, :primary => true
   set :branch,      'origin/staging'
   set :environment, 'staging'
   set :environment_database, defer { environment_info["database"] }
   set :environment_dbhost,   defer { environment_info["host"] }
 end

Solution

  • It turns out there was still a reference to the original repository in the .git/config file.

    I changed this:

    [remote "origin"]
            fetch = +refs/heads/*:refs/remotes/origin/*
            url = [email protected]:oldusername/example.git
    

    To this:

    [remote "origin"]
            fetch = +refs/heads/*:refs/remotes/origin/*
            url = [email protected]:new_repo_user/example.git
    

    And Capistrano started doing the right thing.