class GitProject
GitProject contains helpers for Git commands
Attributes
project[R]
Public Class Methods
new(config)
click to toggle source
# File lib/helpers/git_project.rb, line 15 def initialize(config) @project = Project.new(config) end
Public Instance Methods
add_remotes()
click to toggle source
Add missing remotes
# File lib/helpers/git_project.rb, line 54 def add_remotes @project.all.each do |k, v| working_dir = "#{v['root_dir']}/#{k}" g = Git.open(working_dir) || Git.init(working_dir) GitProject.add_remote(g, v) puts "Checking new remotes for #{k}".green end end
create_project_and_remotes(k, v)
click to toggle source
-
Clone all repositories based on the origin key
-
Add all other remotes unless it is origin
# File lib/helpers/git_project.rb, line 65 def create_project_and_remotes(k, v) puts "root_dir isn't defined for #{k}" unless v['root_dir'] GitProject.dir_or_symlink_exist?(v['root_dir']) root_dir = GitProject.real_root_dir(v['root_dir']) GitProject.create_root_dir(root_dir) g = GitProject.clone(v.values[0], k, root_dir) GitProject.add_remote(g, v) if g end
fetch_all(group = nil)
click to toggle source
By default, fetch from all
# File lib/helpers/git_project.rb, line 75 def fetch_all(group = nil) @project.all(group).each do |k, v| puts "Fetching changes for #{k}".green root_dir = GitProject.real_root_dir(v['root_dir']) GitProject.create_root_dir(root_dir) working_dir = "#{root_dir}/#{k}" g = Git.open(working_dir) || Git.init(working_dir) GitProject.fetch(g) end end
init()
click to toggle source
# File lib/helpers/git_project.rb, line 19 def init @project.all.each do |k, v| begin create_project_and_remotes(k, v) rescue => e initialize_and_add_remotes(k, v) puts "Please check paths and permissions for #{k}. Error: #{e}".red puts "Failed to clone #{v.values[0]}. Initialized & fetched updates from remotes instead.".yellow end end end
initialize_and_add_remotes(k, v)
click to toggle source
# File lib/helpers/git_project.rb, line 32 def initialize_and_add_remotes(k, v) g = Git.init("#{v['root_dir']}/#{k}") return nil unless g GitProject.add_remote(g, v) GitProject.fetch(g) end
new_group(project, name)
click to toggle source
Change group
# File lib/helpers/git_project.rb, line 49 def new_group(project, name) @project.new_group(project, name) end
new_remote(project, name, url)
click to toggle source
Add a new remote
# File lib/helpers/git_project.rb, line 44 def new_remote(project, name, url) @project.new_remote(project, name, url) end
projects()
click to toggle source
# File lib/helpers/git_project.rb, line 39 def projects @project.all end