Class: Git
- Inherits:
-
Object
- Object
- Git
- Defined in:
- lib/apps/git.rb
Class Method Summary collapse
- .branch(directory = '') ⇒ Object
- .clone_and_reset(uri, directory, tagname) ⇒ Object
- .copy(src_url, src_directory, branch, target_directory, filelist) ⇒ Object
- .has_changes?(directory = '') ⇒ Boolean
- .init(directory = '') ⇒ Object
- .latest_tag(directory = '') ⇒ Object
- .publish(destination, source_dir, source_filelist, tag) ⇒ Object
- .remote_origin(directory = '') ⇒ Object
- .tag(directory, version) ⇒ Object
- .url ⇒ Object
- .user_email ⇒ Object
- .user_name ⇒ Object
Class Method Details
.branch(directory = '') ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/apps/git.rb', line 7 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 |
.clone_and_reset(uri, directory, tagname) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/apps/git.rb', line 127 def self.clone_and_reset uri, directory, tagname if(!File.exists?(directory)) `git clone #{uri} #{directory}` Dir.chdir(directory) do `git reset --hard #{tagname}` end end end |
.copy(src_url, src_directory, branch, target_directory, filelist) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/apps/git.rb', line 150 def self.copy(src_url,src_directory,branch,target_directory,filelist) if(!File.exists?(src_directory)) puts `git clone #{src_url} #{src_directory}` else Dir.chdir(src_directory) do puts `git pull` end end Dir.chdir(src_directory) do puts `git checkout #{branch}` filelist.each{|f| dest="#{target_directory}/#{f}" FileUtils.mkdir_p File.dirname(dest) if !File.exists? File.dirname(dest) puts "copying #{f} to #{dest}" FileUtils.cp(f,dest) } end end |
.has_changes?(directory = '') ⇒ Boolean
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/apps/git.rb', line 56 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
67 68 69 70 71 72 73 74 75 |
# File 'lib/apps/git.rb', line 67 def self.init directory='' directory=Dir.pwd if directory.length==0 parent=File.dirname(directory) FileUtils.mkdir_p parent if !File.exists?(parent) && parent.length > 0 Dir.chdir(parent) do `git init --bare` end end |
.latest_tag(directory = '') ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/apps/git.rb', line 136 def self.latest_tag directory='' if directory.length==0 Command.output('git describe --abbrev=0 --tags').strip #`git describe --abbrev=0 --tags`.strip else result='' Dir.chdir(directory) do result=Command.output('git describe --abbrev=0 --tags').strip #result=`git describe --abbrev=0 --tags`.strip end result end end |
.publish(destination, source_dir, source_filelist, tag) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/apps/git.rb', line 94 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}` puts "checking if tag #{tag} exists..." Dir.chdir(tmp_dir) do =`git tag` if(.include?(tag)) puts "tag #{tag} already exists." else puts "tag #{tag} does not exist." Dir.chdir(source_dir) do source_filelist.each{|f| dest = tmp_dir + "/" + f FileUtils.mkdir_p(File.dirname(dest)) if(!File.exists?(File.dirname(dest))) FileUtils.cp(f,dest); puts "copying file #{f} for publishing" } end puts 'git add -A' puts `git add -A` puts 'git commit -m"add"' puts `git commit -m"add"` Git.tag tmp_dir,tag end end FileUtils.rm_r tmp_dir end |
.remote_origin(directory = '') ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/apps/git.rb', line 43 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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/apps/git.rb', line 77 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 |
.url ⇒ Object
18 19 20 21 |
# File 'lib/apps/git.rb', line 18 def self.url url='' url=`git config --get remote.origin.url` if(File.exists?('.git')) end |
.user_email ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/apps/git.rb', line 23 def self.user_email email='' begin email=`git config --list`.scan(/user.email=([\d\w.@\-\+]+)/)[0][0] rescue email='' end email end |
.user_name ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/apps/git.rb', line 33 def self.user_name name='' begin name=`git config --list`.scan(/user.name=([\d\w.@\-\+]+)/)[0][0] rescue name='' end name end |