Class: Indocker::Repositories::Cloner

Inherits:
Object
  • Object
show all
Defined in:
lib/indocker/repositories/cloner.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration, logger) ⇒ Cloner

Returns a new instance of Cloner.



4
5
6
7
# File 'lib/indocker/repositories/cloner.rb', line 4

def initialize(configuration, logger)
  @configuration = configuration
  @logger = logger
end

Instance Method Details

#clone(session, repository) ⇒ Object

Raises:

  • (ArgumenError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/indocker/repositories/cloner.rb', line 9

def clone(session, repository)
  raise ArgumenError.new("only git repositories should be cloned") if !repository.is_git?

  already_cloned = repository_already_cloned?(
    session:     session,
    target_path: repository.clone_path,
    remote_url:  repository.remote_url,
  )

  git_command = if already_cloned
    build_force_pull_command(
      target_path: repository.clone_path,
      branch_name: repository.branch,
    )
  else
    build_clone_command(
      target_path: repository.clone_path,
      branch_name: repository.branch,
      remote_url:  repository.remote_url,
    )
  end

  session.exec!("ssh-agent bash -c 'ssh-add ~/.ssh/#{repository.ssh_key}; #{git_command}'")
end