Module: GitProjectRemote::ClassMethods
- Defined in:
- lib/helpers/git_project_remote.rb
Overview
Check/ add new remotes
Instance Method Summary collapse
- #add_new_remote(g, name, remote) ⇒ Object
-
#add_remote(g, v) ⇒ Object
Add remote.
-
#clone(url, name, path) ⇒ Object
Clone unless dir exists.
- #fetch(g) ⇒ Object
- #remote_exists?(g, name) ⇒ Boolean
Instance Method Details
#add_new_remote(g, name, remote) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/helpers/git_project_remote.rb', line 34 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) ⇒ Object
Add remote
42 43 44 45 46 47 48 49 50 |
# File 'lib/helpers/git_project_remote.rb', line 42 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) || g.remotes.map(&:name).include?(name) add_new_remote(g, name, remote) end end |
#clone(url, name, path) ⇒ Object
Clone unless dir exists
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/helpers/git_project_remote.rb', line 10 def clone(url, name, path) r = "#{path}/#{name}" if Git.open(r) puts 'Already cloned '.yellow + "#{url}".blue else Git.clone(url, name, path: path) || Git.init(r) g = Git.open(r) puts "Cloning #{url} as #{name} into #{path}".green end g end |
#fetch(g) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/helpers/git_project_remote.rb', line 22 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 |
#remote_exists?(g, name) ⇒ Boolean
30 31 32 |
# File 'lib/helpers/git_project_remote.rb', line 30 def remote_exists?(g, name) g.remotes.map(&:name).include?(name) end |