Method: Docman::GitUtil.get

Defined in:
lib/docman/git_util.rb

.get(repo, path, type, version, single_branch = nil, depth = nil, reset = false) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/docman/git_util.rb', line 40

def self.get(repo, path, type, version, single_branch = nil, depth = nil, reset = false)
  FileUtils.rm_rf path if reset and File.directory? path
  if File.directory? path and File.directory?(File.join(path, '.git'))
    Dir.chdir path
    self.reset_repo(path) #if self.repo_changed?(path)
    exec 'fetch --tags'
    if type == 'branch'
      #exec "fetch"
      exec "checkout #{version}"
      exec "pull origin #{version}"
    end
    if type == 'tag'
      exec "checkout tags/#{version}"
    end
  else
    FileUtils.rm_rf path if File.directory? path
    clone_repo(repo, path, type, version, single_branch, depth)
    Dir.chdir path
    exec "checkout #{version}"
  end
  result = type == 'branch' ? self.last_revision(path) : version
  result
end