class GitOp
This class is used by lib/backend.rb git operation for gitarro
Attributes
git_dir[R]
pr[R]
pr_fix[R]
repo_external[R]
repo_protocol[R]
Public Class Methods
new(git_dir, pr, options)
click to toggle source
# File lib/gitarro/git_op.rb, line 44 def initialize(git_dir, pr, options) @git_dir = git_dir # prefix for the test pr that gitarro tests. @pr_fix = 'PR-' # pr object for extract all relev. data. @pr = pr # All gitarro options @options = options # object to handle external repos @repo_external = ExternalRepoGit.new(pr, options) gh = 'https://github.com/' gg = 'git@github.com:' @repo_protocol = @options[:https] ? gh : gg end
Public Instance Methods
del_pr_branch(upstream, pr)
click to toggle source
cleanup the pr_branch(delete it)
# File lib/gitarro/git_op.rb, line 76 def del_pr_branch(upstream, pr) `git checkout #{upstream}` `git branch -D #{pr_fix}#{pr}` end
merge_pr_totarget(upstream, pr_branch)
click to toggle source
merge pr_branch into upstream targeted branch
# File lib/gitarro/git_op.rb, line 60 def merge_pr_totarget(upstream, pr_branch) goto_prj_dir check_git_dir `git checkout #{upstream}` check_duplicata_pr_branch("#{pr_fix}#{pr_branch}") `git remote update` `git fetch` `git pull origin #{upstream}` `git checkout -b #{pr_fix}#{pr_branch} origin/#{pr_branch}` return if $CHILD_STATUS.exitstatus.zero? # if it fails the PR contain a forked external repo repo_external.checkout_into end
Private Instance Methods
check_duplicata_pr_branch(pr)
click to toggle source
this is for preventing that a test branch exists already and we have some internal error
# File lib/gitarro/git_op.rb, line 120 def check_duplicata_pr_branch(pr) puts `git branch --list #{pr}` `git branch -D #{pr} 2>/dev/null` if $CHILD_STATUS.exitstatus.zero? end
check_git_dir()
click to toggle source
# File lib/gitarro/git_op.rb, line 113 def check_git_dir msg_err = 'gitarro is not working on a git directory' raise msg_err if File.directory?('.git') == false end
ck_or_clone_git()
click to toggle source
# File lib/gitarro/git_op.rb, line 83 def ck_or_clone_git git_repo_dir = git_dir + '/' + @options[:repo].split('/')[1] return if File.directory?(git_repo_dir) FileUtils.mkdir_p(git_dir) unless File.directory?(git_dir) Dir.chdir git_dir clone_repo end
clone_repo()
click to toggle source
# File lib/gitarro/git_op.rb, line 92 def clone_repo repo_url = "#{repo_protocol}#{@options[:repo]}.git" puts `git clone #{repo_url}` exit 1 if $CHILD_STATUS.exitstatus.nonzero? end
goto_prj_dir()
click to toggle source
this function merge the pr branch into target branch, where the author of pr wanted to submit
# File lib/gitarro/git_op.rb, line 100 def goto_prj_dir git_repo_dir = git_dir + '/' + @options[:repo].split('/')[1] # chech that dir exist, otherwise clone it ck_or_clone_git begin # /tmp/gitarro, this is in case the dir already exists Dir.chdir git_repo_dir rescue Errno::ENOENT # this is in case we clone the repo Dir.chdir @options[:repo].split('/')[1] end end