Class: Raykit::Git
- Inherits:
-
Object
- Object
- Raykit::Git
- Defined in:
- lib/raykit/git.rb
Instance Attribute Summary collapse
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Class Method Summary collapse
- .add_remote ⇒ Object
- .branch ⇒ Object
- .get_current_branch ⇒ Object
- .get_latest_commit(remote, branch) ⇒ Object
-
.get_latest_tag ⇒ Object
get the latest tag for the current directory.
- .get_relative_path(remote) ⇒ Object
- .get_remote ⇒ Object
- .last_tag ⇒ Object
- .list_remotes ⇒ Object
- .outstanding_commit ⇒ Object
- .remote_urls ⇒ Object
- .remote_urls=(urls) ⇒ Object
- .scan_remote_urls ⇒ Object
- .user_can_commit ⇒ Object
- .user_email ⇒ Object
- .user_name ⇒ Object
Instance Attribute Details
#start_time ⇒ Object
Returns the value of attribute start_time.
3 4 5 |
# File 'lib/raykit/git.rb', line 3 def start_time @start_time end |
Class Method Details
.add_remote ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/raykit/git.rb', line 88 def self.add_remote remote = get_remote if(remote.length > 0) remote_urls_copy = remote_urls if(!remote_urls_copy.include?(remote)) remote_urls_copy.insert(0,remote) Git::remote_urls = remote_urls_copy end end end |
.branch ⇒ Object
5 6 7 8 |
# File 'lib/raykit/git.rb', line 5 def self.branch branches = `git branch` branches.match(/ ([\w.]+)/).captures[0] end |
.get_current_branch ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/raykit/git.rb', line 41 def self.get_current_branch text=`git branch` if(text.include?('HEAD detached')) return 'master' end #puts "get_current_branch text=#{text}" scan=text.scan(/\*\s([\w\.-]+)/) #puts "scan=#{scan}" scan[0][0].to_s end |
.get_latest_commit(remote, branch) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/raykit/git.rb', line 52 def self.get_latest_commit(remote,branch) clone_dir="#{Environment::get_dev_dir('clone')}/#{get_relative_path(remote)}" if(!Dir.exist?(clone_dir)) parent_dir = File.('..',clone_dir) if(!Dir.exist?(parent_dir)) FileUtils.mkdir_p(parent_dir) end Command.new("git clone #{remote} #{clone_dir}") end Dir.chdir(clone_dir) do Command.new('git pull') if(get_current_branch != branch) Command.new("git checkout #{branch}") end text=`git log --name-status HEAD^..HEAD` #puts "get_latest_commit text: #{text}" scan=text.scan(/commit ([\w]+)\s/) #puts "scan: #{scan}" return scan[0][0].to_s end end |
.get_latest_tag ⇒ Object
get the latest tag for the current directory
37 38 39 |
# File 'lib/raykit/git.rb', line 37 def self.get_latest_tag `git describe --abbrev=0 --tags`.strip end |
.get_relative_path(remote) ⇒ Object
74 75 76 |
# File 'lib/raykit/git.rb', line 74 def self.get_relative_path(remote) remote.gsub('https://','').gsub('.git','') end |
.get_remote ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/raykit/git.rb', line 78 def self.get_remote if(Dir.exist?('.git')) cmd = Command.new('git config --get remote.origin.url') #cmd.run return cmd.output.strip else `` end end |
.last_tag ⇒ Object
10 11 12 |
# File 'lib/raykit/git.rb', line 10 def self.last_tag `git describe --abbrev=0 --tags`.strip end |
.list_remotes ⇒ Object
115 116 117 |
# File 'lib/raykit/git.rb', line 115 def self.list_remotes remote_urls.each{|url| puts url} end |
.outstanding_commit ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/raykit/git.rb', line 28 def self.outstanding_commit if(Git::user_can_commit) return !`git status`.include?('nothing to commit,') else return false end end |
.remote_urls ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/raykit/git.rb', line 99 def self.remote_urls filename="#{Environment::get_dev_dir('log')}/Raykit.Git.RemoteUrls.json"; if(File.exist?(filename)) JSON.parse(File.read(filename)) else Array.new end end |
.remote_urls=(urls) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/raykit/git.rb', line 108 def self.remote_urls=(urls) filename="#{Environment::get_dev_dir('log')}/Raykit.Git.RemoteUrls.json" File.open(filename,'w'){|f| f.write(JSON.generate(urls)) } end |
.scan_remote_urls ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/raykit/git.rb', line 119 def self.scan_remote_urls remotes = Array.new git_dirs = Array.new Dir.chdir(Environment::work_dir) do Dir.glob('**/.git'){|git_dir| dir = File.('..',git_dir) if(dir.length > 0) git_dirs.insert(0,dir) end } end git_dirs.each{|git_dir| Dir.chdir(git_dir) do remote = get_remote if(remote.length > 0) remotes.insert(0,remote) end end } remotes end |
.user_can_commit ⇒ Object
22 23 24 25 26 |
# File 'lib/raykit/git.rb', line 22 def self.user_can_commit return false if(user_name.length == 0) return false if(user_email.length == 0) return true end |
.user_email ⇒ Object
18 19 20 |
# File 'lib/raykit/git.rb', line 18 def self.user_email return `git config --get user.email`.strip end |
.user_name ⇒ Object
14 15 16 |
# File 'lib/raykit/git.rb', line 14 def self.user_name return `git config --get user.name`.strip end |