lib/docman/git_util.rb in docman-0.0.20 vs lib/docman/git_util.rb in docman-0.0.21

- old
+ new

@@ -4,50 +4,55 @@ module GitUtil @logger = Logger.new(STDOUT) + def self.git + result = ENV['GIT_CMD'] ? ENV['git_cmd'] : 'git' + result + end + def self.exec(command) @logger.info command - result = `#{command}`.delete!("\n") + result = `#{git} #{command}`.delete!("\n") @logger.info result if result raise "ERROR: #{result}" unless $?.exitstatus == 0 result end def self.reset_repo(path) Dir.chdir path - exec 'git reset --hard' - exec 'git clean -f -d' + exec 'reset --hard' + exec 'clean -f -d' end 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" - exec "git checkout #{version}" - exec "git pull origin #{version}" + exec "fetch" + exec "checkout #{version}" + exec "pull origin #{version}" end if type == 'tag' - exec 'git fetch --tags' - exec "git checkout tags/#{version}" + 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 "git clone #{single_branch} #{depth} #{repo} #{path}" + exec "clone #{single_branch} #{depth} #{repo} #{path}" Dir.chdir path - exec "git checkout #{version}" + exec "checkout #{version}" end result = type == 'branch' ? self.last_revision(path) : version result end @@ -68,19 +73,19 @@ def self.commit(root_path, path, message, tag = nil) if repo_changed? path # puts message pull root_path - exec %Q(git add --all #{path.slice "#{root_path}/"}) - exec %Q(git commit -m "#{message}") if repo_changed? path + exec %Q(add --all #{path.slice "#{root_path}/"}) + exec %Q(commit -m "#{message}") if repo_changed? path self.tag(root_path, tag) if tag end end def self.pull(path) Dir.chdir path - exec 'git pull' + exec 'pull' end def self.repo?(path) File.directory? File.join(path, '.git') end @@ -95,17 +100,17 @@ result.delete!("\n") end def self.push(root_path, version) Dir.chdir root_path - exec "git pull origin #{version}" - exec "git push origin #{version}" + exec "pull origin #{version}" + exec "push origin #{version}" end def self.tag(root_path, tag) Dir.chdir root_path - exec %Q(git tag -a -m "Tagged to #{tag}" "#{tag}") - exec "git push origin #{tag}" + exec %Q(tag -a -m "Tagged to #{tag}" "#{tag}") + exec "push origin #{tag}" end end end \ No newline at end of file