lib/docman/git_util.rb in docman-0.0.14 vs lib/docman/git_util.rb in docman-0.0.15

- old
+ new

@@ -18,54 +18,58 @@ Dir.chdir path exec 'git reset --hard' exec 'git clean -f -d' end - def self.get(repo, path, type, version, force_return = false) + 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 fetch" exec "git checkout #{version}" - initial_revision = self.last_revision exec "git pull origin #{version}" end if type == 'tag' exec 'git fetch --tags' - initial_revision = self.last_revision exec "git checkout tags/#{version}" end else - initial_revision = nil FileUtils.rm_rf path if File.directory? path exec "git clone #{repo} #{path}" Dir.chdir path exec "git checkout #{version}" end - result = self.last_revision - @logger.info "Commit hash: #{result}" - # force_return or result != initial_revision ? result : false + 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 def self.update(path) pull path end - def self.commit(root_path, path, message) + 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 + self.tag(root_path, tag) if tag end end def self.pull(path) Dir.chdir path @@ -86,11 +90,17 @@ result.delete!("\n") end def self.push(root_path, version) Dir.chdir root_path - `git pull origin #{version}` - `git push origin #{version}` + exec "git pull origin #{version}" + exec "git 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}" end end end \ No newline at end of file