module GitProjectRemote::ClassMethods

Check/ add new remotes

Public Instance Methods

add_new_remote(g, name, remote) click to toggle source
# File lib/helpers/git_project_remote.rb, line 49
def add_new_remote(g, name, remote)
  g.add_remote(name, remote)
  g.add_remote('all', remote) unless remote_exists?(g, name)
  `git remote set-url --add all #{remote}`
  puts "Added remote #{name}".green
end
add_remote(g, v) click to toggle source

Add remote

# File lib/helpers/git_project_remote.rb, line 57
def add_remote(g, v)
  g.add_remote('origin', v['origin']) unless remote_exists?(g, 'origin')
  g.add_remote('all', v['origin']) unless remote_exists?(g, 'all')
  v.each do |name, remote|
    next if  %w(root_dir all group).include?(name) || remote_exists?(g, name)
    add_new_remote(g, name, remote)
  end
end
clone(url, name, path) click to toggle source

Clone unless dir exists

# File lib/helpers/git_project_remote.rb, line 24
def clone(url, name, path)
  path = real_root_dir(path)
  r = "#{path}/#{name}"
  g = Git.open(r)
  if g
    puts 'Already cloned '.yellow + "#{url}".blue
  else
    Git.clone(url, name, path: path) || Git.init(r)
    puts "Cloning #{url} as #{name} into #{path}".green
  end
  g
end
fetch(g) click to toggle source
# File lib/helpers/git_project_remote.rb, line 37
def fetch(g)
  g.remotes.each do |r|
    next if %w(root_dir all group).include?(r.name)
    r.fetch
    puts "Fetching updates from #{r.name}: #{r.url}".green
  end
end
real_root_dir(path) click to toggle source

Get real root_dir

# File lib/helpers/git_project_remote.rb, line 18
def real_root_dir(path)
  return File.readlink(path) if File.symlink?(path)
  path
end
remote_exists?(g, name) click to toggle source
# File lib/helpers/git_project_remote.rb, line 45
def remote_exists?(g, name)
  g.remotes.map(&:name).include?(name)
end