Class: GemContribute::CLI::Git
- Inherits:
-
Object
- Object
- GemContribute::CLI::Git
- Defined in:
- lib/gem_contribute/cli/fork_clone_branch.rb
Overview
Thin wrapper around git so the spec can swap in a fake without shelling out. The real implementation uses Open3 with arg-list invocation — no shell, so no injection surface.
Instance Method Summary collapse
- #add_remote(path, name, url) ⇒ Object
- #checkout_branch(path, branch) ⇒ Object
- #clone(url, target) ⇒ Object
- #push(path, remote, branch) ⇒ Object
- #remote_exists?(path, name) ⇒ Boolean
- #run!(argv) ⇒ Object
Instance Method Details
#add_remote(path, name, url) ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/gem_contribute/cli/fork_clone_branch.rb', line 179 def add_remote(path, name, url) # Idempotent: if the remote already exists (e.g. reusing a clone) # we silently succeed rather than fail the whole flow. return if remote_exists?(path, name) run!(["git", "-C", path, "remote", "add", name, url]) end |
#checkout_branch(path, branch) ⇒ Object
175 176 177 |
# File 'lib/gem_contribute/cli/fork_clone_branch.rb', line 175 def checkout_branch(path, branch) run!(["git", "-C", path, "checkout", "-b", branch]) end |
#clone(url, target) ⇒ Object
171 172 173 |
# File 'lib/gem_contribute/cli/fork_clone_branch.rb', line 171 def clone(url, target) run!(["git", "clone", url, target]) end |
#push(path, remote, branch) ⇒ Object
187 188 189 |
# File 'lib/gem_contribute/cli/fork_clone_branch.rb', line 187 def push(path, remote, branch) run!(["git", "-C", path, "push", "-u", remote, branch]) end |
#remote_exists?(path, name) ⇒ Boolean
191 192 193 194 |
# File 'lib/gem_contribute/cli/fork_clone_branch.rb', line 191 def remote_exists?(path, name) out, _err, status = Open3.capture3("git", "-C", path, "remote") status.success? && out.split("\n").include?(name) end |
#run!(argv) ⇒ Object
196 197 198 199 200 201 |
# File 'lib/gem_contribute/cli/fork_clone_branch.rb', line 196 def run!(argv) _stdout, stderr_str, status = Open3.capture3(*argv) return if status.success? raise GemContribute::AdapterError, "git #{argv[1..].join(" ")} failed: #{stderr_str.strip}" end |