require 'tmpdir' require 'rake' class Git def self.branch directory='' directory=Dir.pwd if directory.length == 0 Dir.chdir(directory) do begin `git branch`.scan(/\* ([.\w-]+)/)[0][0] if(File.exists?('.git')) rescue '' end end end def self.remote_origin directory='' url='' directory=Dir.pwd if directory.length == 0 Dir.chdir(directory) do begin url=`git remote show origin`.scan(/Fetch URL: ([\.\-:\/\w\d]+)/)[0][0] if(File.exists?('.git')) rescue url='' end end url end def self.has_changes? directory='' directory=Dir.pwd if directory.length==0 Dir.chdir(directory) do if(File.exists?('.git')) return true if `git status`.include?('modified:') return true if `git status`.include?('new file:') end end false end def self.init directory='' directory=Dir.pwd if directory.length==0 FileUtils.mkpath directory if !File.exists?(directory) if(!File.exists?("#{directory}/.git")) Dir.chdir(directory) do `git init --bare` #File.open('.gitignore','w'){|f| # f.puts '### Mac ###' # f.puts '*.DS_Store' #} #{}`git add .gitignore` #{}`git commit -m'added .gitignore'` end end end def self.tag directory,version directory=Dir.pwd if directory.length == 0 Dir.chdir(directory) do `git pull` tags=`git tag` if(!tags.include?(version)) puts 'tagging branch' puts `git tag version -m'#{version}'` puts 'committing' puts `git commit -m'#{version}'` puts 'pushing' puts `git push --tags` puts `git push` end end end def self.publish destination, source_dir, source_filelist, tag puts "publish to #{destination}" tmp_dir=Dir.mktmpdir FileUtils.mkdir_p(File.dirname(tmp_dir)) if(!File.exists?(File.dirname(tmp_dir))) FileUtils.rm_r(tmp_dir) if File.exists?(tmp_dir) puts `git clone #{destination} #{tmp_dir}` Dir.chdir(tmp_dir) do tags=`git tag` if(tags.include?(tag)) puts "tag #{tag} already exists." else Dir.chdir(source_dir) do source_filelist.each{|f| dest = tmp_dir + "/" + f FileUtils.cp(f,dest); } end puts `git add -A` puts `git commit -m"add"` Git.tag tmp_dir,tag end end FileUtils.rm_r tmp_dir end end