Class: Gitomator::Task::CloneRepos
- Inherits:
-
BaseReposTask
- Object
- BaseTask
- BaseReposTask
- Gitomator::Task::CloneRepos
- Defined in:
- lib/gitomator/task/clone_repos.rb
Instance Attribute Summary
Attributes inherited from BaseReposTask
Attributes inherited from BaseTask
Instance Method Summary collapse
-
#initialize(context, repos, local_dir, opts = {}) ⇒ CloneRepos
constructor
A new instance of CloneRepos.
-
#process_repo(source, index) ⇒ Object
override.
Methods inherited from BaseReposTask
#after_processing_all_repos, #before_processing_any_repos, #process_repo_error, #run
Methods inherited from BaseTask
#ci, #git, #hosting, #run, #tagging
Constructor Details
#initialize(context, repos, local_dir, opts = {}) ⇒ CloneRepos
Returns a new instance of CloneRepos.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gitomator/task/clone_repos.rb', line 14 def initialize(context, repos, local_dir, opts={}) super(context, repos, local_dir) @opts = opts before_processing_any_repos do logger.debug "Clonning #{repos.length} repo(s) into #{local_dir} ..." end after_processing_all_repos do |repo2result, repo2error| cloned = repo2result.select {|_, result| result}.length skipped = repo2result.reject {|_, result| result}.length errored = repo2error.length logger.info "Done (#{cloned} cloned, #{skipped} skipped, #{errored} errors)" end end |
Instance Method Details
#process_repo(source, index) ⇒ Object
override
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gitomator/task/clone_repos.rb', line 32 def process_repo(source, index) namespace = hosting.resolve_namespace(source) repo_name = hosting.resolve_repo_name(source) branch = hosting.resolve_branch(source) local_repo_root = File.join(@local_dir, repo_name) if Dir.exist? local_repo_root logger.info "Local clone exists, #{local_repo_root}" return false end repo = hosting.read_repo(repo_name) raise "No such remote repo, #{repo_name}" if repo.nil? logger.info "git clone #{repo.url}" git.clone(repo.url, local_repo_root) unless branch.nil? logger.debug("Switching to remote branch #{branch}") git.checkout(local_repo_root, branch, {:is_new => true, :is_remote => true}) end return true end |