class GitHelper::ChangeRemote

Attributes

new_owner[RW]
old_owner[RW]

Public Class Methods

new(old_owner, new_owner) click to toggle source
# File lib/git_helper/change_remote.rb, line 7
def initialize(old_owner, new_owner)
  @old_owner = old_owner
  @new_owner = new_owner
end

Public Instance Methods

execute() click to toggle source
# File lib/git_helper/change_remote.rb, line 12
def execute
  original_dir = Dir.pwd
  nested_dirs = Dir.entries(original_dir).select do |entry|
    entry_dir = File.join(original_dir, entry)
    File.directory?(entry_dir) && !['.', '..'].include?(entry)
  end

  nested_dirs.each do |nested_dir|
    process_dir(nested_dir, original_dir)
  end
end

Private Instance Methods

highline() click to toggle source
# File lib/git_helper/change_remote.rb, line 73
        def highline
  @highline ||= HighlineWrapper.new
end
local_code() click to toggle source

rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize

# File lib/git_helper/change_remote.rb, line 69
        def local_code
  @local_code ||= GitHelper::LocalCode.new
end
process_dir(current_dir, original_dir) click to toggle source
# File lib/git_helper/change_remote.rb, line 24
        def process_dir(current_dir, original_dir)
  Dir.chdir(current_dir)

  if File.exist?('.git') && highline.ask_yes_no(
    "Found git directory: #{current_dir}. Do you wish to proceed in updating #{current_dir}'s remote URLs? (y/n)",
    { required: true }
  )
    process_git_repository
  end

  Dir.chdir(original_dir)
end
process_git_repository() click to toggle source
# File lib/git_helper/change_remote.rb, line 37
        def process_git_repository
  local_code.remotes.each do |remote|
    if remote.include?(old_owner)
      process_remote(remote)
    else
      puts "  Found remote is not pointing to #{old_owner}."
    end
  end
  puts
end
process_remote(remote) click to toggle source

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

# File lib/git_helper/change_remote.rb, line 50
        def process_remote(remote)
  remote_name = local_code.remote_name(remote)

  if local_code.ssh_remote?(remote)
    repo = local_code.remote_project(remote)
    source_name = local_code.remote_source(remote)
    remote_url = "git@#{source_name}:#{new_owner}/#{repo}.git"
  elsif local_code.https_remote?(remote)
    repo = local_code.remote_project(remote)
    source_name = local_code.remote_source(remote)
    remote_url = "https://#{source_name}/#{new_owner}/#{repo}.git"
  end

  puts "  Changing the remote URL #{remote_name} to be '#{remote_url}'."
  local_code.change_remote(remote_name, remote_url)
end