Module: GitRefresh::Git

Defined in:
lib/git_refresh/git.rb

Class Method Summary collapse

Class Method Details

.refresh(target_dir, source_url, ref = 'master') ⇒ Object

Clone or update a git repo



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/git_refresh/git.rb', line 6

def self.refresh(target_dir, source_url, ref='master')
  status = false
  FileUtils.mkdir_p target_dir
  if Dir.exists?("#{target_dir}/.git")
    # update
    Dir.chdir(target_dir) do
      status = system("git fetch && git checkout #{ref}")
    end
  else
    # clone
    status = system("git clone -b #{ref} #{source_url} #{target_dir}")
  end


  if ! status
    raise "Git operation failed, see previous error"
  end

  status
end