Class: TYCiCore::Git
- Inherits:
-
Object
- Object
- TYCiCore::Git
- Defined in:
- lib/tuya/ci/core/git.rb
Class Method Summary collapse
- .git_branch_exist_local?(branch) ⇒ Boolean
- .git_branch_exist_remote?(branch) ⇒ Boolean
- .git_checkout_branch(target_branch) ⇒ Object
- .git_clean ⇒ Object
- .git_commit_all(message) ⇒ Object
- .git_commit_modify(message) ⇒ Object
- .git_create_empty_repo_http(name, url) ⇒ Object
- .git_create_empty_repos(name, url) ⇒ Object
- .git_current_branch ⇒ Object
- .git_delete_temp_path(name) ⇒ Object
- .git_detached? ⇒ Boolean
- .git_has_modify?(str) ⇒ Boolean
- .git_push ⇒ Object
- .git_remote_repo_exist?(url) ⇒ Boolean
- .git_tag_add(tag) ⇒ Object
- .git_tag_add_push(tag) ⇒ Object
- .git_tag_checkout(tag) ⇒ Object
- .git_tag_delete!(tag, local = true, remote = true) ⇒ Object
- .git_tag_exist?(tag, remote = false) ⇒ Boolean
- .git_tag_push(tag) ⇒ Object
- .git_tag_push_all ⇒ Object
Class Method Details
.git_branch_exist_local?(branch) ⇒ Boolean
154 155 156 |
# File 'lib/tuya/ci/core/git.rb', line 154 def self.git_branch_exist_local?(branch) TYCiCore::EXE.exe('git', %W(rev-parse -q --verify refs/heads/#{branch})).length > 0 end |
.git_branch_exist_remote?(branch) ⇒ Boolean
158 159 160 161 |
# File 'lib/tuya/ci/core/git.rb', line 158 def self.git_branch_exist_remote?(branch) temp = TYCiCore::EXE.exe('git', %W(branch -a)) temp.scan(/remotes\/origin\/#{branch}/).size > 0 end |
.git_checkout_branch(target_branch) ⇒ Object
93 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 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/tuya/ci/core/git.rb', line 93 def self.git_checkout_branch(target_branch) puts "Git checkout branch: #{target_branch}".green commands = [ %W(add -u), %W(reset --hard), %W(remote prune origin), %W(fetch) ] EXE.multi_exe('git', commands, true ) commands = [] if git_detached? puts "Current status is HEAD detached".green in_target_branch = false else current_branch = git_current_branch puts "Current branch is #{current_branch}".green in_target_branch = current_branch == target_branch commands << %W(rebase) end unless in_target_branch remote_exist = git_branch_exist_remote? target_branch local_exist = git_branch_exist_local? target_branch puts "Git local branch: #{target_branch} is exist?: #{local_exist}".green puts "Git remote branch: #{target_branch} is exist?: #{remote_exist}".green if local_exist commands << %W(checkout #{target_branch}) unless remote_exist commands << %W(git push --set-upstream origin #{target_branch}) end else if remote_exist commands << %W(checkout #{target_branch}) else commands << %W(checkout -b #{target_branch}) commands << %W(push --set-upstream origin #{target_branch}) end end end commands << %W(remote prune origin) commands << %W(fetch) commands << %W(rebase) EXE.multi_exe('git', commands, true ) end |
.git_clean ⇒ Object
145 146 147 |
# File 'lib/tuya/ci/core/git.rb', line 145 def self.git_clean EXE.multi_exe('git', [%W(add .), %W(reset --hard)], true) end |
.git_commit_all(message) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/tuya/ci/core/git.rb', line 82 def self.git_commit_all() puts "Git commit all".green git_commit_commands = [ %W(add -A), %W(commit -am '#{}') ] EXE.multi_exe('git', git_commit_commands, true) end |
.git_commit_modify(message) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tuya/ci/core/git.rb', line 64 def self.git_commit_modify() puts "Git commit modify".green git_status = EXE.exe("git", %W(status), true) commit_result = git_has_modify? git_status if commit_result commands = [ %W(add -u), %W(commit -m '#{}') ] EXE.multi_exe("git", commands, true) end commit_result end |
.git_create_empty_repo_http(name, url) ⇒ Object
171 172 173 |
# File 'lib/tuya/ci/core/git.rb', line 171 def self.git_create_empty_repo_http(name, url) end |
.git_create_empty_repos(name, url) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/tuya/ci/core/git.rb', line 183 def self.git_create_empty_repos(name, url) user = ENV["HOME"] temp_path = "#{user}/.tuya_git_temp/" temp_path_p = "#{temp_path}#{name}" `mkdir -p #{temp_path_p}` FileUtils.cd temp_path_p `touch Readme.md` git_commands = [ %W(init), %W(add -A), %W(commit -am init\ #{name}\ by\ tuya-odm), %W(remote add origin #{url}), %W(push --set-upstream origin master) ] TYCiCore::EXE.multi_exe('git', git_commands, true) FileUtils.cd temp_path end |
.git_current_branch ⇒ Object
140 141 142 143 |
# File 'lib/tuya/ci/core/git.rb', line 140 def self.git_current_branch temp = EXE.exe('git', %W(branch)) temp.scan(/^\*\s(.*)/)[0][0] end |
.git_delete_temp_path(name) ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/tuya/ci/core/git.rb', line 175 def self.git_delete_temp_path(name) user = ENV["HOME"] temp_path = "#{user}/.tuya_git_temp/" temp_path_p = "#{temp_path}#{name}" `rm -rf #{temp_path_p}` if File.exist? temp_path_p end |
.git_detached? ⇒ Boolean
149 150 151 152 |
# File 'lib/tuya/ci/core/git.rb', line 149 def self.git_detached? temp = TYCiCore::EXE.exe('git', %W(status)) temp.scan(/HEAD detached at/).size > 0 end |
.git_has_modify?(str) ⇒ Boolean
163 164 165 |
# File 'lib/tuya/ci/core/git.rb', line 163 def self.git_has_modify?(str) return str.include?("Changes not staged for commit") || str.include?("Changes to be committed") end |
.git_push ⇒ Object
59 60 61 62 |
# File 'lib/tuya/ci/core/git.rb', line 59 def self.git_push puts "Git commit push".green EXE.exe('git', %W(push), true ) end |
.git_remote_repo_exist?(url) ⇒ Boolean
167 168 169 |
# File 'lib/tuya/ci/core/git.rb', line 167 def self.git_remote_repo_exist?(url) `curl -s --head #{url} | grep "HTTP/1.[01] [23].."`.scan(/200 OK/).size > 0 end |
.git_tag_add(tag) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/tuya/ci/core/git.rb', line 14 def self.git_tag_add(tag) puts "Git tag add: #{tag}".green command = %W(tag -a #{tag} -m add\ tag:\ #{tag}) EXE.exe('git', command, true ) end |
.git_tag_add_push(tag) ⇒ Object
9 10 11 12 |
# File 'lib/tuya/ci/core/git.rb', line 9 def self.git_tag_add_push(tag) git_tag_add tag git_tag_push tag end |
.git_tag_checkout(tag) ⇒ Object
5 6 7 |
# File 'lib/tuya/ci/core/git.rb', line 5 def self.git_tag_checkout(tag) EXE.exe('git', %W(checkout #{tag}), true ) end |
.git_tag_delete!(tag, local = true, remote = true) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tuya/ci/core/git.rb', line 38 def self.git_tag_delete!(tag, local=true, remote=true) puts "Git tag: #{tag} delete".green commands = [] commands << %W(tag -d #{tag}) if local commands << %W(push origin :refs/tags/#{tag}) if remote EXE.multi_exe('git', commands, true ) unless commands.empty? end |
.git_tag_exist?(tag, remote = false) ⇒ Boolean
51 52 53 54 55 56 57 |
# File 'lib/tuya/ci/core/git.rb', line 51 def self.git_tag_exist?(tag, remote=false ) if remote EXE.exe('git', %W(ls-remote -q --exit-code origin #{tag})).length > 0 else EXE.exe('git', %W(rev-parse -q --verify #{tag})).length > 0 end end |