Module: Consist::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/consist/utils.rb

Instance Method Summary collapse

Instance Method Details

#clone_repo_contents(source_repo, target_dir) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/consist/utils.rb', line 8

def clone_repo_contents(source_repo, target_dir)
  temp_dir = Dir.mktmpdir

  puts "Using #{source_repo} as template to initialize Consistfile..."
  system("git clone --depth=1 #{source_repo} #{temp_dir} >/dev/null 2>&1")

  Dir.foreach(temp_dir) do |item|
    next if [".", "..", ".git"].include?(item)
    next unless ["Consistfile", ".consist"].include?(item)

    source_path = File.join(temp_dir, item)
    target_path = File.join(target_dir, item)
    FileUtils.cp_r(source_path, target_path)
  end

  FileUtils.remove_entry_secure(temp_dir)

  puts "...done"
end