Method: Docman::GitUtil.get

Defined in:
lib/docman/git_util.rb

.get(repo, path, type, version) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/docman/git_util.rb', line 23

def self.get(repo, path, type, version)
  if File.directory? path and File.directory?(File.join(path, '.git'))
    Dir.chdir path

    self.reset_repo(path) if self.repo_changed?(path)

    if type == 'branch'
      exec "git checkout #{version}"
      exec "git pull origin #{version}"
    end
    if type == 'tag'
      exec 'git fetch --tags'
      exec "git checkout tags/#{version}"
    end
  else
    FileUtils.rm_rf path if File.directory? path
    exec "git clone #{repo} #{path}"
    Dir.chdir path
    exec "git checkout #{version}"
  end
  result = `git rev-parse --short HEAD`
  @logger.info "Commit hash: #{result}"
  result.delete!("\n")
end