lib/docman/git_util.rb in docman-0.0.16 vs lib/docman/git_util.rb in docman-0.0.17
- old
+ new
@@ -18,11 +18,12 @@
Dir.chdir path
exec 'git reset --hard'
exec 'git clean -f -d'
end
- def self.get(repo, path, type, version)
+ 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)
if type == 'branch'
exec "git fetch"
@@ -33,25 +34,24 @@
exec 'git fetch --tags'
exec "git checkout tags/#{version}"
end
else
FileUtils.rm_rf path if File.directory? path
- exec "git clone #{repo} #{path}"
+ if type == 'branch'
+ single_branch = single_branch ? "-b #{version} --single-branch" : ''
+ depth = (depth and depth.is_a? Integer) ? "--depth #{depth}" : ''
+ else
+ single_branch=''
+ depth=''
+ end
+ exec "git clone #{single_branch} #{depth} #{repo} #{path}"
Dir.chdir path
exec "git checkout #{version}"
end
result = type == 'branch' ? self.last_revision : version
result
end
- def self.read_yaml_from_file(repo, path, version, filename)
- self.get(repo, path, 'branch', version)
- filepath = File.join(path, filename)
- return YAML::load_file(filepath) if File.file? filepath
- nil
- rescue StandardError => e
- raise "Error in info file: #{filepath}, #{e.message}"
- end
def self.last_revision
result = `git rev-parse --short HEAD`
result.delete!("\n")
end
\ No newline at end of file