Module: YAVDB::Utils::Git

Defined in:
lib/yavdb/utils/git.rb

Class Method Summary collapse

Class Method Details

.download_or_update(repo_path, repo_url, repo_branch, force_update = true) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/yavdb/utils/git.rb', line 42

def self.download_or_update(repo_path, repo_url, repo_branch, force_update = true)
  puts "Downloading #{repo_url}" if Constants::DEBUG

  if File.exist?(repo_path) && Dir.entries(repo_path) != ['.', '..']
    if File.directory?(File.expand_path(File.join(repo_path, '.git')))
      Dir.chdir(repo_path) do
        YAVDB::Utils::Executor.run("git fetch --all && git reset --hard origin/#{repo_branch}") if force_update
      end
    else
      puts "Repository directory already exists and is not a valid git repository in #{repo_path}"
      exit(1)
    end
  else
    YAVDB::Utils::Executor.run("git clone #{repo_url} -b #{repo_branch} #{repo_path}")
  end
end

.get_contents(repo_url, repo_branch, with_cache = true, group_cache_key = 'git') ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yavdb/utils/git.rb', line 27

def self.get_contents(repo_url, repo_branch, with_cache = true, group_cache_key = 'git')
  puts "Requesting #{repo_url}" if Constants::DEBUG

  if with_cache
    YAVDB::Utils::Cache.cache_path(group_cache_key, repo_url) do |repo_path|
      download_or_update(repo_path, repo_url, repo_branch)
      repo_path
    end
  else
    repo_path = Dir.mktmpdir(group_cache_key)
    download_or_update(repo_path, repo_url, repo_branch)
    repo_path
  end
end