class TYCiCore::Git
Public Class Methods
git_branch_exist_local?(branch)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/tuya/ci/core/git.rb, line 82 def self.git_commit_all(message) puts "Git commit all".green git_commit_commands = [ %W(add -A), %W(commit -am '#{message}') ] EXE.multi_exe('git', git_commit_commands, true) end
git_commit_modify(message)
click to toggle source
# File lib/tuya/ci/core/git.rb, line 64 def self.git_commit_modify(message) 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 '#{message}') ] EXE.multi_exe("git", commands, true) end commit_result end
git_create_empty_repo_http(name, url)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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?()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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 )
click to toggle source
# 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
git_tag_push(tag)
click to toggle source
# File lib/tuya/ci/core/git.rb, line 22 def self.git_tag_push(tag) puts "Git tag push: #{tag}".green command = %W(push origin #{tag}) EXE.exe('git', command, true ) end
git_tag_push_all()
click to toggle source
# File lib/tuya/ci/core/git.rb, line 30 def self.git_tag_push_all puts "Git tag push all".green command = %W(push origin --tags) EXE.exe('git', command, true ) end