Class: GemContribute::Operations::Clone
- Inherits:
-
Object
- Object
- GemContribute::Operations::Clone
- Defined in:
- lib/gem_contribute/operations/clone.rb
Overview
Bootstrap step 2: clone the fork into ‘<root>/<owner>/<repo>` (reusing an existing clone if one is there), and ensure an `upstream` remote points at the canonical project. Returns a `Result` carrying the local path and a `reused` flag, or a tagged `Failure`.
The “reuse if ‘.git` exists” rule and the upstream-remote convention are gem-contribute policy on top of git, not git itself — that’s why they live here rather than in ‘Git`.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #call(adapter:, project:, fork_clone_url:, root:) ⇒ Object
-
#initialize(git: Git.new) ⇒ Clone
constructor
A new instance of Clone.
Constructor Details
Instance Method Details
#call(adapter:, project:, fork_clone_url:, root:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gem_contribute/operations/clone.rb', line 25 def call(adapter:, project:, fork_clone_url:, root:) target = File.join(root, project.owner, project.repo) reused = File.directory?(File.join(target, ".git")) unless reused FileUtils.mkdir_p(File.dirname(target)) @git.clone(fork_clone_url, target) end @git.add_remote(target, "upstream", adapter.clone_url(project.owner, project.repo)) Success(Result.new(path: target, reused: reused)) rescue GemContribute::AdapterError => e Failure([:adapter_error, e.]) end |