Class: Git
- Inherits:
-
Object
- Object
- Git
- Defined in:
- lib/dev_git.rb,
lib/dev_commands.rb
Class Method Summary collapse
- .branch ⇒ Object
- .has_changes?(directory = '') ⇒ Boolean
- .init(directory = '') ⇒ Object
- .publish(destination, source_dir, source_filelist, tag) ⇒ Object
- .remote_origin(directory = '') ⇒ Object
- .tag(directory, version) ⇒ Object
Class Method Details
.branch ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/dev_git.rb', line 5 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 |
.has_changes?(directory = '') ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dev_git.rb', line 29 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 |
.init(directory = '') ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dev_git.rb', line 40 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 |
.publish(destination, source_dir, source_filelist, tag) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/dev_git.rb', line 73 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 =`git tag` if(.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 |
.remote_origin(directory = '') ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dev_git.rb', line 16 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 |
.tag(directory, version) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dev_git.rb', line 56 def self.tag directory,version directory=Dir.pwd if directory.length == 0 Dir.chdir(directory) do `git pull` =`git tag` if(!.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 |