Class: Geet::Services::AddUpstreamRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/geet/services/add_upstream_repo.rb

Overview

Add the upstream repository to the current repository (configuration).

Constant Summary collapse

DEFAULT_GIT_CLIENT =
Utils::GitClient.new

Instance Method Summary collapse

Constructor Details

#initialize(repository, out: $stdout, git_client: DEFAULT_GIT_CLIENT) ⇒ AddUpstreamRepo

Returns a new instance of AddUpstreamRepo.



10
11
12
13
14
# File 'lib/geet/services/add_upstream_repo.rb', line 10

def initialize(repository, out: $stdout, git_client: DEFAULT_GIT_CLIENT)
  @repository = repository
  @out = out
  @git_client = git_client
end

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/geet/services/add_upstream_repo.rb', line 16

def execute
  raise "Upstream remote already existing!" if @git_client.remote_defined?(Utils::GitClient::UPSTREAM_NAME)

  parent_path = @repository.remote.parent_path

  if parent_path
    parent_url = compose_parent_url(parent_path)

    @git_client.add_remote(Utils::GitClient::UPSTREAM_NAME, parent_url)
  else
    raise "The repository has no upstream!"
  end
end