Class: GitHelper::ChangeRemote

Inherits:
Object
  • Object
show all
Defined in:
lib/git_helper/change_remote.rb

Instance Method Summary collapse

Instance Method Details

#execute(old_owner, new_owner) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/git_helper/change_remote.rb', line 3

def execute(old_owner, new_owner)
  current_dir = Dir.pwd
  nested_dirs = Dir.entries(current_dir).select do |entry|
    entry_dir = File.join(current_dir, entry)
    File.directory?(entry_dir) && !(entry == '.' || entry == '..')
  end

  nested_dirs.each do |dir|
    Dir.chdir dir
    if File.exist?('.git')
      puts "Found git directory: #{dir}."
      remotes = `git remote -v`.split("\n")
      remotes.each do |remote|
        if resp.include?(old_owner)
          puts "  Git directory's remote is pointing to: '#{old_owner}'."
          swap_ssh(old_owner, new_owner, remote) if remote.scan(/(git@)/).any?
          swap_https(old_owner, new_owner, remote) if remote.scan(/(https:\/\/)/).any?
        else
          puts "  No need to update remote."
        end
      end
    end
    Dir.chdir current_dir
  end
end