Class: MacSetup::GitRepoInstaller
- Inherits:
-
Object
- Object
- MacSetup::GitRepoInstaller
- Defined in:
- lib/mac_setup/git_repo_installer.rb
Class Method Summary collapse
- .can_update? ⇒ Boolean
- .expand_url(repo) ⇒ Object
- .install_repo(repo, install_path) ⇒ Object
- .run(config, _status) ⇒ Object
- .update_repo(install_path) ⇒ Object
Class Method Details
.can_update? ⇒ Boolean
40 41 42 |
# File 'lib/mac_setup/git_repo_installer.rb', line 40 def self.can_update? Shell.run("git status --porcelain").empty? end |
.expand_url(repo) ⇒ Object
44 45 46 |
# File 'lib/mac_setup/git_repo_installer.rb', line 44 def self.(repo) repo =~ %r{^[^/]+/[^/]+$} ? "https://github.com/#{repo}.git" : repo end |
.install_repo(repo, install_path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mac_setup/git_repo_installer.rb', line 17 def self.install_repo(repo, install_path) if Dir.exist?(install_path) print "#{repo} Already Installed. Updating..." update_repo(install_path) else print "Installing #{repo}..." url = (repo) Shell.run(%(git clone --recursive #{url} "#{install_path}")) puts "Ok" end end |
.run(config, _status) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mac_setup/git_repo_installer.rb', line 5 def self.run(config, _status) repos = config.git_repos return if repos.none? puts "Installing Git Repos..." repos.each do |repo_and_path| repo, install_path = repo_and_path.to_a.flatten install_repo(repo, File.(install_path)) end end |
.update_repo(install_path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mac_setup/git_repo_installer.rb', line 29 def self.update_repo(install_path) Dir.chdir(install_path) do if can_update? Shell.run("git pull && git submodule update --init --recursive") puts "Ok" else puts "\nCan't update. Unstaged changes in #{install_path}" end end end |