Module: Workspace
- Includes:
- Contracts
- Defined in:
- lib/git-ready/workspace.rb
Class Method Summary collapse
- .clone(url, path) ⇒ Object
- .configure_remotes(path, origin_url, upstream_url) ⇒ Object
- .git_repository?(path) ⇒ Boolean
- .setup(repositories) ⇒ Object
Class Method Details
.clone(url, path) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/git-ready/workspace.rb', line 24 def self.clone(url, path) credentials = Rugged::Credentials::SshKeyFromAgent.new username: 'git' Rugged::Repository.clone_at(url, path, credentials: credentials) unless git_repository? path rescue Rugged::NetworkError Announce.failure "Failed to clone repository #{url} to path #{path}" end |
.configure_remotes(path, origin_url, upstream_url) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/git-ready/workspace.rb', line 13 def self.configure_remotes(path, origin_url, upstream_url) repository = Rugged::Repository.new path repository.remotes.set_url 'origin', origin_url repository.remotes.set_url 'upstream', upstream_url rescue Rugged::RepositoryError Announce.failure "Failed to configure remotes #{origin_url} and #{upstream_url} for #{path}" rescue Rugged::OSError Announce.warning "#{path} does not exist" end |
.git_repository?(path) ⇒ Boolean
8 9 10 |
# File 'lib/git-ready/workspace.rb', line 8 def self.git_repository?(path) Dir.exist? "#{path}/.git" end |
.setup(repositories) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/git-ready/workspace.rb', line 32 def self.setup(repositories) progress = ProgressBar.new repositories.length repositories.each do |repo| path = "#{Settings.workspace}/#{repo[:origin][:name]}" clone repo[:origin][:ssh_url], path configure_remotes path, repo[:origin][:ssh_url], repo[:upstream][:ssh_url] progress.increment! end end |