lib/docman/git_util.rb in docman-0.0.22 vs lib/docman/git_util.rb in docman-0.0.23
- old
+ new
@@ -3,22 +3,16 @@
module Docman
module GitUtil
@logger = Logger.new(STDOUT)
+ @git = ENV.has_key?('GIT_CMD') ? ENV['GIT_CMD'] : 'git'
- def self.git
- result = ENV.has_key?('GIT_CMD') ? ENV['GIT_CMD'] : 'git'
- puts result
- @logger.info ENV
- result
- end
-
- def self.exec(command)
- @logger.info command
- result = `#{git} #{command}`.delete!("\n")
- @logger.info result if result
+ def self.exec(command, show_result = true)
+ @logger.info "#{@git} #{command}"
+ result = `#{@git} #{command}`.delete!("\n")
+ @logger.info result if show_result and result
raise "ERROR: #{result}" unless $?.exitstatus == 0
result
end
def self.reset_repo(path)
@@ -41,24 +35,27 @@
exec 'fetch --tags'
exec "checkout tags/#{version}"
end
else
FileUtils.rm_rf path if File.directory? 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 "clone #{single_branch} #{depth} #{repo} #{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
+ def self.clone_repo(repo, path, type, version, single_branch = nil, depth = nil)
+ 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("clone #{single_branch} #{depth} #{repo} #{path}")
+ end
def self.last_revision(path = nil)
result = nil
if self.repo? path
Dir.chdir path unless path.nil?
\ No newline at end of file